From d2cff42a993079fd098fb88d8c32f893adac1d82 Mon Sep 17 00:00:00 2001 From: picklesrus Date: Wed, 9 May 2018 11:57:14 -0700 Subject: [PATCH] Remove the event listener for processing audio at the same time that we disconnect the script node. At this point we are closing the web socket and do not want to process more of the microphone data even if it is already in flight. Also add it back when we resume listening instead of just at init time. --- src/extensions/scratch3_speech/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/extensions/scratch3_speech/index.js b/src/extensions/scratch3_speech/index.js index a0bc78847..166c6de36 100644 --- a/src/extensions/scratch3_speech/index.js +++ b/src/extensions/scratch3_speech/index.js @@ -319,6 +319,7 @@ class Scratch3SpeechBlocks { // This is called on green flag to reset things that may never have existed // in the first place. Do a bunch of checks. if (this._scriptNode) { + this._scriptNode.removeEventListener('audioprocess', this._processAudioCallback); this._scriptNode.disconnect(); } if (this._sourceNode) { @@ -522,6 +523,7 @@ class Scratch3SpeechBlocks { */ _resumeListening () { this._context.resume.bind(this._context); + this._scriptNode.addEventListener('audioprocess', this._processAudioCallback); this._newWebsocket(); }