Chrome android text to speech not changing language

亡梦爱人 提交于 2019-12-13 02:47:21

问题


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);

回答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.



来源:https://stackoverflow.com/questions/56728654/chrome-android-text-to-speech-not-changing-language

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!