Mingliang Ma
Mingliang Ma

Reputation: 31

Audio file is corrupted using mediaRec.startRecord() from PhoneGap 1.6.1

I'm trying to record a sample audio on the actual device using media.startRecord() PhoneGap 1.6.1 API (http://docs.phonegap.com/en/1.6.1/cordova_media_media.md.html#media.startRecord). The startRecord() API can be executed with no error. The audio file is created after the recording is finished. However the size of the recorded audio file is very small (~9kB), compare to the recorded file from a commercial recording app with same length, but the size is around ~100kB. I downloaded the audio file from my app to Windows, and it's not playable.

I used the sample code from PhoneGap for audio recording:

function startRecording() {  
    // Create your Media object

    var src="recording.wav"
    mediaRec = new Media(src,

        // Success callback
        function() {
            console.log("mediaRec -> success");
        },

        // Error callback
        function(err) {
            if (typeof err.message != 'undefined')
                err = err.message;
            console.log("Error : " + err);
   });

    // Record audio
    mediaRec.startRecord();
}


function stopRecording(){  
    console.log("stop recording...");  
    mediaRec.stopRecord();  
}  

I added the following permissions in the AndroidManifest.xml:

<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

There is no error when the mediaRec.startRecord() and mediaRec.startRecord() were executed. The log looks like this:

11-23 11:46:34.975: I/Web Console(3646): start recording...  
11-23 11:46:35.178: I/AudioHardwareQSD(3216): AudioHardware PCM record is going to standby.  
11-23 11:46:35.178: I/AudioHardwareQSD(3216): do input routing device 40000  
11-23 11:46:35.178: I/AudioHardwareQSD(3216): Routing audio to speaker(builtin-mic)  
11-23 11:46:35.178: D/AudioHardwareQSD(3216): Switching audio device to   
11-23 11:46:35.178: D/AudioHardwareQSD(3216): Speakerphone  
11-23 11:46:35.178: I/MPEG4Writer(3216): limits: 2147483647/0 bytes/us, bit rate: 12200 bps and the estimated moov size 3072 bytes  
11-23 11:46:35.205: I/AudioHardwareQSD(3216): AudioHardware PCM record is going to standby.  
11-23 11:46:35.205: I/AudioHardwareQSD(3216): do input routing device 40000  
11-23 11:46:35.205: I/AudioHardwareQSD(3216): Routing audio to speaker(builtin-mic)  
11-23 11:46:35.205: D/AudioHardwareQSD(3216): Switching audio device to   
11-23 11:46:35.205: D/AudioHardwareQSD(3216): Speakerphone  
11-23 11:46:35.205: I/AudioHardwareQSD(3216): do input routing device 40000  
11-23 11:46:35.205: I/AudioHardwareQSD(3216): Routing audio to speaker(builtin-mic)  
11-23 11:46:35.445: I/MPEG4Writer(3216): setStartTimestampUs: 269619  
11-23 11:46:35.445: I/MPEG4Writer(3216): Earliest track starting time: 269619  
11-23 11:46:35.495: D/CordovaLog(3646): mediaRec -> success  
11-23 11:46:35.495: D/CordovaLog(3646): file:///data/data/com.voiceRec2/files/www/default/js/voiceRec2.js: Line 34 : mediaRec -> success  
11-23 11:46:35.495: I/Web Console(3646): mediaRec -> success at file:///data/data/com.voiceRec2/files/www/default/js/voiceRec2.js:34  
11-23 11:46:40.005: D/dalvikvm(3512): GC_EXPLICIT freed 290K, 45% free 3809K/6855K, external 1685K/2133K, paused 48ms  
11-23 11:46:44.995: D/CordovaLog(3646): mediaRec sr: recording.wav  

11-23 11:46:45.045: I/MPEG4Writer(3216): Received total/0-length (481/0) buffers and encoded 481 frames. - audio  
11-23 11:46:45.045: I/MPEG4Writer(3216): Audio track drift time: 118795 us  
11-23 11:46:45.085: I/AudioHardwareQSD(3216): AudioHardware PCM record is going to standby.  
11-23 11:46:45.085: I/AudioHardwareQSD(3216): do input routing device 40000  
11-23 11:46:45.085: I/AudioHardwareQSD(3216): Routing audio to speaker(builtin-mic)  
11-23 11:46:45.085: D/AudioHardwareQSD(3216): Switching audio device to   
11-23 11:46:45.085: D/AudioHardwareQSD(3216): Speakerphone  
11-23 11:46:45.085: I/AudioHardwareQSD(3216): do input routing device 0  
11-23 11:46:45.085: I/AudioHardwareQSD(3216): Routing audio to Speakerphone  
**11-23 11:46:45.085: D/MPEG4Writer(3216): 0 chunks are written in the last batch**  
11-23 11:46:45.105: D/CordovaLog(3646): mediaRec -> success  

The "0 chunks are written in the last batch" looks suspicious to be, but I do not know what does it mean. Can anyone show me where did I do wrong and point me to the right direction? Thank you in advance!! :)

Ming

Upvotes: 3

Views: 763

Answers (1)

Lenny T
Lenny T

Reputation: 409

The API docs for v1.6 don't mention this, but the latest API doc says that Android records in AMR format rather than WAV.

Upvotes: 1

Related Questions