1.5.3 • Published 3 years ago

react-voice-decorator v1.5.3

Weekly downloads
3
License
MIT
Repository
github
Last release
3 years ago

react-voice-decorator

React voice recorder component using navigator's mediaDevices and MediaRecorderapi that provides record/play/pause functionalities for developers using render-props design pattern.

demo

see Demo at https://codesandbox.io/s/react-voice-recorder-demo-9i8ik

usage

  • add package using yarn
    yarn add react-voice-decorator
  • use the render-props component:
import React, { useCallback, useRef } from 'react'

import VoiceDecorator from 'react-voice-decorator'

export default function App() {
  const voiceRef = useRef(null)

    const getVoice = useCallback((getterFn) => {
    voiceRef.current = getterFn()
  }, [])

  return (
    <div>
      <VoiceDecorator
        render={(props) => (
          <>
            <h1 onClick={props.toggleRecord}>
              {props.isRecording ? 'Stop Recording' : 'Record'}
            </h1>
            <h1 onClick={props.togglePlay}>
              {props.isPlaying ? 'Pause' : 'Play'}
            </h1>
          </>
        )}
        voiceGetter={getVoice}
      />
    </div>
  )
}
  • available props:
prop keytype
toggleRecordfunction
togglePlayfunction
isPlayingboolean
isRecordingboolean
voiceGetterfunction

ref

You can get recorded voice as an audio object using react ref

limitation

This package doesn't work on Safari with iOS versions lower than 13.4 (for the higher versions it works fine)

1.5.3

3 years ago

1.5.2

3 years ago

1.5.0

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago