播放生成的声音 [英] play back generated sounds
本文介绍了播放生成的声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想捕获音频(在我的情况下来自 getUserMedia
)并播放它。我能够将一堆AudioBuffers推送到这样的数组:
I want to capture audio (in my case from getUserMedia
) and play it back. I'm able to push a bunch of AudioBuffers to an array like so:
var recorder = audio_context.createJavaScriptNode(256, 2, 2);
recorder.onaudioprocess = function(e) {
recorded.push(e.inputBuffer.getChannelData(0));
// or just:
// recorded.push(e.inputBuffer);
};
recorder.connect(audio_context.destination);
但是我如何在记录的$ c中播放缓冲区$ c> array?
But then how do I play the buffers in the recorded
array?
将这些合并到一个缓冲区并用 createBufferSource
进行播放的方法?
A way to merge these into one buffer and play it with createBufferSource
?
一个完全不同的方法?
推荐答案
完成音频录制后,您应该能够执行以下操作:
Once you're done recording the audio, you should be able to do the following:
var bufferIndex = 0;
recorder.onaudioprocess = function (e) {
var outputData = e.outputbuffer.getChannelData(0);
var recordedData = recorded[bufferIndex];
for (var i = 0; i < recordedData.length; i++) {
outputData[i] = recordedData[i];
});
bufferIndex++;
}
(你可以更简单/更清洁;这只是为了说明目的)
(You can probably make that simpler/cleaner; this was just for illustration purposes)
这篇关于播放生成的声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文