Chrome Android文本到语音不会更改语言 [英] Chrome android text to speech not changing language

查看:129
本文介绍了Chrome Android文本到语音不会更改语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码在Chrome桌面上可以正常运行,但是在Chrome Android中,它未使用指定的msg.lang.像美国英语一样,正在朗读法语文本,就好像它是英语一样.手机的默认语言是英语,这有关系吗?无论用户在手机上进行了哪些设置,我都希望页面以选定的语言读出.

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

推荐答案

将破折号更改为下划线即可解决问题,即将其从"fr-FR"更改为"fr_FR".

Changing the dash to an underscore fixed it, i.e., from 'fr-FR' to 'fr_FR'.

文档 https://w3c.github.io/speech-api/#tts-section 指出代码应为"BCP 47",并指定破折号.

The documentation https://w3c.github.io/speech-api/#tts-section states that the code should be "BCP 47", which specifies a dash.

但是,本文指出在某些移动实现中使用了下划线: https://manu.ninja/using-网络语音API的语音合成界面

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

因此下划线将其修复.下划线也适用于台式机Chrome.

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.

这篇关于Chrome Android文本到语音不会更改语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆