Search code examples
javascriptgoogle-chromefirefoxtext-to-speechspeech-synthesis

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


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);

Solution

  • 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'));