1、安裝speak-tts包
npm install speak-tts
2、在頁面中引入
import Speech from 'speak-tts'
3、初始化以及實現
點擊查看代碼
data () {
return {
speech:null
}
},
mounted(){
this.speechInit();
},
methods:{
speechInit(){
this.speech = new Speech();
this.speech.setLanguage('zh-CN');
this.speech.init().then(()=>{
console.log('語音播報初始化完成...')
})
},
//語音播報
speak(){
this.speech.speak({text:"語音播報測試"}).then(()=>{
console.log("播報完成...")
})
}
}
參考
1.speak-tts: https://github.com/tom-s/speak-tts
3.vue 語音播報(文字轉語音)https://www.icode9.com/content-4-864733.html