- 安装speak-tts插件
npm install speak-tts
- 在页面中引入
import Speech from 'speak-tts'
- 初始化对象
data() {
return {
speech: null,
}
},
mounted() {
this.speechInit();
},
methods: {
speechInit() {
this.speech = new Speech();
this.speech.setLanguage("zh-CN");
this.speech.init().then(() => {});
},
}
- 调用
methods: {
// 执行播报
handleSpeech() {
this.speech.speak({ text: "您有新订单,请注意查看" }).then(() => {
console.log("播报成功");
});
},
}