SpeechSynthesis stops working after first utterance in FireFox, but works in Chrome

妖精的绣舞 提交于 2020-01-06 05:34:25

问题


The problem is very simple, see JSfiddle.

SpeechSynthesis works fine in Chrome, but mysteriously stops after the first utterance in FireFox. (Works for me in Safari as well.) Any ideas welcome, as I don't have much to go by.

The code:

var u = new SpeechSynthesisUtterance();
var synth = window.speechSynthesis;
u.text = "hello";
synth.speak(u);
synth.speak(u);
synth.speak(u);

回答1:


This is actually a known bug in Firefox.

The specs drafts are still not very clear about the re-usability of an utterance, but you can see this issue on w3c's github, where they agreed on the fact it should be.

For the time being, one workaround is to create a new utterance every time...

var synth = window.speechSynthesis;

synth.speak(new SpeechSynthesisUtterance('hello'));
synth.speak(new SpeechSynthesisUtterance('hello'));
synth.speak(new SpeechSynthesisUtterance('hello'));


来源:https://stackoverflow.com/questions/47274695/speechsynthesis-stops-working-after-first-utterance-in-firefox-but-works-in-chr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!