Android-Chrome 中的 SpeechSynthesis:无法从美国英语更改英语语音 [英] SpeechSynthesis in Android-Chrome: cannot change English voice from US English

查看:23
本文介绍了Android-Chrome 中的 SpeechSynthesis:无法从美国英语更改英语语音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Android-Chrome 上使用语音合成 API.问题是,尽管有 4 种英语语音可用,但浏览器始终使用美国英语,无论代码指定什么.我可以使用其他语言,例如法语,而不是其他英语语音,例如 en-AU、GB 或 IN.

I'm using the speech synthesis API on Android-Chrome. The issue is that although there are 4 English voices available, it is always US English that is used by the browser, no matter what the code specifies. I can use other languages e.g. French, just not other English voices e.g en-AU, GB, or IN.

此代码从 getVoices 数组中过滤出英式英语语音对象,并使用第一个说出单词tomato".问题是这个词总是发音为to-may-lo"而不是to-mar-to",这意味着我的文字没有按应有的押韵.

This code filters British English voice objects from the getVoices array and uses the first to utter the word 'tomato'. The problem is that the word is always pronounced "to-may-lo" not "to-mar-to" which means my text doesn't rhyme as it should.

显示使用的语音对象并且(在我尝试过的手机上)是 GB 对象.

The voice object that was used is displayed and (on the phones I've tried) is an GB one.

HTML...

<!DOCTYPE html>
<html lang="en-GB">
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Let's not call the whole thing off</title>
        <script src="tomato.js" defer></script>
    </head>
    <body>
        <div id="tomato" lang="en-GB">Tomato</div>
        <div id="platform"></div>
    </body>
</html>

还有剧本...

var platform = document.getElementById("platform");
var tomato = document.getElementById("tomato");

var voices = [];
var voicesGB = [];
voices = speechSynthesis.getVoices();
speechSynthesis.onvoiceschanged = function() {
    voices = speechSynthesis.getVoices();
    voicesGB = voices.filter(voice => /en(-|_)GB/.test(voice.lang));
};

function speak(word) {
    var msg = new SpeechSynthesisUtterance();
    msg.default = false;
    msg.text = word;
    msg.voice = voicesGB[0];
    msg.lang = voicesGB[0].lang;
    window.speechSynthesis.speak(msg);
    for (var p in msg.voice) {
        platform.innerHTML += p + ': ' + msg.voice[p] + '<br>\n';
    }
}

tomato.addEventListener("click",() => {speak('tomato');});

还有一个 jsbin:https://jsbin.com/xefukemuga/edit?html,js,输出在 Android Chrome 中运行此程序并点按番茄"一词.

And a jsbin: https://jsbin.com/xefukemuga/edit?html,js,output Run this in Android Chrome and tap the word 'tomato'.

我到处搜索并尝试了各种修复.您如何控制 Android-Chrome 使用的语音?

I have searched all over and tried various fixes. How do you control what voice Android-Chrome uses?

推荐答案

在 Android 5.0.2 版上解决此问题的唯一方法是更改​​ Android 设置中的默认语音,然后重新启动设备.这将使您可以使用您想要的语音,但其他英语语音将不可用.这里是更多细节:

The only way to work around this issue on Android version 5.0.2 is to change the default voice in the Android settings and then restart the device. That will let you use the voice you want, but the other English ones will then be unavailable. Here is some more detail:

SpeechSynthesis.getVoices() 将返回几个英语选项(美国、澳大利亚、尼日利亚、印度和英国)但一次只有一个可用.你可以选择哪一个去设置应用程序,然后控制->语言和输入->文本到语音选项.选择 Google Text-to-speech Engine 旁边的齿轮图标,然后在语言下,您可以更新要使用的确切区域设置.如果您选择安装语音数据",您甚至可以从样本中进行选择某些地区的不同声音.您需要重新启动设备更改此设置后才能生效.

SpeechSynthesis.getVoices() will return several options for English (United States, Australia, Nigeria, India, and United Kingdom) but only one is available at a time. You can pick which one by going to the Settings app, then Controls->Language and input->Text-to-speech options. Select the gear icon next to Google Text-to-speech Engine, then under Language you can update the exact locale you want to use. If you select "Install voice data" you can even select from a sample of different voices for some locales. You need to restart the device after changing this setting for it to take effect.

在 Android 设备上播放时使用的声音SpeechSynthesisUtterance 将取决于您在安卓设置.您可以选择要播放的语言javascript(详见下文)但您无法控制使用的语言环境或准确的语音.

The voice used on an Android device when you play a SpeechSynthesisUtterance will depend on what you have selected in the Android settings. You can choose which language you want to play from javascript (see below for details) but you have no control over the locale or exact voice used.

这个问题出现在Chrome和Firefox上,所以很可能是一个问题与Android平台的speechSynthesis API的实现.浏览器更新不太可能解决这个问题,但有所不同Android 版本可能.(我的测试设备是 Android 5.0.2,所以如果这会在以后的更新中修复,请告诉我).

This problem occurs on Chrome and Firefox, so it is likely a problem with the Android platform's implementation of the speechSynthesis API. It's unlikely that a browser update will fix this, but different versions of Android might. (My test device is on Android 5.0.2, so if this is fixed in a future update, please let me know).

这篇关于Android-Chrome 中的 SpeechSynthesis:无法从美国英语更改英语语音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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