我希望能够从ArrayBuffer中播放音频数据......因此我生成了我的数组并用麦克风输入填充它。
如果我在画布上绘制这些数据,它看起来像 -->
所以这个方法可行!
但是如果我想要收听这些数据,则:
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*/);
But i get the error: Uncaught SyntaxError: An invalid or illegal string was specified.anybody who can give me a hint ?
EDIT 1 (More code and how I get the mic input):
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.
谢谢你的帮助!