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

@mingto/xunfei-lat

v2.2.9

Published

讯飞LAT 语音转文本

Downloads

274

Readme

@mingto/xunfei-lat

讯飞实时语音识别(ASR)服务工具库,支持流式音频处理、分割和传输,专为浏览器环境优化。

特性

  • 🎙️ 流式处理:支持实时音频流输入,边录制边识别
  • 🌍 多语言支持:支持中文、英文及多种方言
  • 📱 浏览器端支持:专为浏览器环境优化,内置麦克风管理
  • 🔧 灵活配置:支持自定义语音参数、端点检测、多候选结果
  • 🤖 智能监听:支持智能语音监听,自动检测语音并启动识别
  • 实时反馈:提供识别中、识别完成等多种状态回调
  • ✂️ 音频分段:内置音频分割和分段处理机制

安装

pnpm add @mingto/xunfei-lat

快速开始

import xunfeiLAT from '@mingto/xunfei-lat'

// 配置系统参数
xunfeiLAT.config({
  API_SECRET: 'your_api_secret',
  APPID: 'your_appid',
  API_KEY: 'your_api_key'
})

// 创建识别实例
const latInstance = xunfeiLAT.create({
  language: 'zh_cn',       // 语种:中文
  domain: 'iat',           // 应用领域:日常用语
  accent: 'mandarin',      // 方言:普通话
  vad_eos: 3600000,       // 端点检测静默时间
  dwa: 'wpgs',             // 动态修正
  ptt: 1,                  // 开启标点
  nunum: 1                 // 数字格式规则
}, {
  autoControl: true,
  initialDelay: 3000,
  subsequentDelay: 1000
})

// 订阅事件
latInstance.on('appFinish', () => {
  console.log('识别已结束')
})

latInstance.on('appResultText', (text) => {
  console.log('最终识别结果:', text)
})

latInstance.on('appResponseText', (text) => {
  console.log('实时识别中:', text)
})

// 开始识别
latInstance.start()

// 或者使用智能监听
// latInstance.watch()

// 结束识别
// latInstance.finish()

API

全局配置

xunfeiLAT.config(systemConfig)

配置系统参数,这些参数通常在讯飞开放平台申请。

xunfeiLAT.config({
  API_SECRET: 'your_api_secret',
  APPID: 'your_appid',
  API_KEY: 'your_api_key'
})

系统配置参数

| 参数 | 类型 | 必填 | 说明 | |------|------|------|------| | API_SECRET | string | ✅ 是 | 在讯飞开放平台申请的密钥信息 | | APPID | string | ✅ 是 | 在讯飞开放平台申请的 APPID 信息 | | API_KEY | string | ✅ 是 | 在讯飞开放平台申请的 API_KEY 信息 |

创建识别实例

xunfeiLAT.create(businessParams, sectionDelayParams?)

创建实时语音识别实例。

const latInstance = xunfeiLAT.create({
  language: 'zh_cn',
  domain: 'iat'
}, {
  autoControl: true,
  initialDelay: 3000,
  subsequentDelay: 1000
})

业务参数 businessParams

| 参数 | 类型 | 必填 | 默认值 | 说明 | |------|------|------|--------|------| | language | string | 否 | 'zh_cn' | 语种,支持 'zh_cn'(中文)、'en_us'(英文)等 | | domain | string | 否 | 'iat' | 应用领域,支持 'iat'(日常用语)、'medical'(医疗)等 | | accent | string | 否 | 'mandarin' | 方言,支持 'mandarin'(普通话)等 | | vad_eos | number | 否 | 3600000 | 后端点检测的静默时间(毫秒) | | dwa | string | 否 | 'wpgs' | 动态修正,仅中文普通话支持 | | pd | string | 否 | 'game' | 领域个性化参数 | | ptt | number | 否 | 1 | 是否开启标点符号添加,0-关闭,1-开启 | | rlang | string | 否 | 'zh-cn' | 字体,仅中文支持,'zh-cn'(简体)、'zh-hk'(繁体香港) | | vinfo | number | 否 | 0 | 是否返回子句端点偏移值,0-关闭,1-开启 | | nunum | number | 否 | 1 | 数字格式规则,0-关闭,1-开启(中文普通话和日语支持) | | speex_size | number | 否 | 1 | speex 音频帧长,1-标准开源 speex,2-讯飞定制 speex | | nbest | number | 否 | 1 | 发音相似时的句子多候选结果,范围 1-5 | | wbest | number | 否 | 1 | 发音相似时的词语多候选结果,范围 1-5 |

分段延迟参数 sectionDelayParams

| 参数 | 类型 | 必填 | 默认值 | 说明 | |------|------|------|--------|------| | autoControl | boolean | ❌ | true | 是否自动控制延迟输出 | | initialDelay | number | ❌ | 3500 | 第一次延迟时间(毫秒) | | subsequentDelay | number | ❌ | 3000 | 后续延迟时间(毫秒) |

实例方法

latInstance.start()

开始语音识别。

latInstance.start()

latInstance.watch()

智能语音监听,监听浏览器音频输入,当检测到音量大于 20% 且系统处于离线状态时自动启动录音和识别。

latInstance.watch()

latInstance.finish()

结束语音识别。

latInstance.finish()

latInstance.on(eventName, callback)

订阅识别事件。

latInstance.on('appFinish', () => {
  console.log('识别已结束')
})

应用事件

| 事件名 | 触发时机 | 说明 | |--------|----------|------| | appFinish | 应用被停止时触发 | 应用的所有处理器都已停止运行 | | appResultText | 最终识别结果事件触发 | 处理识别到的最终文本结果 | | appResponseText | 实时识别过程中触发 | 单词识别,应用过程中实时返回 |

事件示例

latInstance.on('appFinish', () => {
  console.log('识别已结束')
})

latInstance.on('appResultText', (text) => {
  console.log('最终识别结果:', text)
})

latInstance.on('appResponseText', (text) => {
  console.log('实时识别中:', text)
})

语种与方言支持

支持的语种

| 语种代码 | 说明 | |----------|------| | zh_cn | 中文(支持简单的英文识别) | | en_us | 英文 | | 其他小语种 | 需在控制台添加试用或购买后显示 |

支持的应用领域

| 领域代码 | 说明 | |----------|------| | iat | 日常用语 | | medical | 医疗 | | gov-seat-assistant | 政务坐席助手 | | seat-assistant | 金融坐席助手 | | gov-ansys | 政务语音分析 | | gov-nav | 政务语音导航 | | fin-nav | 金融语音导航 | | fin-ansys | 金融语音分析 |

支持的方言

| 方言代码 | 说明 | |----------|------| | mandarin | 普通话 | | 其他方言 | 需在控制台添加试用或购买后显示 |

使用示例

基础识别

import xunfeiLAT from '@mingto/xunfei-lat'

xunfeiLAT.config({
  API_SECRET: 'your_api_secret',
  APPID: 'your_appid',
  API_KEY: 'your_api_key'
})

const latInstance = xunfeiLAT.create({
  language: 'zh_cn',
  domain: 'iat',
  accent: 'mandarin',
  ptt: 1  // 开启标点
})

latInstance
  .on('appFinish', () => console.log('识别完成'))
  .on('appResultText', (text) => console.log('识别结果:', text))

latInstance.start()

智能监听模式

import xunfeiLAT from '@mingto/xunfei-lat'

xunfeiLAT.config({
  API_SECRET: 'your_api_secret',
  APPID: 'your_appid',
  API_KEY: 'your_api_key'
})

const latInstance = xunfeiLAT.create({
  language: 'zh_cn',
  domain: 'iat'
})

latInstance
  .on('appResponseText', (text) => {
    console.log('实时识别:', text)
  })
  .on('appResultText', (text) => {
    console.log('最终结果:', text)
  })

// 启用智能监听,会自动检测语音并开始识别
latInstance.watch()

英文识别

import xunfeiLAT from '@mingto/xunfei-lat'

xunfeiLAT.config({
  API_SECRET: 'your_api_secret',
  APPID: 'your_appid',
  API_KEY: 'your_api_key'
})

const latInstance = xunfeiLAT.create({
  language: 'en_us',
  domain: 'iat'
})

latInstance.on('appResultText', (text) => {
  console.log('English result:', text)
})

latInstance.start()

医疗领域识别

import xunfeiLAT from '@mingto/xunfei-lat'

xunfeiLAT.config({
  API_SECRET: 'your_api_secret',
  APPID: 'your_appid',
  API_KEY: 'your_api_key'
})

const latInstance = xunfeiLAT.create({
  language: 'zh_cn',
  domain: 'medical'  // 医疗领域
})

latInstance.on('appResultText', (text) => {
  console.log('医疗识别结果:', text)
})

latInstance.start()

多候选结果

import xunfeiLAT from '@mingto/xunfei-lat'

xunfeiLAT.config({
  API_SECRET: 'your_api_secret',
  APPID: 'your_appid',
  API_KEY: 'your_api_key'
})

const latInstance = xunfeiLAT.create({
  language: 'zh_cn',
  domain: 'iat',
  nbest: 3,  // 句子多候选结果
  wbest: 2   // 词语多候选结果
})

latInstance.on('appResultText', (text) => {
  console.log('多候选识别结果:', text)
})

latInstance.start()

注意事项

  • ⚠️ 需要在讯飞开放平台申请账号并获取相应的 API_SECRET、APPID、API_KEY
  • ⚠️ 建议将 API 配置放在服务端,前端通过接口获取,避免密钥泄露
  • ⚠️ 首次使用需要用户授权麦克风权限
  • ⚠️ 长语音建议分段识别,提高识别准确度
  • ⚠️ 在页面离开或组件卸载时,记得调用 finish() 方法结束识别
  • ⚠️ 不同领域和方言需要在控制台开通后才能使用
  • ⚠️ 建议在网络环境良好的情况下使用,避免识别延迟
  • ⚠️ nbestwbest 设置多候选会影响性能,响应时间延迟约 200ms 左右

参考文档

详细配置可参考 讯飞语音识别文档

许可证

MIT