npm install react-volume-indicator
useVolumeLevelhook
const [startRecording, stopRecording, volume] = useVolumeLevel();startRecording: Function called to start mic's recording; after calling this function value ofvolumewill start changingstopRecording: Function called to stop mic's recording; after calling this function value ofvolumewill remain 0volume: The value of mic's input volume in a 0-100 range, changing every 50ms
VolumeIndicatorcomponent
<VolumeIndicator backgroundColor="blue" indicatorColor="grey" volume={volume} />backgroundColor: Color of the container's backgroundindicatorColor: Color of the volume value display within the containervolume: A state variable between 0-100 that determines its value (similar to progress % in a progress bar)
Together they can be used like this -
import {useVolumeLevel, VolumeIndicator} from 'react-volume-indicator'
function App() {
const [startRecording, stopRecording, volume] = useVolumeLevel();
return (
<div>
<div style={{margin: 10}}>
<VolumeIndicator backgroundColor="blue" indicatorColor="grey" volume={volume} />
</div>
<button onClick={startRecording} style={{backgroundColor: 'red', padding: 10, margin: 10}}>
Record
</button>
<button onClick={stopRecording} style={{backgroundColor: 'green', padding: 10, }}>
Stop
</button>
</div>
);
}
export default App;Looking forward to pushing improvements iteratively and make it better!
