AudioRecord plugin on Cordova/Phonegap 1.9.0

Phonegap’s Media.startAudioRecord on ios records 16 bit stereo uncompressed WAV. Not exactly ideal for uploading afterwards. The AudioRecord plugin for ios allows full access to the available Core Audio encoders. The installation instructions are less than required, so after piecing together some items from across the web, here are some edited instructions (if I knew my way around GitHub, I would try to add this directly to the plugin’s page):

  1. Make sure your PhoneGap Xcode project has been updated. [comment: whatever that means, I did not do this]
  2. Add the .h and .m files to your Plugins folder in your project, by dropping them into the folder in XCode itself
  3. Add the .js files to your “www” folder on disk, and add reference(s) to the .js files in your html file(s). [This is not necessary, as we will do the link differently]
  4. Add the following to your onDeviceReady() function:

  5. Media.prototype.startRecordWithSettings = function(options) {
    Cordova.exec(null, null, "AudioRecord","startAudioRecord", [this.id, this.src, options]);
    };
    Media.prototype.stopRecordWithSettings = function() {
    Cordova.exec(null, null, "AudioRecord","stopAudioRecord", [this.id, this.src]);
    };

  6. Use this as a framework for modifying your existing media.startAudioRecord() and media.stopAudioRecord() usage – the file supplied should be .caf and not .wav

  7. var recordSettings = {
    "FormatID": "kAudioFormatAppleLossless",
    "SampleRate": 44100.0,
    "NumberOfChannels": 1,
    "LinearPCMBitDepth": 16
    }
    mediaRec.startRecordWithSettings(recordSettings);

    // Stop recording after 10 sec
    var recTime = 0;
    var recInterval = setInterval(function() {
    recTime = recTime + 1;
    setAudioPosition(recTime + " sec");
    if (recTime >= 10) {
    clearInterval(recInterval);
    mediaRec.stopRecordWithSettings();
    }
    }, 1000);

  8. A list of the valid audio formats can be found within the AudioRecord.m file or with some more explanation at http://developer.apple.com/library/ios/#qa/qa1615/_index.html

Other References: