I just created a blob:
const audioBlob = new Blob(audioChunks, { 'type' : 'audio/wav; codecs=0' });
and sent it to the backend in base64 format. I saved this into a file named "test.wav" using the following code:
await writeFile('./temp/test.wav', Buffer.from(filename.replace('data:audio/wav; codecs=0;base64,', ''), 'base64'), 'base64');
On the output "test.wav" file, I get the codec as opus, bitrate=N/A and sample rate=48000. I want to change these values to codec=wav, bitrate=256kbps and sample rate=16000. How to achieve it in node(or angular)?
Here is a link for my frontend code.
This line just provides mime information but doesn't affect the actual output
const audioBlob = new Blob(audioChunks, { 'type' : 'audio/wav; codecs=0' });
To select correct audio codec and bitrate please start recording with following options
var options = {
audioBitsPerSecond : 128000,
mimeType : 'audio/ogg'
}
var mediaRecorder = new MediaRecorder(stream, options);
As far as I know ogg codec is supported by default in WebRTC, so it is cross browser compatible
Later, on the backend side, you will need to transform ogg
audio stream to anything else you want using for example fluent-ffmpeg
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With