How to record audio in format of mp3/m4a JavaScript- recorder.js

Manohar Gunturu picture Manohar Gunturu · Aug 21, 2015 · Viewed 11.8k times · Source

In recorderjs rec.exportWAV([callback][, type]) is used to generate a Blob object containing the recorded audio in WAV format.

But the WAV file is taking large space, for 30sec it is approximately 1mb. So I want to record the audio in format of mp3/m4a which takes less space.

Is there any way to record audio in format of mp3/m4a.

Answer

Octavian Naicu picture Octavian Naicu · Jun 19, 2018

Recorder.js does NOT support encoding captured audio as mp3.

It can only record 16 bit mono or stereo uncompressed pcm as wav.

To halve the size you could record mono sound instead of 2 channel/stereo using numChannels:1 in the Recorder.js constructor like this:

var rec = new Recorder(source,{numChannels:1})

numChannels is an undocumented feature of Recorder.js (the library is not maintained anymore).

Source: https://addpipe.com/blog/using-recorder-js-to-capture-wav-audio-in-your-html5-web-site/

To record to mp3 you can use:

  1. WebAudioRecorder.js which includes an asm.js version of the LAME mp3 encoder
  2. vmsg which includes a WebAssembly version of the LAME mp3 encoder