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

 使用插件 同声传译

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

 

 

 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 @   web格调  阅读(1141)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· Apache Tomcat RCE漏洞复现(CVE-2025-24813)
历史上的今天:
2021-04-14 数组去重
点击右上角即可分享
微信分享提示