使用textToSpeech文字转语音,之后用getBackgroundAudioManager进行播放,就一直重复播放。
前几周还正常呢,
const plugin = requirePlugin('WechatSI')
const innerAudioContext = wx.getBackgroundAudioManager();
Page({
onLoad(options) {
// 监听语音结束错误
innerAudioContext.onError((error) => {
console.log('error');
console.log(error);
})
},
clickHandle() {
var that = this;
let playContent = "信息播报功能已关闭。"
plugin.textToSpeech({
lang: "zh_CN",
tts: true,
content: playContent,
success: function (res) {
that.yuyinPlay(res.filename + '&key=' + Math.random(), playContent);
},
fail: function (res) {
wx.showToast({
title: '语音合成错误!',
icon: 'none',
duration: 2000
})
}
})
},
//播放语音
yuyinPlay: function (src, playContent) {
if (src == '') {
return;
}
innerAudioContext.title = playContent
innerAudioContext.src = src //设置音频地址
innerAudioContext.play(); //播放音频
},
})