gpt4 book ai didi

javascript - Android-Chrome 中的 SpeechSynthesis : cannot change English voice from US English

转载 作者:行者123 更新时间:2023-12-01 16:29:45 27 4
gpt4 key购买 nike

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

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

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

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,output
在 Android Chrome 中运行它,然后点击“tomato”这个词。

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

最佳答案

在 Android 版本 5.0.2 上解决此问题的唯一方法是更改​​ Android 设置中的默认语音,然后重新启动设备。这将让您使用您想要的语音,但其他英语语音将不可用。 Here是一些更详细的信息:

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.

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.

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

关于javascript - Android-Chrome 中的 SpeechSynthesis : cannot change English voice from US English,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52975068/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com