微信小程序语音转文字功能

 使用插件 同声传译

在微信公众平台添加第三方插件 同声传译

 

 

 app.json写入

  "plugins": {
    "WechatSI": {
      "version": "0.3.0",
      "provider": "wx069ba97219f66d99"
    }
  },

使用的地方引入

var app = getApp()
//引入插件:微信同声传译
var plugin = requirePlugin("WechatSI")
//获取全局唯一的语音识别管理器recordRecoManager
let manager = plugin.getRecordRecognitionManager()
Component({

  properties: {
  },

  data: {
    spekerIcon: 0,
    timer: null,
  },
  attached: function () {
  //优先执行
    this.initRecorder()
    //开始录音
  manager.start({
      duration: 60000,
      lang: "zh_CN"
    });

  },
  methods: {
  //录音转文字
    initRecorder: function () {
      var _this = this
      manager.onStop = function (res) {
        _this.setData({
          text_cont: res.result
        })
      };
      manager.onStart = function (res) {
        console.log(res);
      };
      manager.onError = function (res) {
        console.log(res);
      };
    },
  //结束执行的方法
    okSpeak() {
      manager.stop()
    }

  },
})

 

posted @ 2022-04-14 16:30  web格调  阅读(1106)  评论(0编辑  收藏  举报