Skip to content

Commit

Permalink
capture previousUtterance synchronously for next announce() call, p…
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed May 3, 2021
1 parent 6922095 commit 4bb06ce
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions js/accessibility/speaker/webSpeaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,13 @@ class WebSpeaker {
// doesn't dispose of it before firing, see #215
this.utterances.push( speechSynthUtterance );

// Keep this out of the start listener so that it can be synchrounous to the UtteranceQueue draining/announcing, see bug in https://github.com/phetsims/sun/issues/699#issuecomment-831529485
this.previousUtterance = utterance;

const startListener = () => {
this.startSpeakingEmitter.emit( utterance );
this.speakingProperty.set( true );
speechSynthUtterance.removeEventListener( 'start', startListener );

this.previousUtterance = utterance;
};

const endListener = () => {
Expand Down Expand Up @@ -287,6 +288,9 @@ class WebSpeaker {
utterance.pitch = this.voicePitchProperty.value;
utterance.rate = this.voiceRateProperty.value;

// Keep this synchrounous as it pertains to the UtteranceQueue draining/announcing, see bug in https://github.com/phetsims/sun/issues/699#issuecomment-831529485
this.previousUtterance = utterance;

this.synth.speak( utterance );
}
}
Expand Down

0 comments on commit 4bb06ce

Please sign in to comment.