ios - iOS13 Safari WebSpeechApi 错误:SpeechSynthesisUtterance 不会使用提供的语言环境
问题描述
iOS 13(Safari 和 WkWebView)中似乎存在一个错误,它使 iOS 使用设备语言语音,并且无法通过查看 SpeechSynthesisUtterance 中提供的“语言”来找到合适的语音。
我通过自己设置合适的声音解决了这个问题。
这在其他浏览器/平台中不需要(例如 macOS Safari、iOS < 13、Chrome 等)
this._getUtteranceRate().then((rate) => {
let utterance = new SpeechSynthesisUtterance(words);
utterance.rate = rate;
utterance.lang = 'sv-SE';
utterance.voice = this.voice; //IOS13 fix
window.speechSynthesis.speak(utterance);
});
window.speechSynthesis.onvoiceschanged = () => {
this.setVoice();
}
setVoice() {
this.voice = window.speechSynthesis.getVoices().find((voice) => {
return voice.lang === 'sv-SE';
});
}
解决方案
似乎需要在 iOS13 的 SpeechSynthesisUtterance 上明确设置语音,因为语言环境不用于查找语音。
推荐阅读
- python - 编写正则表达式以匹配 1 或 2 个字母但不是全部 3
- php - 带有 htaccess 的 Wordpress PHP 7
- django - 如何将django rest框架中的对象转换为超链接
- pandas - 如何在熊猫中对具有不同顺序的多列进行排序?
- java - RoboVM:IDEVICE_E_NO_DEVICE
- c++ - 如何在 C/C++ 中使用 libudev 从 sys/devices 获取设备路径?
- javascript - 调试 React 上下文重新渲染
- r - 在 R 中构建直方图
- javascript - 为什么更改后对连接数组的操作会影响两个数组?
- vbscript - VBScript/ASP Classic - 解析和替换字符串中的多个项目