js SpeechSynthesisUtterance 语音播报,页面加载完毕后出声,谷歌现在出不了声音,但是如果时在页面上显示的按钮并点击,是可以出声音的
if (window.speechSynthesis)
{
// let spelSynth = window.speechSynthesis.getVoices && window.speechSynthesis.getVoices().find(item => item.localService && item.lang === "zh-CN");
window.speechSynthesis.cancel();
const synth = window.speechSynthesis;
const msg = new SpeechSynthesisUtterance();
msg.text = text;
msg.lang = "zh-CN";
msg.volume = "1";
msg.rate = 1;
msg.pitch = 1;
/** 下面注释当前浏览器支持哪些语言 */
// window.speechSynthesis.getVoices().map(item =>
// {
// console.log(item);
// });
console.log(msg);
synth.speak(msg);
}
运行结果及报错内容
是还需要设置什么东西吗,或者有相关的插件可以使用
页面刷新或者重新加载完毕后直接出声音,页面加载完毕