Web Audio API - record to MP3? Web Audio API - record to MP3? javascript javascript

Web Audio API - record to MP3?


The only Javascript MP3 encoder I've seen is https://github.com/akrennmair/libmp3lame-js, which is a port using emscripten. It's supposed to be slow, and I've never used it.

I don't know of any natively-written Javascript MP3 encoders, and encoding is not covered by the Web Audio API.


There's a library written in pure javascript, called lamejs. To encode mp3s from raw audio. It is much faster than emscripten compile of libmp3lame. https://github.com/zhuker/lamejs

Example usage:

lib = new lamejs();mp3encoder = new lib.Mp3Encoder(1, 44100, 128); //mono 44.1khz encode to 128kbpssamples = new Int16Array(44100); //one second of silencevar mp3 = mp3encoder.encodeBuffer(samples); //encode mp3


I was frustrated with this problem, and existing solutions, so I came up with something simpler:

https://github.com/sb2702/audioRecord.js

Usage

Create a recorder object (async because requires user permission)

    Recorder.new(function(recorder){     }); 

Start recording

         recorder.start();        

Stops recording

         recorder.stop();    

Export as mp3

         recorder.exportMP3(function(mp3Blob){             console.log("Here is your blob: " + URL.createObjectURL(mp3Blob));          });

Mostly based on RecorderJS, but changed some things around to export to mp3 files, and to not have to muck around with AudioContext / navigator.getUs