1.微信小程序官網(wǎng)配置
微信小程序官網(wǎng)設(shè)置-->第三方設(shè)置-->插件管理-->添加插件-->微信同聲傳譯-->添加插件
2.app.json即配置插件位置添加代碼
"plugins": {
"WechatSI": {
"version": "0.3.1",
"provider": "wx069ba97219f66d99"
}
}
3.文字轉(zhuǎn)語音播放代碼
var plugin = requirePlugin("WechatSI");
/** 文字轉(zhuǎn)語音 */
function textToSpeech() {
plugin.textToSpeech({
lang: "zh_CN",
tts: true,
content: "一個常見的需求",
success: function(res) {
speech(res.filename)
},
fail: function(res) {
console.log("fail tts", res)
}
})
}
function speech(url: string) {
const audio = Taro.createInnerAudioContext()
audio.autoplay = true
audio.src = url
audio.volume = 1
audio.onPlay(() => {
console.log('開始播放')
})
}