微信小程序开发语音识别文字教程  

现在后台 添加插件 

微信同声传译

然后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://developers.weixin.qq.com/miniprogram/dev/extended/service/translator.html

 

版权声明:本文为newmiracle原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/newmiracle/p/11881052.html