3

我正在尝试使用 media.startRecord() PhoneGap 1.6.1 API(http://docs.phonegap.com/en/1.6.1/cordova_media_media.md.html#media.startRecord在实际设备上录制示例音频)。startRecord() API 可以正常执行。录制完成后会创建音频文件。但是录制的音频文件的大小非常小(~9kB),与来自商业录音应用程序的相同长度的录音文件相比,但大小约为~100kB。我将音频文件从我的应用程序下载到 Windows,但无法播放。

我使用 PhoneGap 的示例代码进行录音:

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();  
}  

我在 AndroidManifest.xml 中添加了以下权限:

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

执行 mediaRec.startRecord() 和 mediaRec.startRecord() 时没有错误。日志如下所示:

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  

“最后一批中写入了 0 个块”看起来很可疑,但我不知道这是什么意思。谁能告诉我我在哪里做错并指出正确的方向?先感谢您!!:)

4

1 回答 1

1

v1.6 的 API 文档没有提到这一点,但最新的 API 文档说 Android 以 AMR 格式而不是 WAV 记录。

于 2013-03-01T16:44:52.170 回答