function voice() {
// var d = "未按顺序绑定零件号"
var d = "绑定成功"
// const articleTxt = this.article.content.replace(/<[^>]+>/g, ""); //获取富文本的纯文字
const articleTxt = d
let to_speak = new SpeechSynthesisUtterance(articleTxt);
let msg = new SpeechSynthesisUtterance();
to_speak.rate = 0.8;// 设置播放语速,范围:0.1 - 10之间
to_speak.pitch = 2 // 高音调(数字越大越尖锐,默认为 1,范围 0~2 )
to_speak.volume = 1 // 音量 0.5 倍(默认为1,范围 0~1)
to_speak.voiceURI = 'Ting-Ting'
to_speak.voiceURI = 'Google 普通话(中国大陆)';
to_speak.onend = (event) => { //语音合成结束时候的回调
this.isPlay = false; //关闭播放状态,
this.isResume = false; //不在继续播放
this.isPause = false; //不是暂停状态
}
window.speechSynthesis.speak(to_speak);
this.isPlay = true; //播放状态
}
//暂停
function pause() {
window.speechSynthesis.pause();
this.isPause = true; //暂停
this.isResume = false; //不是继续播放
}
//继续播放
function resume() {
window.speechSynthesis.resume(); //继续
this.isResume = true; //正在继续播放
this.isPause = false; //不是暂停状态
}
//清除所有语音播报创建的队列
function cancel() {
window.speechSynthesis.cancel();
this.isPlay = false; //关闭播放状态,
this.isResume = false; //不在继续播放
this.isPause = false; //不是暂停状态
}