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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@minto-ai/huoshan-lat

v0.0.27

Published

讯飞LAT 语音转文本

Readme

@huoshan-lat/xunfei-lat

一个用于音频录制、处理、分割和通过网络请求发送音频数据的语音处理库。

安装

pnpm install @huoshan-lat/xunfei-lat

使用

配置系统参数

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

/**
 * 平台系统配置
 */
const systemConfig = {

}

// 配置系统参数
LatController.config(systemConfig)

创建实例

创建 LatController 实例,并配置业务参数:

/**
 * 创建LatController实例
 */
const businesstParams = {

  /**
   *采样率,默认为16000
   */
  sample_rate: number,

  /**
   * 位深
   */
  bits: number,
  /**
   * 声道数
   */
  channels: number,
  format: string,
  codec: string,
  enable_itn: boolean,
  enable_punc: boolean,
  enable_ddc: boolean,

  // sample_rate=16000&bits=16&channels=1&format=raw&codec=raw&enable_itn=true&enable_punc=true&enable_ddc=true

  /**
   * 语种
   * - 'zh_cn': 中文(支持简单的英文识别)
   * - 'en_us': 英文
   * - 其他小语种参数值需在控制台添加试用或购买后显示
   */
  language: 'zh_cn',

  /**
   * 应用领域
   * - 'iat': 日常用语
   * - 'medical': 医疗
   * - 'gov-seat-assistant': 政务坐席助手
   * - 'seat-assistant': 金融坐席助手
   * - 'gov-ansys': 政务语音分析
   * - 'gov-nav': 政务语音导航
   * - 'fin-nav': 金融语音导航
   * - 'fin-ansys': 金融语音分析
   */
  domain: 'iat',

  /**
   * 方言,当前仅在language为中文时,支持方言选择。
   * - 'mandarin': 中文普通话、其他语种
   * - 其他方言参数值需在控制台添加试用或购买后显示
   */
  accent: 'mandarin',

  /**
   * 用于设置后端点检测的静默时间,单位是毫秒。
   * 默认2000(小语种除外,小语种不设置该参数默认为未开启VAD)。
   */
  vad_eos: 3600000,

  /**
   * 动态修正(仅中文普通话支持)
   * - 'wpgs': 开启流式结果返回功能
   */
  dwa: 'wpgs',

  /**
   * 领域个性化参数(仅中文支持)
   * - 'game': 游戏
   * - 'health': 健康
   * - 'shopping': 购物
   * - 'trip': 旅行
   */
  pd: 'game',

  /**
   * 是否开启标点符号添加(仅中文支持)
   * - 1: 开启(默认值)
   * - 0: 关闭
   */
  ptt: 1,

  /**
   * 字体(仅中文支持)
   * - 'zh-cn': 简体中文(默认值)
   * - 'zh-hk': 繁体香港
   */
  rlang: 'zh-cn',

  /**
   * 返回子句结果对应的起始和结束的端点帧偏移值。
   * - 0: 关闭(默认值)
   * - 1: 开启
   */
  vinfo: 0,

  /**
   * 数字格式规则为阿拉伯数字格式(中文普通话和日语支持)
   * - 0: 关闭
   * - 1: 开启(默认值)
   */
  nunum: 1,

  /**
   * speex音频帧长,仅在speex音频时使用
   * - 1: 当speex编码为标准开源speex编码时必须指定
   * - 2: 当speex编码为讯飞定制speex编码时不要设置
   */
  speex_size: 1,

  /**
   * 获取在发音相似时的句子多侯选结果。
   * 取值范围[1,5],设置多候选会影响性能,响应时间延迟200ms左右。
   */
  nbest: 1,

  /**
   * 获取在发音相似时的词语多侯选结果。
   * 取值范围[1,5],设置多候选会影响性能,响应时间延迟200ms左右。
   */
  wbest: 1
}

/**
 *
 */
const sectionDelayParams = {

  /**
   * 是否自动控制延迟
   */
  autoControl: true,

  /**
   * 第一次延迟时间
   */
  initialDelay: 3000,

  /**
   * 后续延迟时间
   */
  subsequentDelay: 1000,
}

const latInstance = LatController.create(businesstParams, sectionDelayParams)

可用方法

开始录音

latInstance.start()

智能语音监听

latInstance.watch()

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

结束录音

latController.finish()

应用钩子

应用钩子事件允许您在特定时刻执行自定义逻辑。

| 钩子名称 | 触发时机 | 描述 | | :---------------- | :--------------------------------- | :----------------------------- | | appFinish | 应用被停止时触发。 | 应用的所有处理器都已停止运行。 | | appResultText | 识别结果事件触发。 | 处理识别到的文本结果。 | | appResponseText | 单词识别触发,也就是应用过程中触发 |

appFinish

当应用的所有处理器完成工作,应用被停止时,此事件被触发:

latInstance.on('appFinish', () => {
  console.log('应用已停止运行,所有处理器均已完成工作。')
})

appResultText

当应用处理并识别出文本结果时,此事件被触发:

latInstance.on('appResultText', () => {
  console.log('应用已输出识别到的文本结果。')
})

appResponseText

当应用过程中触发,也就是应用过程中触发

latInstance.on('appResponseText', () => {
  console.log('应用已输出识别到的文本结果。')
})

注意

本工具库为内部工具库,不负责改BUG,请勿随便下载。