Add mic indicator update event for speech2text

This commit is contained in:
Eric Rosenbaum 2018-09-18 10:58:49 -04:00
parent 64a1d3e02b
commit e44eff48e3
2 changed files with 16 additions and 0 deletions

View file

@ -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.

View file

@ -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);