Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google chrome speechSynthesis.speak不在chrome中工作_Google Chrome_Webspeech Api - Fatal编程技术网

Google chrome speechSynthesis.speak不在chrome中工作

Google chrome speechSynthesis.speak不在chrome中工作,google-chrome,webspeech-api,Google Chrome,Webspeech Api,我在Windows10上使用的是chrome版本55.0.2883.87M(64位) 下面的简单html文件再现了这个问题,并从我更复杂的应用程序中提取。它应该说出页面加载上的3个单词。它适用于MS Edge和Firefox,但不适用于chrome。几周前,这段代码在Chrome上对我有效,没问题 <html> <head> <script lang="javascript"> window.speechSynthesis.speak(

我在Windows10上使用的是chrome版本55.0.2883.87M(64位)

下面的简单html文件再现了这个问题,并从我更复杂的应用程序中提取。它应该说出页面加载上的3个单词。它适用于MS Edge和Firefox,但不适用于chrome。几周前,这段代码在Chrome上对我有效,没问题

<html>
<head>
    <script lang="javascript">
        window.speechSynthesis.speak(new SpeechSynthesisUtterance("cat"));
        window.speechSynthesis.speak(new SpeechSynthesisUtterance("dog"));
        window.speechSynthesis.speak(new SpeechSynthesisUtterance("bark"));
    </script>
</head>
<body></body>
</html>

window.speechSynthesis.speak(新speechSynthesis(“cat”);
window.speechSynthesis.speak(新speechSynthesis(“狗”);
window.speechSynthesis.speak(新speechSynthesis(“树皮”);
resultsDisplay=document.getElementById(“rd”);
startButton=document.getElementById(“startbtn”);
stopButton=document.getElementById(“stopbtn”);
识别=新建(window.SpeechRecognition | | window.webkitSpeechRecognition | | | window.mozSpeechRecognition | | window.msSpeechRecognition)();
recognition.lang=“en-US”;
recognition.interimResults=false;
识别率=5;
recognition.onresult=函数(事件){
resultsDisplay.innerHTML=“你说:”+event.results[0][0]。记录;
};
函数start(){
识别。开始();
startButton.style.display=“无”;
stopButton.style.display=“block”;
}
函数停止(){
识别。停止();
startButton.style.display=“block”;
stopButton.style.display=“无”;
}
.resultsDisplay{宽度:100%;高度:90%;}
#stopbtn{显示:无;}


开始 停止
我可能永远也不知道,因为这个问题是间歇性的,但在我开始在说话之前取消之后,它似乎就消失了

utter = new window.SpeechSynthesisUtterance("cat");

window.speechSynthesis.cancel();
window.speechSynthesis.speak(utter);
我不认为取消必然会出现在话语对象的创造和使用之间。只是每次演讲之前都会有。我可能有一个不同的问题,因为我只是创造了一个话语对象,而不是一堆。我只在Chrome78上看到过。使用Windows7,64位。从未在Firefox或Edge上看到过问题

2周后编辑。经过几十次尝试后没有复发。看来。取消()解决了我的问题。我的症状是:在Chrome中调用speechSynthesis.speak()有时无法启动演讲。代码,
speechSynthesis中没有立即出现问题的迹象。speechSynthesis.speak
为真,
。pending
为假。不会有来自话语对象的事件。正常情况下,当语音正常工作时,我会在调用.speak()大约0.1秒后收到一个
'start'
事件。

speechSynthesis.speak()自2018年起,如果没有用户在谷歌Chrome浏览器中激活,将不再被允许使用它违反了Google Chrome的自动播放策略。因此Google Chrome已经成功撤销了它的自动播放功能,但是你可以通过添加一个按钮来进行自定义调用来利用它

您可以访问此处查看chrome本身提供的状态。下面的图片清楚地显示,未经用户许可,speechSynthesis.speak()调用是被禁止的