1

我目前正在开发对讲机类型的环境。录制和重新采样音频现在可以正常工作(感谢您的帮助),播放作品..有点。

我的数据来自(WAV-)blob,所以这就是我所做的:

audioPlay(blob)
{
        var fileReader = new FileReader();
        fileReader.onload = function() {
                theContext.decodeAudioData(this.result, function(buffer) {
                        var source = theContext.createBufferSource(); 
                        source.buffer = buffer;
                        source.connect(theContext.destination);
                        source.start(0);
                        });
                };
        fileReader.readAsArrayBuffer(blob);
}

但是每个新音频都会增加一个轻微的启动延迟,该延迟会随着每个新音频而增长。几声音频后,延迟增加了将近 2-3 秒。日志记录没有显示任何延迟,程序一直流畅到.source.start。

有任何想法吗?

4

2 回答 2

0

Michaela, this sounds more like it might be a problem in the source - are you sure each incoming blob is correct (of correct length, and has audio at the beginning?) It seems like it might be that you're just tacking the new recording on to the end of an empty buffer at that end. Barring that specific problem, I'd take a look at the audio blob that's coming in - maybe the decode is too expensive for some reasons? (I.e. if you have a 2-3 second cumulative delay, you should be able to tell from logging if the delay is in receiving the data, decoding it, or in the buffer itself.

于 2013-12-23T14:50:07.887 回答
0

不要为每个样本从 0 开始播放。而是跟踪时间。

 if (nextTime == 0) { nextTime = context.currentTime }
 source.start(nextTime);
 nextTime+=source.buffer.duration; 
于 2013-12-21T00:27:52.010 回答