插件申请
在小程序官方申请同声传译插件,地址:
mp.weixin.qq.com
引入插件
在app.json中加入
"plugins": {"WechatSI": {"version": "0.3.6","provider": "wx069ba97219f66d99"}},
封装公共类
如page.js
var pluginSI = requirePlugin("WechatSI");
var innerAudioSI = wx.createInnerAudioContext();
/*** 文字转语音* @author tj* @param string text */textPlayer(text) {pluginSI.textToSpeech({lang: "zh_CN",tts: true,content: text,success: function (res) {console.log("succ tts", res.filename)innerAudioSI.src = res.filename;innerAudioSI.play();},fail: function (res) {console.log("fail tts", res)}});return innerAudioSI;}
在js文件中调用
getApp().page.textPlayer(`测试的语音合成播报`);