中化加油站项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

76 lines
1.4 KiB

/**
* 语音工具
*/
export class SpeakingTool {
private static instance: SpeakingTool;
static get Instance() {
if (SpeakingTool.instance == null) {
SpeakingTool.instance = new SpeakingTool();
}
return SpeakingTool.instance;
}
/**
* 阅读一段文字
* 会清空已有的阅读列表
* @param msg
*/
speak(msg: string) {
console.log("阅读" + msg);
if (this.isIE()) {
}
else {
this.clear();
let speakMsg = new SpeechSynthesisUtterance(msg);
speakMsg.lang = "zh-CN";
speakMsg.rate = 1;
speakMsg.pitch = 1.5;
window.speechSynthesis.speak(speakMsg);
return speakMsg;
}
}
/**
* 暂停正在进行的阅读
* @param speakMsg
*/
pause() {
window.speechSynthesis.pause();
}
/**
* 继续之前暂停的阅读
*/
resume() {
window.speechSynthesis.resume();
}
/**
* 清空进行中的阅读
*/
clear() {
window.speechSynthesis.cancel();
}
/**
* IE浏览器
*/
private isIE() {
// if ("ActiveXObject" in window) {
// console.log("IE 浏览器")
// return true;
// }
// else {
// return false;
// }
return false;
}
}