html5 decodeaudio,javascript - decodeAudioData HTML5 Audio API - Stack Overflow

The returned error from the callback function is null because in the current webaudio api spec that function does not return an object error

callback DecodeSuccessCallback = void (AudioBuffer decodedData);

callback DecodeErrorCallback = void ();

void decodeAudioData(ArrayBuffer audioData,

DecodeSuccessCallback successCallback,

optional DecodeErrorCallback errorCallback);

DecodeSuccessCallback is raised when the complete input ArrayBuffer is decoded and stored internally as an AudioBuffer but for some unknown reason decodeAudioData can not decode a live stream.

You can try to play the captured buffer setting the output buffer data when processing audio

function connectAudioInToSpeakers(){

//var context = new webkitAudioContext();

navigator.webkitGetUserMedia({audio: true}, function(stream) {

var context = new webkitAudioContext();

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){

try{

ctx.clearRect(0, 0, document.getElementById("myCanvas").width, document.getElementById("myCanvas").height);

document.getElementById("myCanvas").width = document.getElementById("myCanvas").width;

ctx.fillStyle="#FF0000";

var input = e.inputBuffer.getChannelData(0);

var output = e.outputBuffer.getChannelData(0);

for(var i in input) {

output[i] = input[i];

ctx.fillRect(i/4,input[i]*500+200,1,1);

}

}catch (e){

console.log('node.onaudioprocess',e.message);

}

}

// connect the ScriptProcessorNode with the input audio

liveSource.connect(node);

// if the ScriptProcessorNode is not connected to an output the "onaudioprocess" event is not triggered in chrome

node.connect(context.destination);

//Geb mic eingang auf boxen

//liveSource.connect(context.destination);

});

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值