@baxibaba/react-audio-recorder
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@baxibaba/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 @baxibaba/react-audio-recorder

yarn add @baxibaba/react-audio-recorder

Props

Property name Type Default Description
status string RECORD_STATUS.IDLE RECORD_STATUS.(IDLE,RECORDING,PAUSED)
audioResult string - Result blob url.
errorMessage string - Error messages.
timer number - Record timer (in secs).
startRecording method - Call this method to start recording.
stopRecording method - Call this method to stop recording.
pauseRecording method - Call this method to pause recording.
resumeRecording method - Call this method to resume recording.

Usage (Class Version)

import React, { Component } from 'react'

import { ReactAudioRecorder } from '@baxibaba/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 '@baxibaba/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 © baxibaba

Package Sidebar

Install

npm i @baxibaba/react-audio-recorder

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

37.9 kB

Total Files

11

Last publish

Collaborators

  • baxibaba