音频数据流以HTML5格式 [英] Audio data streaming in HTML5
本文介绍了音频数据流以HTML5格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在以小块接收来自服务器的PCM音频数据,并将它们存储在一个阵列中。现在我想用一些HTML5功能按顺序播放这些音频块。我正在寻找的两种可能的解决方案是:
I am receiving PCM audio data from the server in small chunks and having them stored in an Array. Now I would like to play these audio chunks sequentially without gaps using some HTML5 capability. Two options which I am looking at as 'possible' solutions are:
- HTML5 Audio tag with Data URI
- Web audio API
当我调查这些选项,请向我建议任何其他选项或对我正在查看的两个选项的看法。虽然跨平台解决方案将是最好的,但我可以解决Chrome浏览器唯一的解决方案作为解决方案
While I am investigating these options, please suggest me any other option or views on the two options I am looking at. Though a cross platform solution will be the best but I can settle for Chrome only solution as
var startTime = 0;
for (var i = 0, audioChunk; audioChunk = AUDIO_CHUNKS[i]; ++i) {
// Create/set audio buffer for each chunk
var audioBuffer = audioCtx.createBuffer(NUM_CHANNELS, NUM_SAMPLES, SAMPLE_RATE);
audioBuffer.getChannelData(0).set(audioChunk);
var source = audioCtx.createBufferSource();
source.buffer = audioBuffer;
source.noteOn(startTime);
source.connect(audioCtx.destination);
startTime += audioBuffer.duration;
}
这篇关于音频数据流以HTML5格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文