//语音播报
function voiceBroadcast(content){
var voice = getWindowVoice();
var msg = new SpeechSynthesisUtterance(content);
if(voice){
msg.voice = voice;
}
msg.pitch=2;
window.speechSynthesis.cancel();
window.speechSynthesis.speak(msg);
}
// 获取浏览器语音 (中文 + 本地服务)
function getWindowVoice(){
return window.speechSynthesis.getVoices().find(item => item.localService && item.lang === 'zh-CN')
}
附API:
https://developer.mozilla.org/zh-CN/docs/Web/API/SpeechSynthesis