代码语言:javascript
复制var synth = window.speechSynthesis;
var voices = new window.SpeechSynthesisUtterance();
voices.lang = "zh-CN";
需要播放的时候直接设置 voices的text属性的内容,然后调用 speak 函数传入voices对象即可,如下:
代码语言:javascript
复制voices.text="今儿,天儿不错!"
synth.speak(voices)
点击播放