From e44eff48e3fc82b9b1deef385f79f52d4b83fc5f Mon Sep 17 00:00:00 2001 From: Eric Rosenbaum Date: Tue, 18 Sep 2018 10:58:49 -0400 Subject: [PATCH] Add mic indicator update event for speech2text --- src/engine/runtime.js | 13 +++++++++++++ src/extensions/scratch3_speech2text/index.js | 3 +++ 2 files changed, 16 insertions(+) diff --git a/src/engine/runtime.js b/src/engine/runtime.js index daca604c7..68ab4e64c 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -457,6 +457,15 @@ class Runtime extends EventEmitter { return 'PERIPHERAL_SCAN_TIMEOUT'; } + /** + * Event name for requesting an update of the indicator that shows that the + * microphone is being used to stream audio. + * @const {string} + */ + static get UPDATE_MIC_INDICATOR () { + return 'UPDATE_MIC_INDICATOR'; + } + /** * Event name for reporting that blocksInfo was updated. * @const {string} @@ -989,6 +998,10 @@ class Runtime extends EventEmitter { return isConnected; } + requestMicIndicatorUpdate (visible) { + this.emit(Runtime.UPDATE_MIC_INDICATOR, visible); + } + /** * Retrieve the function associated with the given opcode. * @param {!string} opcode The opcode to look up. diff --git a/src/extensions/scratch3_speech2text/index.js b/src/extensions/scratch3_speech2text/index.js index 342de0abb..416903c8b 100644 --- a/src/extensions/scratch3_speech2text/index.js +++ b/src/extensions/scratch3_speech2text/index.js @@ -236,6 +236,8 @@ class Scratch3Speech2TextBlocks { * @private */ _stopListening () { + this.runtime.requestMicIndicatorUpdate(false); + // Note that this can be called before any Listen And Wait block did setup, // so check that things exist before disconnecting them. if (this._context) { @@ -436,6 +438,7 @@ class Scratch3Speech2TextBlocks { * @private */ _startListening () { + this.runtime.requestMicIndicatorUpdate(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);