SpeechSynthesis停止以chrome扩展程序讲话,但他可以讲话,但时间不长
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);
};
答案 0 :(得分:0)
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);
当句子全部读出后,停止计时器。
utterance.onend = function (event) {
clearTimeout(this.myTimeout);
}
};