Web Audio Api:通过套接字从nodejs服务器播放数据块的正确方法

我正在使用下面的代码来解码nodejs套接字的audio块

window.AudioContext = window.AudioContext || window.webkitAudioContext; var context = new AudioContext(); var delayTime = 0; var init = 0; var audioStack = []; var nextTime = 0; client.on('stream', function(stream, meta){ stream.on('data', function(data) { context.decodeAudioData(data, function(buffer) { audioStack.push(buffer); if ((init!=0) || (audioStack.length > 10)) { // make sure we put at least 10 chunks in the buffer before starting init++; scheduleBuffers(); } }, function(err) { console.log("err(decodeAudioData): "+err); }); }); }); function scheduleBuffers() { while ( audioStack.length) { var buffer = audioStack.shift(); var source = context.createBufferSource(); source.buffer = buffer; source.connect(context.destination); if (nextTime == 0) nextTime = context.currentTime + 0.05; /// add 50ms latency to work well across systems - tune this if you like source.start(nextTime); nextTime+=source.buffer.duration; // Make the next buffer wait the length of the last buffer before being played }; } 

但是,audio块之间有一些差距/毛刺,我无法弄清楚。

我也用MediaSource读过,可以做同样的事情,让播放器处理时间,而不是手动完成。 有人可以提供一个处理MP3数据的例子吗?

而且,哪种方法可以处理使用networkingaudioAPI进行直播? 我已经阅读了关于这个主题的几乎所有的问题,没有一个似乎没有毛刺工作。 有任何想法吗?