Search code examples
google-chromefirefoxwavgetusermediarecorder.js

How to Reduce wav File-size created by Recorder.js


I am using recorder.js to upload user's audio files on our server. This is working in chrome and firefox both..But our audio file will be around 1 minute and for 1 minute audio file its generating approx 8 MB file which is too large to upload on server..

I have tried to update recorderWorker.js file:

Updated interleave method as

function interleave(inputL, inputR)
{
  var result = new Float32Array(inputL.length);
   for (var i = 0; i < inputL.length; ++i)
    result[i] = 0.5 * (inputL[i] + inputR[i]);
  return result;
}

and set channel-count as

/* channel count */
view.setUint16(22, 1, true);

By this above code my file was created in just half size ie of 4 MB. when I play this file in chrome it is working but when I try this file in firefox and windows media player..This is not working..In firefox its giving failed to load and in windows media player giving "Windows Media Player encountered a problem while playing the file." message.

I have created 2 samples:

http://216.245.194.124/recorduploadsample.com/
http://216.245.194.124/recorduploadsample2.com/

First sample will work in both chrome and firefox and after record anything we can play the recorded sound..(This is original code with large file size)

Second sample is working only in chrome not in firefox (Updated above code to reduce the file size)

I need to reduce the file size by changing resolution of the audio file and that should work in chrome, firefox both...Can anyone suggest the solution for this?

Thanks in Advance


Solution

  • The problem with wav is that the files are non-compressed, therefore they take up a lot of space on the disk, just 1 minute of recording can take as much as 10 Megabytes.

    The solution to this? Well let’s convert the wav file to mp3. Simply saving the wav file and then converting it will not do. We will need to convert the recording, to mp3, in real time, in the browser.

    https://nusofthq.com/blog/recording-mp3-using-only-html5-and-javascript-recordmp3-js/