嗯, 使用讯飞的这个转语音是有bug的。
安卓8以上会出现合成错误的情况。所以我在网上找了一些简单的解决方法
话不多说上代码
test() {
var main
= plus
.android
.runtimeMainActivity()
var SpeechUtility
= plus
.android
.importClass('com.iflytek.cloud.SpeechUtility')
SpeechUtility
.createUtility(main
, "appid=这里放你自己的appid,")
var SynthesizerPlayer
= plus
.android
.importClass('com.iflytek.cloud.SpeechSynthesizer')
var play
= SynthesizerPlayer
.createSynthesizer(main
, null)
let msg
= {
content
: '星夫柒到账12元'
}
uni
.getSystemInfo({
success
: function(res
) {
console
.log(res
.system
);
if (parseInt(res
.system
) >= 8) {
let ttt
= this.changeEnCode(msg
.content
)
play
.startSpeaking(ttt
, null)
} else {
play
.startSpeaking(msg
.content
, null)
console
.log("receive: ", msg
)
}
}
});
},
处理那个文本的方法
changeEnCode(str
) {
let res
= []
for (let i
= 0; i
< str
.length
; i
++) {
res
[i
] = ("00" + str
.charCodeAt(i
).toString(16)).slice(-2) + ("00" + str
.charCodeAt(i
).toString(16)).slice(-4, -2)
}
let strCode
= "\\u" + res
.join("\\u")
strCode
= strCode
.replace(/\\/g, "%")
return unescape(strCode
)
},
如果需要监听订单实时提醒,最好放到app.vue的onLaunch里
转载请注明原文地址: https://lol.8miu.com/read-759.html