1.1.2 • Published 3 years ago

@sarafhbk/react-audio-recorder v1.1.2

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

@sarafhbk/react-audio-recorder

This is a simple audio recorder package for react application using the javascript Web Audio API.

NPM JavaScript Style Guide

Demo

Checkout the Demo.

Install

npm install --save @sarafhbk/react-audio-recorder

yarn add @sarafhbk/react-audio-recorder

Props

Property nameTypeDefaultDescription
statusstringRECORD_STATUS.IDLERECORD_STATUS.(IDLE,RECORDING,PAUSED)
audioResultstring-Result blob url.
errorMessagestring-Error messages.
timernumber-Record timer (in secs).
startRecordingmethod-Call this method to start recording.
stopRecordingmethod-Call this method to stop recording.
pauseRecordingmethod-Call this method to pause recording.
resumeRecordingmethod-Call this method to resume recording.

Usage (Class Version)

import React, { Component } from 'react'

import { ReactAudioRecorder } from '@sarafhbk/react-audio-recorder'

class Example extends Component {
  render() {
    return (
      <ReactAudioRecorder
        render={({
          timer,
          stopRecording,
          startRecording,
          resumeRecording,
          pauseRecording,
          audioResult,
          status,
          errorMessage
        }) => (
          <div>
            <audio controls src={audioResult} />
            <p>
              Status : <b>{status}</b>
            </p>
            <p>
              Error Message : <b>{errorMessage}</b>
            </p>
            <div>
              <p>{new Date(timer * 1000).toISOString().substr(11, 8)}</p>
              <div>
                <button onClick={startRecording}>Start</button>
                <button onClick={stopRecording}>Stop</button>
                <button onClick={pauseRecording}>Pause</button>
                <button onClick={resumeRecording}>Resume</button>
              </div>
            </div>
          </div>
        )}
      />
    )
  }
}

Usage (Hooks Version)

import React from 'react'

import { useAudioRecorder } from '@sarafhbk/react-audio-recorder'

function Example() {
  const {
    audioResult,
    timer,
    startRecording,
    stopRecording,
    pauseRecording,
    resumeRecording,
    status,
    errorMessage
  } = useAudioRecorder()
  return (
    <div>
      <audio controls src={audioResult} />
      <p>
        Status : <b>{status}</b>
      </p>
      <p>
        Error Message : <b>{errorMessage}</b>
      </p>
      <div>
        <p>{new Date(timer * 1000).toISOString().substr(11, 8)}</p>
        <div>
          <button onClick={startRecording}>Start</button>
          <button onClick={stopRecording}>Stop</button>
          <button onClick={pauseRecording}>Pause</button>
          <button onClick={resumeRecording}>Resume</button>
        </div>
      </div>
    </div>
  )
}

License

MIT © sarafhbk