uniapp 微信语音播放功能(整理)

简介: uniapp 微信语音播放功能(整理)

1、在你的小程序中,加上可调用插件,设置-第三方设置-添加插件:微信同声传译。


2、把源码视图 中的appid替换成你自己的appid(点击详情-可查看appid)

data(){
  return{
    playN: 0,
  }
},
onShow(){
  this.play();  //语音
},
methods:(){
  // 播放语音
  play() {
    if(this.$.get_data("logInData") != true){ //判断了下是否登录状态
      return false
    }
    this.$.ajax("GET", "/api/mech/getVoiceMessage", {}, (res) => {
      if (res.code == 1000) {
        var _this = this;
        // var data = [80];
        var data = res.data;
        var numText = '';
        // var num = 1;
        if (data != undefined && _this.playN < data.length) {
          numText = data[_this.playN];
          // let text = "微信收款 800 元" // 真实环境替换为以后端返回文本(数字金额前后加一个空格,播报时就会顿一下)
          // let text = "微信收款 " + numText + "元";
          let text = numText;
          //直接调用全局封装好的方法
          _this.WechatSI.textToSpeech({
            lang: "zh_CN",
            tts: true,
            content: text,
            success: function(res) {
              console.log("succ tts", res.filename) //MP3录音文件
              _this.ScanAudio(res.filename);
              _this.playN++;
              console.log("playN", _this.playN);
              setTimeout(function() {
                _this.play();
              }, 6000);
            },
            fail: function(res) {
              console.log("fail tts", res)
            }
          })
        } else {
          setTimeout(function() {
            _this.playN = 0;
            _this.play();
          }, 6000);
        }
      }
    });
  },
},
相关文章
|
10天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的校园水电费管理微信小程序的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的校园水电费管理微信小程序的详细设计和实现
33 0
|
22天前
|
小程序
微信小程序如何实现进入小程序自动连WiFi功能
微信小程序如何实现进入小程序自动连WiFi功能
|
10天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的优购电商小程序的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的优购电商小程序的详细设计和实现
32 0
|
10天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的微信课堂助手小程序的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的微信课堂助手小程序的详细设计和实现
45 3
|
10天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的电子商城购物平台的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的电子商城购物平台的详细设计和实现
40 3
|
10天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的英语学习交流平台的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的英语学习交流平台的详细设计和实现
26 2
|
10天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的微信阅读网站小程序的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的微信阅读网站小程序的详细设计和实现
39 2
|
10天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的移动学习平台的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的移动学习平台的详细设计和实现
33 1
|
10天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的教师管理系统的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的教师管理系统的详细设计和实现
37 2
|
10天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的学生公寓电费信息的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的学生公寓电费信息的详细设计和实现
34 1

热门文章

最新文章