javascript - 使用 Web Speech API 的 SpeechSynthesis 接口(interface)改善发音

标签 javascript text-to-speech webspeech-api speechsynthesizer

我正在编写一个使用 Web Speech APISpeechSynthesis 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/

相关文章:

javascript - 如何在 Ajax 编程中保持 ID 的唯一性?

Javascript 将日期更改为 (dd/mm/yyyy) 格式

android - 如何创建自定义文本到语音引擎

javascript - 使用多个变量打开不同的链接

javascript - HTML5 语音合成 API - 只能使用 "native"语音

javascript - Fullcalendar 弹出窗口为空(使用 eventLimit)

Javascript setInterval 未运行

azure - 如何测量在 Azure 认知服务语音合成 (TTS) 中使用的字符?

python - 可听错误 - Python 日志记录模块的自定义非阻塞文本到语音处理程序

javascript - 如何在 chromium 浏览器中创建文本或将文本转换为音频?