问题
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