场景

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

安装
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();  //从暂停处继续播放

转载文章
官方文档

GitHub 加速计划 / vu / vue
207.52 K
33.66 K
下载
vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
最近提交(Master分支:1 个月前 )
73486cb5 * chore: fix link broken Signed-off-by: snoppy <michaleli@foxmail.com> * Update packages/template-compiler/README.md [skip ci] --------- Signed-off-by: snoppy <michaleli@foxmail.com> Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com> 3 个月前
e428d891 Updated Browser Compatibility reference. The previous currently returns HTTP 404. 3 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐