Skip to content

Commit

Permalink
Only step the queue of voicingManager is initialized, see phetsims/sc…
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegreenberg committed Feb 7, 2022
1 parent 0d89299 commit 2e725e8
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions js/accessibility/voicing/voicingManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,23 +248,26 @@ class VoicingManager extends Announcer {
*/
stepQueue( dt ) {

// increase the time each element has spent in queue
for ( let i = 0; i < this.voicingQueue.length; i++ ) {
const voicingQueueElement = this.voicingQueue[ i ];
voicingQueueElement.timeInQueue += dt * 1000;
}
if ( this.initialized ) {

// This manages the case where the 'end' event came from an utterance, but there was no next utterance ready to be
// spoken. Make sure that we support anytime that utterances are ready but there is no "end" callback that would
// trigger `alertNow()`.
if ( !this.getSynth().speaking && this.voicingQueue.length > 0 ) {
this.alertNow();
}
// increase the time each element has spent in queue
for ( let i = 0; i < this.voicingQueue.length; i++ ) {
const voicingQueueElement = this.voicingQueue[ i ];
voicingQueueElement.timeInQueue += dt * 1000;
}

// If our queue is empty and the synth isn't speaking, then clear safariWorkaroundUtterances to prevent memory leak.
// This handles any uncertain cases where the "end" callback on SpeechSynthUtterance isn't called.
if ( !this.getSynth().speaking && this.voicingQueue.length === 0 && this.safariWorkaroundUtterances.length > 0 ) {
this.safariWorkaroundUtterances = [];
// This manages the case where the 'end' event came from an utterance, but there was no next utterance ready to be
// spoken. Make sure that we support anytime that utterances are ready but there is no "end" callback that would
// trigger `alertNow()`.
if ( !this.getSynth().speaking && this.voicingQueue.length > 0 ) {
this.alertNow();
}

// If our queue is empty and the synth isn't speaking, then clear safariWorkaroundUtterances to prevent memory leak.
// This handles any uncertain cases where the "end" callback on SpeechSynthUtterance isn't called.
if ( !this.getSynth().speaking && this.voicingQueue.length === 0 && this.safariWorkaroundUtterances.length > 0 ) {
this.safariWorkaroundUtterances = [];
}
}
}

Expand Down

0 comments on commit 2e725e8

Please sign in to comment.