edimuj / cordova-plugin-audioinput

This iOS/Android Cordova/PhoneGap plugin enables audio capture from the device microphone, by in near real-time forwarding audio to the web layer of your application. A typical usage scenario for this plugin would be to use the captured audio as source for a web audio node chain, where it then can be analyzed, manipulated and/or played.

Home Page:https://github.com/edimuj/app-audioinput-demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wav file is too large

ShyamSMoorthy opened this issue · comments

Hello , Am using the exact "CaptureCfg" configuration mentioned in the document , and everything working fine , But there is major issue we are facing is the wav file is way too large that we are not able to pass is to server or perform any other operations.
(Eg:If we record for 10 min , the blob size is around 165 MB)

Is there any possibility of reducing the wav file size , that would be very helpful .Thanks in advance.

audioinput.DEFAULT = {
SAMPLERATE: audioinput.SAMPLERATE.CD_AUDIO_44100Hz,
BUFFER_SIZE: 16384,
CHANNELS: audioinput.CHANNELS.MONO,
FORMAT: audioinput.FORMAT.PCM_16BIT,
NORMALIZE: true,
NORMALIZATION_FACTOR: 32767.0,
STREAM_TO_WEBAUDIO: false,
CONCATENATE_MAX_CHUNKS: 10,
AUDIOSOURCE_TYPE: audioinput.AUDIOSOURCE_TYPE.DEFAULT,
DEBUG: false
};

commented

I understand, WAV is an uncompressed audio format, which is the reason for why it is so large.

There are some things you could do to make the resulting file at bit smaller:

  1. SAMPLERATE can be lowered from 44100Hz to 16000Hz (audioinput.SAMPLERATE.VOIP_16000Hz) which probably is enough for most applications. That more than halves the number of samples, which directly cuts the size of the resulting WAV file (which should go from 165MB to around 60MB).
  2. Create several smaller recording chunks instead of a single big one and then concatenate them on the server.
  3. Compress the WAV before sending it to the server. There are a number of ways of doing this:
    3.1 Quick and dirty: Before sending the WAV, zip it using a client side library, for example https://github.com/Stuk/jszip: zip.file("audio.wav", blob); On the server, you then need to unzip the file before processing it.
    3.2 Convert the audio to a compressed audio format: Like for example here: https://github.com/Audior/Recordmp3js or using https://github.com/zhuker/lamejs or something similar.
    3.3 Using a Cordova plugin like for example: https://github.com/Tushar-Kanvinde/cordova-phonegap-audio-encode (for iOS) to convert the WAV to M4A.

I hope this helps!

commented

@ShyamSMoorthy since this issue hasn't been active for some time now, I will close it. Just let us know if there is any new information.