1

I'm trying to get some live data on microphone data. So I hooked up a ScriptProcessorNode to the output of my live audio as follows (coffeescript):

audioSource = navigator.getUserMedia({audio:true},(stream)->
    source = context.createMediaStreamSource(stream)

    analyser = context.createScriptProcessor(1024,1,1)
    source.connect(analyser)

    analyser.onaudioprocess = (e)->
        \\Processing Takes Place here

However the onaudioprocess functions is never being called. What do I need to do to make it run?

4

2 回答 2

2

ScriptProcesseronaudioprocess如果其输出未连接到其他节点,则的事件将不会启动。

您可以检查此小提琴以查看它的实际效果。

var scr = context.createScriptProcessor(1024,1,1);

// uncomment the line below and onaudioprocess will start
//scr.connect(context.destination);

scr.onaudioprocess = function(){
    console.log('test');
};

只需将您的ScriptProcessortocontext.destination或虚拟gain节点的输出连接起来即可onaudioprocess启动。

于 2013-09-17T00:31:45.190 回答
0

像这样试试。我认为它会为你工作。

var source = context.createMediaStreamSource(stream);
        var proc = context.createScriptProcessor(2048, 2, 2);
        source.connect(proc);
        proc.connect(context.destination);
        proc.onaudioprocess = function(event)
        {
            var audio_data = event.inputBuffer.getChannelData(0)|| new Float32Array(2048);
            console.log(audio_data);
            iosocket.emit('audiomsg',audio_data); 
        }
于 2014-09-19T06:52:33.807 回答