Search code examples
javascripthtml5-audioweb-mediarecorder

Audio recording in JavaScript on Chrome, always sends video/ogg to the server


I have been trying to record audio in OGG format on Chrome and send it back to the server, but it always gets their in video/ogg format. Here is what I have:

Capturing audio:

let chunks = [];
let recording = null;

let mediaRecorder = new MediaRecorder(stream);
mediaRecorder.start();

mediaRecorder.onstop = function() {
    recording = new Blob(chunks, { 'type' : 'audio/ogg; codecs=opus' });
}

mediaRecorder.ondataavailable = function(e){
    chunks.push(e.data);
}

Sending it to the server:

let data = new FormData();
data.append('audio', recording);

jQuery.ajax(...);

The blob gets to the backend, but always in video/ogg!


Solution

  • I ended up using kbumsik/opus-media-recorder, solved the issue for me. A drop-in replacement for MediaRecorder.