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);
}
没办法的,这个标准已经再逐渐推广开了,禁止网页的音频自动播放,包含音频的视频也不允许自动播放了,诸如腾讯视频或者某某直播等都采用了将视频静音的方式才实现首页视频自动播放。
目前找到了原因,是谷歌版本太新,如果是太新的话就需要用户去点击一下才行,但是这个要求不能去点击