Chrome android text to speech not changing language
Asked Answered
B

2

4

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);
Blintz answered 24/6, 2019 at 0:31 Comment(1)
I am having the same issue! did you figure it out? I created another post about it here: #61816898Pantagruel
B
0

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.

Blintz answered 24/6, 2019 at 13:18 Comment(1)
This doesn't seem to work reliably. After getting text in a French voice for some time, it again reverted to reading out French text in an American voice and I don't know why. So the original question still stands.Blintz
B
0

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.

Bilinear answered 18/5, 2022 at 12:53 Comment(1)
Same issue here, works, with firefox (mobile / desktop) and chrome desktop but on chrome mobile its wonky. It works first time I set it, but when I change language it goes bananas.Costanzia

© 2022 - 2024 — McMap. All rights reserved.