我正在编写一个使用 Web Speech API 的 SpeechSynthesis Interface 的前端用户界面。
我总体上对此很满意。我不关心这些词是否以美国、英国、澳大利亚、新西兰、南非、印度、新加坡式英语、菲律宾等口音发音,但我不确定在 SpeechSynthesis Interface 破坏单词。
到目前为止我想出的唯一解决方案是替换:
- 单个字符串(语音合成器说出与用户阅读的字符串相同的字符串)
与:
- 一对字符串(语音合成器说出与用户读取的字符串不同的字符串 - 指定的对应字符串)
示例:
const buttons = document.querySelectorAll('button');
const speakWord = (e) => {
const word = e.target.dataset.word;
let utterance = new SpeechSynthesisUtterance(word);
speechSynthesis.speak(utterance);
}
buttons.forEach((button) => {
button.addEventListener('click', speakWord, false);
});
h2 {
display: inline-block;
margin-right: 12px;
font-size: 14px;
}
button {
cursor: pointer;
}
<h2>Say:</h2>
<button type="button" data-word="manifests">"manifests"</button>
<button type="button" data-word="modules">"modules"</button>
<button type="button" data-word="configuration">"configuration"</button>
<br>
<h2>Now say:</h2>
<button type="button" data-word="protocols">"protocols"</button>
<button type="button" data-word="web app">"web app"</button>
<br>
<h2>Finally say:</h2><button type="button" data-word="proto kols">"proto kols"</button>
<button type="button" data-word="weh bapp">"weh bapp"</button>
当词 < em>“协议(protocol)” 和 “网络应用程序” 已显示给用户,是否有任何其他方法可以用来覆盖重整?
最佳答案
我遇到了同样的问题。我尝试将 utterance.rate 参数设置为较低的值。对于英语,当 rate 设置为 0.5 时,可理解性更好。如果发音速度不太慢,可以将参数设置为较低的值。
const u = new SpeechSynthesisUtterance('web app');
speechSynthesis.speak(u);
u.rate = 0.5;
speechSynthesis.speak(u);
关于javascript - 使用 Web Speech API 的 SpeechSynthesis 接口(interface)改善发音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68806186/