1、 安装依赖
npm install speak-tts --save
2、引入(那个页面用到在哪里引入)
import Speech from 'speak-tts'
3、使用
<template>
<i class="el-icon-microphone" @click="play()" ></i>
</template>
<script>
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(()=>{ })
},
//播放按钮
play(){
this.speech.speak({text:"请刷身份证"}).then(()=>{}) }
//离开页面取消语音
destroyed() {
this.speech.cancel();
},
}
</script>