From b95b8d41ffe9aa8bbbe78b758d8c6c06ead1d974 Mon Sep 17 00:00:00 2001 From: picklesrus Date: Mon, 27 Aug 2018 08:10:51 -0700 Subject: [PATCH] Fix #1395 by resetting the utterance we check for in the edge trigger hat on green flag (#1476) --- src/extensions/scratch3_speech/index.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/extensions/scratch3_speech/index.js b/src/extensions/scratch3_speech/index.js index 84e4b6e7..673cf576 100644 --- a/src/extensions/scratch3_speech/index.js +++ b/src/extensions/scratch3_speech/index.js @@ -82,7 +82,8 @@ class Scratch3SpeechBlocks { this._currentUtterance = ''; /** - * Similar to _currentUtterance, but set back to '' at the beginning of listening block. + * Similar to _currentUtterance, but set back to '' at the beginning of listening block + * and on green flag. * Used to get the hat blocks to edge trigger. In order to detect someone saying * the same thing twice in two subsequent listen and wait blocks * and still trigger the hat, we need this to go from @@ -188,6 +189,7 @@ class Scratch3SpeechBlocks { this.runtime.on('PROJECT_STOP_ALL', this._resetListening.bind(this)); + this.runtime.on('PROJECT_START', this._resetEdgeTriggerUtterance.bind(this)); // Load in the start and stop listening indicator sounds. this._loadUISounds(); @@ -295,6 +297,15 @@ class Scratch3SpeechBlocks { this._resolveSpeechPromises(); } + /** + * Reset the utterance we look for in the when I hear hat block back to + * the empty string. + * @private + */ + _resetEdgeTriggerUtterance () { + this._utteranceForEdgeTrigger = ''; + } + /** * Close the connection to the socket server if it is open. * @private @@ -738,7 +749,7 @@ class Scratch3SpeechBlocks { // TODO: Question - Should we only play the sound if listening isn't already in progress? return this._playSound(this._startSoundPlayer).then(() => { this._phraseList = this._scanBlocksForPhraseList(); - this._utteranceForEdgeTrigger = ''; + this._resetEdgeTriggerUtterance(); const endSound = (shouldPlayEndSound => { if (shouldPlayEndSound) {