【发布时间】:2021-08-16 16:20:34
【问题描述】:
我正在编写一个前端用户界面,它使用 Web Speech API 的 SpeechSynthesis Interface。
我通常对此感到满意。我不关心这些词是否以美国、英国、澳大利亚、新西兰、南非、印度、新加坡英语、菲律宾等口音发音,但我不确定当 SpeechSynthesis 界面 乱字。
到目前为止,我想出的唯一解决方案是替换:
- 单个字符串(语音合成器说出与用户阅读相同的字符串)
与:
- 一对字符串(语音合成器说出与用户阅读的字符串不同的字符串 - 指定的对应字符串)
示例:
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>
只需成对创建单词并告诉 语音合成器 说出 “proto kols” 和 “weh bapp” em>"protocols" 和 "web app" 显示给用户,我可以使用其他方法来覆盖 mangling 吗?
【问题讨论】:
标签: javascript text-to-speech webspeech-api speechsynthesizer