浏览器启动后首次加载时,语音合成不会在 google chrome 中暂停

Speech Synthesis won't pause in google chrome at first load after browser launch

完全关闭浏览器,重新打开浏览器并使用 speechSynthesis.speak(string);

开始文字转语音

speechSynthesis.pause();在您刷新页面之前不会工作。

同样可见, https://developer.microsoft.com/en-us/microsoft-edge/testdrive/demos/speechsynthesis/

这发生在 Mac 和 Windows, chrome 70.

有人知道解决方法吗?

Does anybody know a workaround?

如果您先说空文本,它会在第一次加载时暂停。

let btnSpeak = document.getElementById("btnSpeak");
let spoken = false;
speechSynthesis.cancel();
function speak() {
    btnSpeak.disabled = true;
    let msg = new SpeechSynthesisUtterance();
    if (!spoken) {
        let mt = new SpeechSynthesisUtterance();
        mt.text = " ";
        window.speechSynthesis.speak(mt);
        spoken = true;
    }
    msg.text = "Use a long sentence to give time to hit pause";
    msg.voice = voices[0];
    msg.lang = voices[0].lang;
    msg.onend = function(event) {
        btnSpeak.disabled = false;
    };
    window.speechSynthesis.speak(msg);
}