【发布时间】:2013-11-11 23:28:19
【问题描述】:
我想从 ArrayBuffer 播放音频数据...所以我生成了我的数组并用 microfone 输入填充它。 如果我在画布上绘制这些数据,它看起来像 -->
所以这行得通!
但如果我想用
收听这些数据context.decodeAudioData(tmp, function(bufferN) { //tmp is a arrayBuffer
var out = context.createBufferSource();
out.buffer = bufferN;
out.connect(context.destination);
out.noteOn(0);
}, errorFunction);
我什么也没听到……因为调用了 errorFunction。但错误为空!
我也尝试过这样获取缓冲区:
var soundBuffer = context.createBuffer(myArrayBuffer, true/*make mono*/);
但我得到错误:未捕获的语法错误:指定了无效或非法的字符串。
谁能给我一个提示?
编辑 1(更多代码以及我如何获得麦克风输入):
navigator.webkitGetUserMedia({audio: true}, function(stream) {
liveSource = context.createMediaStreamSource(stream);
// create a ScriptProcessorNode
if(!context.createScriptProcessor){
node = context.createJavaScriptNode(2048, 1, 1);
} else {
node = context.createScriptProcessor(2048, 1, 1);
}
node.onaudioprocess = function(e){
var tmp = new Uint8Array(e.inputBuffer.byteLength);
tmp.set(new Uint8Array(e.inputBuffer.byteLength), 0);
//Here comes the code from above.
感谢您的帮助!
【问题讨论】:
-
能否也包含从麦克风获取数据的代码?
-
当然。请看我的变化。谢谢
-
我觉得很有帮助 - stackoverflow.com/questions/10365335/…
-
回调函数返回的错误为空,因为在当前的 webaudio api 规范中,该函数不返回对象错误,“回调 DecodeErrorCallback = void ();”看看w3.org/TR/webaudio/#AudioContext-section。
标签: javascript html buffer decode html5-audio