Vue使用speak-tts插件实现后台管理系统语音播报功能

场景

点击界面语音播报按钮,电脑进行语音播报

安装
npm install speak-tts
引用
import Speech from 'speak-tts'
使用
<template>
   <i class="el-icon-microphone" @click="play()" ></i>
   <i class="el-icon-video-pause" @click="paused()"></i> 
   <i class="el-icon-video-play" @click="goahead()" ></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:"收款40万元",
        listeners: {
            //开始播放
            onstart: () => { console.log("Start utterance")},
            //判断播放是否完毕
            onend: () => { console.log("End utterance")},
            //恢复播放
            onresume: () => { console.log("Resume utterance") },
        },
        }).then(()=>{console.log("读取成功")})
    },
    //暂停
    paused() {
      this.speech.pause();
    },
    //从暂停处继续播放
    goahead() {
      this.speech.resume();
    },
},
//离开页面取消语音
 destroyed() {
   this.speech.cancel();
 },
</script>

方法
this.speech.pause();   //暂停
this.speech.cancel();  // 移除所有语音谈话队列中的谈话
this.speech.resume();  //从暂停处继续播放

转载文章
官方文档

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值