'Chrome android text to speech not changing language
The code below works fine in Chrome desktop, but in Chrome Android, it's not using the msg.lang specified. The French text is being read out as if it was English, in an American accent. My phone's default language is English, does that matter? I want the page to read out in the selected language regardless of what settings the user has on their phone.
const msg = new SpeechSynthesisUtterance();
msg.volume = 1;
msg.text = text; // these words are in French
msg.lang = 'fr-FR';
speechSynthesis.speak(msg);
Solution 1:[1]
Changing the dash to an underscore fixed it, i.e., from 'fr-FR' to 'fr_FR'.
The documentation https://w3c.github.io/speech-api/#tts-section states that the code should be "BCP 47", which specifies a dash.
However, this article indicates that in some mobile implementations an underscore is used: https://manu.ninja/using-the-speech-synthesis-interface-of-the-web-speech-api
So making it an underscore fixed it. And the underscore works on desktop Chrome, too.
I won't mark this answer as accepted, in case there is a better answer.
Solution 2:[2]
I believe this is an error with Chrome. I have similar code to the original poster, which works fine in Firefox. There doesn't appear to be a reliable way to fix it, unfortunately.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Phil Francis |
