1

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.

Manohar Gunturu
  • 676
  • 1
  • 10
  • 23

3 Answers3

2

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://blog.addpipe.com/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
octavn
  • 3,154
  • 32
  • 49
0

i think you should check this link : HTML5 record audio to file

here u can change the audio type like this : type = type || config.type || 'audio/wav';

Community
  • 1
  • 1
-2

You can change the format of the recording by mentioning the format in exportWAV function, as follows:

recorder.exportWAV(function (blob) {
                callback(blob);

                // create WAV download link using audio data blob
                // createDownloadLink();

                // Clear the Recorder to start again !
                recorder.clear();
            }, "audio/mp3");

I have came to the above solution for the following link.

Vishal
  • 707
  • 1
  • 8
  • 30
  • 3
    As far as I know, it only changes the mime type, it's not doing any compression to the recorded data. – Emi May 03 '18 at 11:44
  • When you send `audio/mpeg` instead of `audio/wav` to `exportWAV()` it just (erroneously) changes the MIME type of the wav Blob, it does not magically turn on mp3 encoding - you need the LAME mp3 encoding library for that. The tutorial you're quoting is incorrect in this regard. I've recently written an [up to date Recorder.js tutorial](https://addpipe.com/blog/using-recorder-js-to-capture-wav-audio-in-your-html5-web-site/). – octavn Jun 19 '18 at 14:27