recorder-realtime
v1.3.0
Published
a realtime audio recorder that can generate pcm or mp3 with configurable sample rate and bit depth
Downloads
16
Maintainers
Readme
Explaination
a realtime audio recorder, it can generate
pcm
ormp3
buffer of audio data with configurable sample rate and bit depth.when recording, it start a web worker thread in the browser to transform the
bitDepth
andsampleRate
, so it's very fast in realtimeplease remember to using this package under
https
, or it won't work
Usage
import Recorder from 'recorder-realtime';
function initRecorder() {
if (!Recorder.isRecordingSupported()) {
this.screenLogger('Recording features are not supported in your browser.')
} else {
recorder = new Recorder({
recordingGain: parseInt(this.recordingGain, 10),
numberOfChannels: 1, // this is suggested
wavBitDepth: 16,
format: 'mp3', // default to pcm, which is larger
wavSampleRate: 16000,
streamPages: true // we can get the buffer stream in realtime in the ondataavailable callback
})
recorder.onstart = () => {
console.log('recorder started');
}
recorder.onstreamerror = e => {
this.screenLogger('Error encountered: ' + e.message)
}
this.recorder.ondataavailable = data => {
if (data.command === 'buffer') {
this.sendBlogToServer(data.buffer); // 片段数据,bufferLength的大小
} else if (data.command === 'wav') {
const dataBlob = new Blob([typedArray], { type: 'audio/wav' })
const url = URL.createObjectURL(dataBlob)
this.audioSrc = url
}
}
recorder.start();
}
}
Optional Configuration
bufferLength - (optional) default to
4096
, which means when theondataavailable
function called, the size of response buffer will be4096
monitorGain - (optional) set the echo of your recording, the value range is
0-1
, default to0
, which means mute the echonumberOfChannels - (optional) 1 or 2, 1 is suggested
recordingGain - (optional) the volume of your voice, the value range is
0-1
, default to1
wavBitDepth - (optional) the bit length of the recordered buffer, default is
16
, you can set it to8
,16
,24
,32