语音合成后,用 getBackgroundAudioManager 进行播放,会出现重复播放最后几个文字,然后弹出一个 toast 的错误信息。 onError 给出的错误码:errorCode: 0。
``` js
const app = getApp()
let plugin = requirePlugin('WechatSI');
Page({
data: {
audioUrl: '',
backgroundAudioContext: null,
innerAudioContext: null
},
onLoad() {
this.backgroundAudioContext = wx.getBackgroundAudioManager();
this.backgroundAudioContext.title = '背景播放';
this.innerAudioContext = wx.createInnerAudioContext();
plugin.textToSpeech({
lang: 'zh_CN',
tts: true,
content: '语音合成重复播放问题',
success: res => {
if (res.retcode == 0) {
this.audioUrl = res.filename;
} else {
}
},
fail: res => {
}
});
},
playBackgroundAudio() {
this.backgroundAudioContext.src = this.audioUrl;
this.backgroundAudioContext.play();
},
playInnerAudio() {
this.innerAudioContext.src = this.audioUrl;
this.innerAudioContext.play();
}
})
```
``` wxml
<navigation-bar title="Weixin" back="{{false}}" color="black" background="#FFF"></navigation-bar>
<scroll-view class="scroll-area" type="list" scroll-y>
<view class="intro">欢迎使用代码片段,可在控制台查看代码片段的说明和文档</view>
<button bind:tap="playBackgroundAudio">播放 background audio</button>
<button bind:tap="playInnerAudio">播放 inner audio</button>
</scroll-view>
```
IDE 能正常播放,真机播放就会出先这个问题,IOS 、Android 都有这个问题,微信版本:8.0.50。