Chrome: onaudioprocess stops getting called after a while

£可爱£侵袭症+ 提交于 2019-12-23 08:49:12

问题


I'm using ScriptProcessorNode's onaudioprocess callback to process the microphone input. By connecting MediaStreamSourceNode to the ScriptProcessorNode, I can get the raw audio data within the onaudioprocess callback function. However, after about 30 seconds (this varies ranging from 10 to 35 sec,) the browser stops calling onaudioprocess. In the following code, the console.log output ('>>') always stops after about 30 sec.

var ctx = new AudioContext();
var BUFFER_LENGTH = 4096;
console.log('Buffer length is + ' + BUFFER_LENGTH);
navigator.webkitGetUserMedia({audio: true}, function (stream) {
    var mediaStreamSource = ctx.createMediaStreamSource(stream);
    var scriptProcessor = ctx.createScriptProcessor(BUFFER_LENGTH, 1, 1);
    scriptProcessor.onaudioprocess = function (e) {
      console.log('>>');
    };
    scriptProcessor.connect(ctx.destination);
}, function(e) {
  console.error('Unable to get audio input source.');
});

I tried all the possible BUFFER_LENGTH (256, 512, 1024, 2048, 4096, 8192, 16384), but the situation didn't change (log stops after 30 sec.) I observed this issue in the latest Chrome Release (Version 35.0.1916.153) and Canary (Version 37.0.2060.3 canary.) Does anyone know any workarounds?


回答1:


This looks more like your scriptprocessor object is getting garbage collected. Try saving it in a global variable and see if that fixes the problem.



来源:https://stackoverflow.com/questions/24338144/chrome-onaudioprocess-stops-getting-called-after-a-while

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!