Chrome Speech Synthesis with longer texts

前端 未结 12 1199
难免孤独
难免孤独 2020-11-30 19:48

I am getting a problem when trying to use Speech Synthesis API in Chrome 33. It works perfectly with a shorter text, but if I try longer text, it just stops in the middle. A

12条回答
  •  無奈伤痛
    2020-11-30 20:16

    I have solved the probleme while having a timer function which call the pause() and resume() function and callset the timer again. On the onend event I clear the timer.

        var myTimeout;
        function myTimer() {
            window.speechSynthesis.pause();
            window.speechSynthesis.resume();
            myTimeout = setTimeout(myTimer, 10000);
        }
        ...
            window.speechSynthesis.cancel();
            myTimeout = setTimeout(myTimer, 10000);
            var toSpeak = "some text";
            var utt = new SpeechSynthesisUtterance(toSpeak);
            ...
            utt.onend =  function() { clearTimeout(myTimeout); }
            window.speechSynthesis.speak(utt);
        ...
    

    This seem to work well.

提交回复
热议问题