简体   繁体   English

启动浏览器后,语音合成功能不会在Google Chrome中首次加载时暂停

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

Kill the browser completely, reopen the browser and start text-to-speech with speechSynthesis.speak(string); 完全杀死浏览器,重新打开浏览器,然后使用speechSynthesis.speak(string);开始文本转语音。

speechSynthesis.pause(); speechSynthesis.pause(); won't work till you refresh the page. 在刷新页面之前,该功能不起作用。

Same can be seen at, https://developer.microsoft.com/en-us/microsoft-edge/testdrive/demos/speechsynthesis/ https://developer.microsoft.com/zh-cn/microsoft-edge/testdrive/demos/speechsynthesis/

This happens on both Mac and Windows, chrome 70. 在Mac和Windows(chrome 70)上都会发生这种情况。

Does anybody know a workaround? 有人知道解决方法吗?

Does anybody know a workaround? 有人知道解决方法吗?

If you speak an empty text first it pauses on first load. 如果您先说一个空文本,它将在第一次加载时暂停。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM