I am recording audio from getUserMedia({audio:true}); in the browser using Recorder.js and then exporting it as a WAV file because that\'s the only option the l
I had a similar issue (also using recorder.js) and have managed to resolve using the superb videoconverter.js project which includes a port of ffmpeg to Javascript using emscripen. Downside to this is the ffmpeg.js file is about 25Mb.
I modified the existing exportWAV function in recorderWorker.js to return both a WAV (for HTML5 playback) and a Blob containing an encoded MP2 file:
function encodeWAV(samples) {
var buffer = new ArrayBuffer(44 + samples.length * 2);
var view = new DataView(buffer);
/* ... various writing methods */
return { wavdata: new Blob([buffer], { type: "audio/wav" }), mp2data: ffmpeg_convert(buffer) };
}
function ffmpeg_convert(buffer) {
console.log("starting mp2 conversion");
var args = "-i input -f mp2 output.mp2";
var results = ffmpeg_run({
arguments: args.split(" "),
files: [
{
data: new Uint8Array(buffer),
"name": "input"
}
]
});
if (results) {
var file = results[0];
console.log("File recieved", file.name, file.data);
return new Blob([file.data], { type: "audio/mpeg" });
}
return null;
}
This method can be used to encode the WAV to any codec suppored by ffmpeg's libavcodec