【发布时间】:2016-09-24 08:41:26
【问题描述】:
我有一个实时的、恒定的波形数据源,它为我提供了一秒钟的单通道音频,并且每秒具有恒定的采样率。目前我是这样玩的:
// 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 函数控制流?
- 有什么不同?
【问题讨论】:
-
找到的项目:github.com/scottstensland/websockets-streaming-audio 通过 websockets 流式传输波形文件,听起来不错:websockets-streaming-audio.herokuapp.com
标签: javascript html streaming web-audio-api