From d55f48ab9e34441ea206a00ffdac931f549b3a13 Mon Sep 17 00:00:00 2001 From: Jesse Date: Fri, 12 Nov 2021 17:14:06 -0500 Subject: [PATCH] inline alertNow into requestSpeech, see https://github.com/phetsims/utterance-queue/issues/37 --- js/accessibility/voicing/voicingManager.js | 30 ++++++---------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/js/accessibility/voicing/voicingManager.js b/js/accessibility/voicing/voicingManager.js index 0a6eaeb..0ccbd20 100644 --- a/js/accessibility/voicing/voicingManager.js +++ b/js/accessibility/voicing/voicingManager.js @@ -239,27 +239,6 @@ class VoicingManager extends Announcer { queue.splice( index, 1 ); } - /** - * Ask the synth to speak an utterance now (synchronously). - * @private - * - * @param {SpeechSynthesisUtterance} speechSynthesisUtterance - */ - alertNow( speechSynthesisUtterance ) { - const synth = voicingManager.getSynth(); - if ( synth ) { - - // Signify to the utterance-queue that we cannot speak yet until this utterance has finished - this.readyToSpeak = false; - - synth.speak( speechSynthesisUtterance ); - - if ( !this.hasSpoken ) { - this.hasSpoken = true; - } - } - } - /** * @override * @private @@ -434,7 +413,14 @@ class VoicingManager extends Announcer { // but the error event does. In this case signify that speaking has ended. speechSynthUtterance.addEventListener( 'error', endListener ); - this.alertNow( speechSynthUtterance ); + // Signify to the utterance-queue that we cannot speak yet until this utterance has finished + this.readyToSpeak = false; + + this.getSynth().speak( speechSynthUtterance ); + + if ( !this.hasSpoken ) { + this.hasSpoken = true; + } } /**