phetsims / number-suite-common

"Number Suite Common" contains code for use by sims that are part of the Number Suite
GNU General Public License v3.0
0 stars 0 forks source link

Sometimes first speech synthesis sound is very delayed #59

Closed chrisklus closed 1 year ago

chrisklus commented 1 year ago

I've noticed on Mac + Chrome that occasionally the first time I request speech synthesis after loading the sim, there is an approximately 2 sec delay before hearing sound.

chrisklus commented 1 year ago

@zepumph recommends that this is not blocking until we observe it in a reproducible state.

chrisklus commented 1 year ago

@zepumph and I just saw this again when turning on the "Hear Number" control in Number Play. We turned the toggle on and then didn't hear "zero" for about 2 seconds.

chrisklus commented 1 year ago

We also saw a case that maybe happened not at startup but later in usage.

chrisklus commented 1 year ago

After adding debug logs, @zepumph and I just saw this again when turning on "Hear Number" in Number Play. We found that these logs happened immediately:

addToBack
UtteranceQueue.ts:584 ready to announce in attemptToAnnounce():  0
UtteranceQueue.ts:610 announcing:  0
SpeechSynthesisAnnouncer.ts:614 requestSpeech 0

And these logs were delayed by 1-2 seconds (with the delayed speech):

startSpeakingListener 0
SpeechSynthesisAnnouncer.ts:333 endSpeakingListener 0
SpeechSynthesisAnnouncer.ts:327 announcement complete 0

@zepumph says this means that it is an issue with the browser because we are requesting speech from our end immediately but it was the browsers response that took time. Now that we know this, we can remove these debug logs.

zepumph commented 1 year ago

@jessegreenberg, have you experienced this sort of a delay on windows or mac between requesting speech and having it start? No need to do any investigation just yet, I'm just wondering if this rings any bells outside of the chromeOS wake engine.

jessegreenberg commented 1 year ago

I have not. But one thing that rings a bell is that some (even many) voices are provided by a remote service. If that is the case, the speech may be delayed at first while it is downloaded by the browser. https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisVoice/localService

It might be worth checking if it is slow only for voices with localService false.

zepumph commented 1 year ago

Awesome and thanks! @chrisklus can check on his side.

zepumph commented 1 year ago

Today we worked with @stemilymill and @Nancy-Salpepi because @Nancy-Salpepi saw a delay with the German voice "Anna" but that wasn't a localService:false flag on that. In fact, @Nancy-Salpepi had 0 localService:false voices on safari, but Anna was consistently delayed.

Likely there isn't much to do about this, but it is good to know.

chrisklus commented 1 year ago

Thanks @jessegreenberg! I found that on Mac + Chrome the only localService:true voices were Google voices, which matches the behavior of @Nancy-Salpepi's machine since there are no Google voices in Safari. This may still be the cause of this issue sometimes, as I initially reported this happening right after startup in https://github.com/phetsims/number-suite-common/issues/59#issue-1635912408, and the default voice for me in Chrome is a Google voice. Hard to say since there are other, different use cases reported in this issue.

I think for now it seems reasonable to close this issue, as I don't think there is anything actionable to be done with the conclusions from https://github.com/phetsims/number-suite-common/issues/59#issuecomment-1487344429 and https://github.com/phetsims/number-suite-common/issues/59#issuecomment-1496201356. If this becomes more of a noticeable problem or something that we can have more influence over, we can reopen to keep investigating. Happy to keep open and deferred if anyone disagrees.