7

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?

Community
  • 1
  • 1
Leopd
  • 41,333
  • 31
  • 129
  • 167

2 Answers2

8

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);
Paranoid Android
  • 4,672
  • 11
  • 54
  • 73
2

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

SunnySonic
  • 1,318
  • 11
  • 37