C-Nedelcu / talk-to-chatgpt

Talk to ChatGPT AI using your voice and listen to its answers through a voice
GNU Affero General Public License v3.0
1.97k stars 331 forks source link

Selected text-to-speech voice is saved but not loaded correctly (tested in Microsoft Edge) #15

Closed rotemdan closed 1 year ago

rotemdan commented 1 year ago

If I select a voice from the menu, it works temporarily, but then resets to the default voice when the page is reloaded.

I looked further into it and I noticed that after the page is reloaded the console does show the log:

Reloading settings from cookie: en-US-Microsoft Zira - English (United States),1,1,,stop,pause

Which means that the voice name is saved and and then loaded from the cookie, and this conditional body is reached:

if (voice.lang + "-" + voice.name == CN_WANTED_VOICE_NAME) {
    CN_WANTED_VOICE = voice;
    console.log("I will read using voice " + voice.name + " (" + voice.lang + ")");
    return false;
}

The CN_WANTED_VOICE variable should be assigned with the correct voice, but it doesn't seem to actually use it?

The voice falls back to the default one (Microsoft David) and no related message is shown in the console.

I'm not sure why this is happening. It's strange, since the log message shows that it is loaded correctly.

dev-eduka commented 1 year ago

does it happen specifically for that particular voice? for example I have no issue with other voices like French, the voice is saved and restored correctly upon reopening the page. can you try other voices and see if the problem still happens?

rotemdan commented 1 year ago

I found the cause, and apparently it is external. It happened due to a conflict with a secondary text-to-speech extension I have, that was apparently resetting the voice when the page was loaded.

Once I disabled the secondary extension, the issue was resolved.

I'll close this issue.

rotemdan commented 1 year ago

After further investigation, I've isolated that the reason the secondary extension (written by myself) was causing the voice to be reset, was only because it added an event handler to voiceschanged on the page's speechSynthesis object.

It doesn't matter even if the event handler on the secondary extension is empty, the issue still occurs:

speechSynthesis.addEventListener('voiceschanged', () => {
    // nothing here
})

I don't know why would adding a secondary event handler on voiceschanged would cause the voice to be reset, or to impact somehow the execution of the other handler. I've experimented and verified that it is actually the cause.

It may be a bug specific to Microsoft Edge, or a some strange behavior of the Web Speech API itself.