HTML5 语音无法在 mac 10.0.1 上的 Safari 上运行,
我得到了错误,
TypeError: Argument 1 ('utterance') to SpeechSynthesis.speak must be an instance of SpeechSynthesisUtterance
它适用于 Chrome 和 Firefox,而且我很确定它曾经适用于 Safari...
var u = new SpeechSynthesisUtterance();
u.text = "hello world";
u.lang = "en";
window.speechSynthesis.speak(u);
最佳答案
好吧,终于明白了。
我有一些兼容代码来支持没有 html5 语音的浏览器,
if (SpeechSynthesisUtterance == undefined) {
function SpeechSynthesisUtterance(text) {
this.text = text;
}
}
这适用于 Chrome 和 Firefox,但在 Safari 上似乎在解析脚本时会评估任何脚本中的任何函数,因此即使 SpeechSynthesisUtterance 已经存在,也会声明该函数。
我想我需要以不同的方式来做...
关于javascript - HTML 语音不适用于 Safari mac "TypeError",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40773042/