1.2.0 • Published 8 months ago

react-voice-recorder-player v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

react-voice-recorder-player

Say goodbye to boring audio elments and hello to interactive voice recording! react-voice-recorder-player is a React component that lets users record and playback their voice directly in the browser. It even includes a waveform graph that shows the audio being captured and played back in real-time.

react-voice-recorder-player is an ultra light-weight component. The package size is only around 160 kB meaning it won't add unnecessary bulk to your application. And the best part is, its completely customizable! You can easily change the appearance of the component to fit your application's unique design and trigger your own code on our custom events.

Installation

The package can be installed via npm:

npm install react-voice-recorder-player --save

Or via yarn:

yarn add react-voice-recorder-player

See it in action!

Check out the CodePen demo to see the VoiceRecorder component in action. This demo is a great starting point for customizing the component to fit your application's unique design.

Getting Started

Using the VoiceRecorder component is a breeze. Simply import it into your React application like so:

import React from 'react';
import { VoiceRecorder } from 'react-voice-recorder-player';

function App() {
  return (
    <div>
      <h1>React Voice Recorder</h1>
      <VoiceRecorder />
    </div>
  );
}

export default App;

The VoiceRecorder component will provide your users with an intuitive MP3-like interface, complete with record, play, pause, and stop buttons.

Points to note

  • The VoiceRecorder component uses the MediaRecorder API to record audio. This means that the component will only work in browsers that support this API. You can check out the browser compatibility table to see which browsers support this API.
  • There is no limit to the length of the audio that can be recorded. However, the longer the audio, the thinner the waveform graph will be. You can adjust this by increasing the width of the component.
  • And after you're done recording you'll see a download button that lets your users download the audio file to their computer. If you want to disable this feature, simply pass in false to the downloadable prop. If you'd like to obtain the audio file link programmatically, you can pass in a callback function to the onAudioDownload prop. This callback function will be called with the audio file blob as an argument.

Props

Prop nameDescriptionType
mainContainerStyleStyle object for the container of the whole component.CSSProperties
heightHeight of the component.number,string
widthWidth of the component.number,string
controllerContainerStyleStyle object for the container of the controller buttons.CSSProperties
controllerStyleStyle object for the controller buttons.CSSProperties
waveContainerStyleStyle object for the container of the waveform graph.CSSProperties
graphColorColor of the waveform graph.string
graphShadedBoolean value indicating if the waveform graph should be shaded according to the amplitude of the audio. true by default.boolean
downloadableBoolean value indicating if the download button should be displayed to the user when they're done recording. true by default.boolean
uploadAudioFileBoolean value indicating if the upload button should be displayed to the user. true by default.boolean
onAudioDownloadA callback function that'll get called as soon as the Blob is available.Function

Custom Events

In addition to the props mentioned above, you can also use our custom callback events to trigger specific actions in your application. Here's a list of the custom events that are available:

Prop nameDescriptionType
onRecordingStartEvent triggered when recording startsfunction
onRecordingEndEvent fired when recording endsfunction
onPlayStartEvent triggered when playback startsfunction
onPlayEndEvent fired when playback endsfunction
onRecordingPauseEvent triggered when recording is pausedfunction
onPlayPauseEvent fired when playback is pausedfunction

Customization

Want to make the VoiceRecorder component even more personalized? No problem! You can customize the appearance of the component by passing in your own style objects. Here's an example:

import React from 'react';
import { VoiceRecorder } from 'react-voice-recorder-player';

function MyComponent() {
  const styles = {
    mainContainerStyle: {
      backgroundColor: 'gray',
      border: '1px solid black',
      borderRadius: '5px',
      padding: '10px'
    },
    controllerContainerStyle: {
      display: 'flex',
      justifyContent: 'space-between',
      marginTop: '10px'
    },
    controllerStyle: {
      backgroundColor: 'white',
      border: '1px solid black',
      borderRadius: '5px',
      cursor: 'pointer',
      padding: '5px'
    },
    waveContainerStyle: {
      height: '100px',
      marginTop: '10px',
      width: '100%'
    }
  };

  return (
    <VoiceRecorder
      mainContainerStyle={styles.mainContainerStyle}
      controllerContainerStyle={styles.controllerContainerStyle}
      controllerStyle={styles.controllerStyle}
      waveContainerStyle={styles.waveContainerStyle}
    />
  );
}

Troubleshooting

This section provides solutions for known issues related to browser compatibility:

  • Issue: Playback option not working on iOS devices
    • Due to browser limitations on iOS devices, the playback option may not work as expected. In the meantime, consider testing on other browsers or devices for full functionality. (fixed here)
  • Issue: Playback option not working on Mac Safari in Codesandbox

Please note that this list may be updated as new issues are identified and resolved. Contributions from the community are welcome in identifying and fixing any bugs. We appreciate your help in making this project better!

Contributing

We welcome contributions to improve react-voice-recorder-player. To contribute, please follow these steps:

  1. Fork the repository and clone it to your local machine.
  2. Install the package dependencies by running npm install.
  3. Commit your changes with a descriptive commit message.
  4. Push your changes to your forked repository.
  5. Submit a pull request to the main branch of the original repository.

Issues

If you encounter any issues while using react-voice-recorder-player, please feel free to open an issue on the project's GitHub repository. We welcome bug reports, feature requests, and other contributions from the community.

License

react-voice-recorder-player is licensed under the MIT License. See the LICENSE file for more information.

Author

1.2.0

8 months ago

1.1.0

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago