npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

wechat-si-recognition

v1.0.0

Published

微信小程序同声传译语音识别 Hook,含录音权限处理,适用于 uni-app Vue3

Downloads

9

Readme

wechat-si-recognition

微信小程序「同声传译」语音识别 Hook,内置录音权限申请与引导,适用于 uni-app Vue3 微信小程序。使用方只需关心业务逻辑与自定义 UI,长按调 start()、松手调 stop(),在 onStop 中取 payload.result 即可。

特性

  • 仅微信小程序有效,依赖微信官方 同声传译插件
  • 内置录音权限:start() 内自动执行「查权 → 申请 → 失败时弹窗引导去设置」
  • 非小程序端安全降级:isAvailable === falsestart() 返回 Promise.resolve(false)

安装

npm install wechat-si-recognition
# 或 pnpm add wechat-si-recognition
# 或 yarn add wechat-si-recognition

配置小程序插件(必须)

在项目 src/manifest.jsonmp-weixin 中声明同声传译插件,否则插件不可用:

{
  "mp-weixin": {
    "plugins": {
      "WechatSI": {
        "version": "0.3.5",
        "provider": "wx069ba97219f66d99"
      }
    }
  }
}

使用示例

import { useWechatSIRecognition } from 'wechat-si-recognition';

const wechatSI = useWechatSIRecognition({
  lang: 'zh_CN',
  onStop: (payload) => {
    const text = (payload.result || '').trim();
    if (text) {
      // 业务:如发送文本消息
      sendMessage({ type: 'text', content: text });
    }
  },
  onError: (payload) => {
    console.error(payload.msg);
    // 可选:uni.$u.toast(payload.msg);
  }
});

// 在自定义「按住说话」按钮上:
// - touchstart:设 300ms 定时器,到点后调用 wechatSI.start()
// - touchend / touchcancel:调用 wechatSI.stop()

// 长按 300ms 后
wechatSI.start().then((ok) => {
  if (ok) {
    // 显示录音中 UI、震动等
    showRecordingOverlay();
    uni.vibrateShort({ type: 'medium' });
  }
});

// 松手
wechatSI.stop();

API

useWechatSIRecognition(options)

| 参数 | 类型 | 默认值 | 说明 | |------|------|--------|------| | options.lang | string | 'zh_CN' | 识别语言:zh_CN | en_US | zh_HK | sichuanhua | | options.onRecognize | (result: string) => void | - | 识别中间结果(可选) | | options.onStop | (payload) => void | - | 结束回调,payload 见下表 | | options.onError | (payload) => void | - | 错误回调,payload: { retcode, msg } | | options.permissionModal | object | 见下 | 无权限时弹窗文案,可选 |

onStop(payload) 结构:

| 字段 | 类型 | 说明 | |------|------|------| | result | string | 语音转文字结果(松手后最终结果) | | tempFilePath | string | 录音临时文件路径 | | duration | number | 录音时长(ms) | | fileSize | number | 文件大小 |

permissionModal 默认:

{
  title: '需要录音权限',
  content: '请授权录音,用于语音识别',
  confirmText: '去设置',
  cancelText: '取消'
}

返回值

| 属性 | 类型 | 说明 | |------|------|------| | start | () => Promise<boolean> | 开始录音;内部先处理权限,成功启动则 resolve(true) | | stop | () => void | 停止录音 | | isAvailable | boolean | 当前环境是否可用(仅小程序且已配置插件时为 true) |

错误码

| retcode | 说明 | |---------|------| | -1 | 同声传译插件不可用或启动失败(未配置插件或非小程序端) | | -2 | 未授权录音(用户拒绝或弹窗后未授权) | | 其他 | 以微信插件返回为准,见 插件文档 |

参考

License

MIT