Socket
Book a DemoInstallSign in
Socket

@amirseifi/react-voice-recorder

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@amirseifi/react-voice-recorder

A react package for recording voice

1.0.1
latest
Source
npmnpm
Version published
Weekly downloads
8
Maintainers
1
Weekly downloads
 
Created
Source

React Voice Recorder.

A package for recording voice in react.

You can use this package ( Media Core ) if you just want to get MediaRecorder.

Demo Link: react voice recorder

:warning: Warning :warning: This package work in localhost AND secure domain (HTTPS).

:warning: Warning :warning: You must mount the component when you want to start the record and unMount the component when the record is complete.

Future Feature.

  • control seek icon in playback voice ( with mouse or finger ).
  • show progress play in playback voice.
  • callback function for the requested timer.
  • possibility for changing icons.

How to use and props.

NameRequiredTypeDescription
isLoggingfalsebooleanLog error while using the recorder in develop mode , default : false
audioBitsPerSecondfalsenumberSet audioBitsPerSecond for the recording of voice
onPermissionDeniedtruefunctionFunction
onCanceltruefunctionFunction
onDataAvailabletruefunctionFunction

Sample :

import { useState } from 'react'
import './App.css'

import { AudioRecorder, IDataAvailable } from "@amirseifi/react-voice-recorder"
import "@amirseifi/react-voice-recorder/dist/style.css"

function App() {

  const [isRecordMode, setIsRecordMode] = useState(false)
  const [audioSrc, setAudioSrc] = useState("")

  const onDataReady = (value: IDataAvailable) => {
    const reader = new FileReader()

    reader.onload = (event) => {
      if (event.target !== null)
        setAudioSrc(event.target.result as string)
    }
    reader.readAsDataURL(value.value)

    setIsRecordMode(false)
  }
  const onCancel = () => {
    setIsRecordMode(false)
    setAudioSrc("")
  }

  const onPermissionDenied = () => {
    setIsRecordMode(false)
    setAudioSrc("")
    alert("Permission Denied")
  }

  return (
    <div className="App">

      {
        audioSrc && (
          <audio src={audioSrc} controls />
        )
      }

      <div className='chat-control'>
        <div className='chat-control-container'>


          {
            !isRecordMode && (
              <button onClick={() => { setIsRecordMode(!isRecordMode) }}>click to record</button>
            )
          }
          <div className='voice-recorder'>
            {
              isRecordMode && (
                <AudioRecorder
                  onCancel={onCancel}
                  onDataAvailable={onDataReady}
                  onPermissionDenied={onPermissionDenied}
                  isLogging
                />
              )
            }
          </div>
        </div>
      </div>
    </div>
  )
}

export default App

Contributing

Feel free to submit a PR if you found a bug (I might've missed many! 😀) or if you want to enhance it further.

Thanks!. Happy Recording!

Keywords

typescript

FAQs

Package last updated on 10 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.