Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhoneGap Android plugin for higher quality audio recording?

The PhoneGap media API provides a mechanism to record audio in a cross-platform way which works on android, but the audio quality is completely horrible -- 8 kHz sampling rate and perhaps some highly lossy codec as well. I understand from this SO question that with java code it's possible to get higher quality audio recording.

Anybody know of a PhoneGap plugin for Android that allows for higher quality audio recording?

like image 451
Leopd Avatar asked Sep 09 '11 05:09

Leopd


2 Answers

For anyone interested, what we did was dropping support for anything less than Android 2.3 and modify the Cordova native code ourselves.

If you are using Cordova 3+, I forked the project with the code changes here

For previous releases, just modify AudioPlayer.java (this is from Cordova 2.9)

 // support only 2.3.3+ to be able to record AAC with 44100 audio sampling
 this.recorder.setAudioSamplingRate(44100);
 this.recorder.setAudioEncodingBitRate(96000);
 this.recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
 this.recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);

 //this.recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);// THREE_GPP);
 //this.recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);// //AMR_NB);
like image 162
Mirko Avatar answered Sep 22 '22 00:09

Mirko


You will have to write your own plugin unfortunately.

Here a list of current plugins: https://github.com/phonegap/phonegap-plugins/tree/master/Android

For IOS there is an older audio record one. Maybe you can have a look there:

https://github.com/phonegap/phonegap-plugins/tree/master/iOS/AudioRecord

Creating a plugin is not such a big deal though. Here some code for the actual recording:

http://www.androiddevblog.net/android/android-audio-recording-part-2

http://developer.android.com/reference/android/media/AudioRecord.html

like image 39
SunnySonic Avatar answered Sep 20 '22 00:09

SunnySonic