Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome: onaudioprocess stops getting called after a while

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?

like image 365
kuu Avatar asked Jun 21 '14 04:06

kuu


1 Answers

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.

like image 59
cwilso Avatar answered Oct 18 '22 03:10

cwilso