diff --git a/src/engine/runtime.js b/src/engine/runtime.js index 68ab4e64..d634dbc8 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -458,12 +458,11 @@ class Runtime extends EventEmitter { } /** - * Event name for requesting an update of the indicator that shows that the - * microphone is being used to stream audio. + * Event name to indicate that the microphone is being used to stream audio. * @const {string} */ - static get UPDATE_MIC_INDICATOR () { - return 'UPDATE_MIC_INDICATOR'; + static get MIC_LISTENING () { + return 'MIC_LISTENING'; } /** @@ -998,8 +997,12 @@ class Runtime extends EventEmitter { return isConnected; } - requestMicIndicatorUpdate (visible) { - this.emit(Runtime.UPDATE_MIC_INDICATOR, visible); + /** + * Emit an event to indicate that the microphone is being used to stream audio. + * @param {boolean} listening - true if the microphone is currently listening. + */ + emitMicListening (listening) { + this.emit(Runtime.MIC_LISTENING, listening); } /** diff --git a/src/extensions/scratch3_speech2text/index.js b/src/extensions/scratch3_speech2text/index.js index fcb5b5ed..184eef5d 100644 --- a/src/extensions/scratch3_speech2text/index.js +++ b/src/extensions/scratch3_speech2text/index.js @@ -207,7 +207,7 @@ class Scratch3Speech2TextBlocks { * @private. */ _resetListening () { - this.runtime.requestMicIndicatorUpdate(false); + this.runtime.emitMicListening(false); this._stopListening(); this._closeWebsocket(); this._resolveSpeechPromises(); @@ -437,7 +437,7 @@ class Scratch3Speech2TextBlocks { * @private */ _startListening () { - this.runtime.requestMicIndicatorUpdate(true); + this.runtime.emitMicListening(true); this._initListening(); // Force the block to timeout if we don't get any results back/the user didn't say anything. this._speechTimeoutId = setTimeout(this._stopTranscription, listenAndWaitBlockTimeoutMs);