微信小程序开发语音识别文字教程
现在后台 添加插件
微信同声传译
然后app.json
加入插件
"plugins": { "WechatSI": { "version": "0.0.7", "provider": "xxxxxxxxx" } }
前端页面
<image class="psearchsp_yuyinbtn" bindtouchstart='luyin' bindtouchend='quxiaoluyin' style="display:{{isshow}}" src="yuyinbtn.png"></image>
js
var plugin = requirePlugin("WechatSI") var manager = plugin.getRecordRecognitionManager()
luyin() { manager.start({ lang: 'zh_CN', }) console.log('开始录音'); }, quxiaoluyin() { manager.stop() console.log('取消录音'); },
录音完成后回调
onload函数里面写
manager.onRecognize = function (res) { console.log("current result", res.result) } manager.onStop = function (res) {
// mp3临时路径 console.log("record file path", res.tempFilePath)
//mp3语音转化成文字结果 console.log("result", res.result) } manager.onStart = function (res) { console.log("成功开始录音识别", res) } manager.onError = function (res) { console.error("error msg", res.msg) }
详细文档 看云图网
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/6238.html