Android-Chrome で音声合成 API を使用しています。問題は、英語の音声が 4 つありますが、コードの指定に関係なく、ブラウザで使用されるのは常に米国英語です。フランス語などの他の言語を使用できますが、en-AU、GB、または IN などの他の英語の音声は使用できません。
このコードは、getVoices 配列からイギリス英語の音声オブジェクトをフィルター処理し、最初の音声オブジェクトを使用して「tomato」という単語を発声します。問題は、単語が常に「to-mar-to」ではなく「to-may-lo」と発音されることです。これは、私のテキストが本来の韻を踏まないことを意味します。
使用された音声オブジェクトが表示され、(私が試した電話では) 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 が使用する音声をどのように制御しますか?