Update event name to MIC_LISTENING

This commit is contained in:
Eric Rosenbaum 2018-09-20 12:06:31 -04:00
parent 396d69743d
commit f5edcfa3bb
2 changed files with 11 additions and 8 deletions
src
engine
extensions/scratch3_speech2text

View file

@ -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);
}
/**

View file

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