小程序使用微信同声传译进行语言播报(数字播报问题)

小程序使用微信同声传译进行语言播报(数字播报问题)

需求是产品提的 代码是我写的(没办法,卑微打工人)

废话不多说直接开始吧

  1. 首先在微信微信公众平台插件管理引入插件(微信同声传译插件地址
    在这里插入图片描述
    2.在详情中找到你的appid 复制下来 打开小程序 在app.json中添加如下代码 (记得保存)
    “plugins”: {
    “WechatSI”: {
    “version”: “0.3.5”,
    “provider”: “wx069ba97219f66d99”
    }
    }

  2. 最重要的一步来了

<view class="titleplay" bindtap='openYun' wx:if="{{voicePlay}}">
        <text class="playcen">语音读题</text>
        <image class="titleimg" src="../../image/question/audioPlay.png"></image>
      </view>
      <view class="titleplay" bindtap='end' wx:else>
        <text class="playcening">播放中</text>
        <image class="titleimg" src="https://xxxx.com/fileCenter/api/file/getFileAuth?bucketName=jiakaozhijia&fileName=cm/SubjectOne/31BE404405AEA55E22E6B370178B4C7A"></image>
 </view>
// 文字转语音
    openYun() {
      let that = this;
      that.setData({
        voicePlay: false
      })
      plugin.textToSpeech({
        lang: "zh_CN",
        tts: true,
        content: that.data.titltName,//这里是你获取到的语言地址
        success: function (res) {
          that.setData({
            src: res.filename
          })
          that.yuyinPlay();
        },
      })
    },

    //语音读题播放语音
    yuyinPlay: function (e) {
      let that = this
      if (that.data.src == '') {
        return;
      }
      that.properties.automaticEnd = false
      that.innerAudioContext.src = that.data.src //设置音频地址
      that.innerAudioContext.play(); //播放音频
      that.innerAudioContext.onEnded(() => {
        that.setData({
          voicePlay: true
        })
        this.properties.automaticEnd = true
        if (that.properties.automatic && that.properties.isVip == '1') {
          if (that.properties.questionItem.questionRecode && that.properties.questionItem.questionRecode.is_right == '0' || that.properties.isDoRight === 0) {
            that.properties.isDoRight = 1
            that.audioPlay()
          }
        }
      })
    },

    // 语音读题结束语音
    end: function (e) {
      this.setData({
        voicePlay: true
      })
      this.innerAudioContext.pause(); //暂停音频
    },

哦,忘记了一步 记得引入插件:微信同声传译

const plugin = requirePlugin('WechatSI');
const vipQuestionAudio = wx.createInnerAudioContext({});

还有一点忘记说明了 识别语音播报有数字的时候 记得转成为字符串 不然会当成金额来播报

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值