小程序使用微信同声传译进行语言播报(数字播报问题)
需求是产品提的 代码是我写的(没办法,卑微打工人)
废话不多说直接开始吧
-
首先在微信微信公众平台插件管理引入插件(微信同声传译插件地址)
2.在详情中找到你的appid 复制下来 打开小程序 在app.json中添加如下代码 (记得保存)
“plugins”: {
“WechatSI”: {
“version”: “0.3.5”,
“provider”: “wx069ba97219f66d99”
}
} -
最重要的一步来了
<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 = thisif (that.data.src == '') {return;}that.properties.automaticEnd = falsethat.innerAudioContext.src = that.data.src //设置音频地址that.innerAudioContext.play(); //播放音频that.innerAudioContext.onEnded(() => {that.setData({voicePlay: true})this.properties.automaticEnd = trueif (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 = 1that.audioPlay()}}})},// 语音读题结束语音end: function (e) {this.setData({voicePlay: true})this.innerAudioContext.pause(); //暂停音频},
哦,忘记了一步 记得引入插件:微信同声传译
const plugin = requirePlugin('WechatSI');
const vipQuestionAudio = wx.createInnerAudioContext({});
还有一点忘记说明了 识别语音播报有数字的时候 记得转成为字符串 不然会当成金额来播报