首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SpeechSynthesis在说话时随机停止说话

SpeechSynthesis在说话时随机停止说话
EN

Stack Overflow用户
提问于 2019-04-25 02:41:57
回答 1查看 93关注 0票数 0

SpeechSynthesis在chrome扩展中停止说话,但他可以说话,但时间不会太长

代码语言:javascript
复制
chrome.runtime.onInstalled.addListener(
    function() {
        chrome.contextMenus.create(
            {
                title: "Read",
                id: "read",
                contexts:["selection"]
            }
        );
    }
);

chrome.contextMenus.onClicked.addListener(onClickHandler);

function onClickHandler(info, tab) {
    var utterance = new SpeechSynthesisUtterance(info.selectionText);
    utterance.lang = "nl-BE";
    utterance.volume = 0.5;
    utterance.rate = 0.8;
    speechSynthesis.speak(utterance);
};
EN

回答 1

Stack Overflow用户

发布于 2019-09-12 13:31:02

代码语言:javascript
复制
   chrome.runtime.onInstalled.addListener(
        function() {
            chrome.contextMenus.create(
                {
                    title: "Read",
                    id: "read",
                    contexts:["selection"]
                }
            );
        }
    );

    chrome.contextMenus.onClicked.addListener(onClickHandler);

    function onClickHandler(info, tab) {
        var utterance = new SpeechSynthesisUtterance(info.selectionText);
        utterance.lang = "nl-BE";
        utterance.volume = 0.5;
        utterance.rate = 0.8;
        function myTimer() {
        speechSynthesis.pause();
        speechSynthesis.resume();
        var myTimeout = setTimeout(myTimer, 10000);
      }
        var myTimeout = setTimeout(myTimer, 10000);
        speechSynthesis.speak(utterance);

一旦整个句子被读出,就停止计时器。

代码语言:javascript
复制
        utterance.onend = function (event) {
            clearTimeout(this.myTimeout);
        }
    };
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55836625

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档