我有一个实时的恒定波形数据源,每秒钟以恒定的采样率为我提供第二个单通道音频。目前,我打他们这样说:WebAudio - 无缝播放音频块的序列
// data : Float32Array, context: AudioContext
function audioChunkReceived (context, data, sample_rate) {
var audioBuffer = context.createBuffer(2, data.length, sample_rate);
audioBuffer.getChannelData(0).set(data);
var source = context.createBufferSource(); // creates a sound source
source.buffer = audioBuffer;
source.connect(context.destination);
source.start(0);
}
音频播放罚款,但与正在播放的连续区块之间的明显停顿(如预期)。我想摆脱他们,我明白我将不得不介绍一些缓冲。
问题:
- 是否有一个JS库,能为我做到这一点? (我正在寻找它们的过程中)
- 如果没有图书馆可以做到这一点,我该怎么做呢?
- 检测播放在一个源中完成时是否有另一个准备好立即播放? (使用AudioBufferSourceNode.onended事件处理程序)
- 创建一个大缓冲区并一个接一个地复制我的音频块,并使用AudioBufferSourceNode.start AudioBufferSourceNode.stop函数控制流程?
- 有什么不同?
找到的项目:https://github.com/scottstensland/websockets-streaming-audio它通过WebSockets的流波形文件的话,听起来体面:http://websockets-streaming-audio.herokuapp.com/ – xmichaelx