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?
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);
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With