<div v-on:click="read(word.word)" ></div>
export default {
data() {
return {
synth:'',
msg:'',
word:'你长得真好看!'
};
},
methods: {
read() {
this.synth = window.speechSynthesis;
this.msg = new SpeechSynthesisUtterance();
this.msg.text = this.word;
this.msg.lang = "zh-CN";
console.log(this.msg);
this.throttle(this.handleSpeak(), 1000);
},
handleSpeak() {
this.synth.speak(this.msg);
} ,
throttle(fn, delay) {
let last = 0;
return function() {
const now = new Date();
if (now - last > delay) {
fn.apply(this, arguments);
last = now;
}
};
}
},
mounted() {
this.read();
}
}