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

iat-voice

v0.0.57

Published

Downloads

276

Readme

Zoe 语音识别(语音听写)

🏡 下载安装:

# 使用npm命令下载安装
$ npm i iat-voice

📚 使用方法:

流式识别

| 参数名 | 类型 | 是否必需 | 描述 | | ------------ | ------ | -------- | -------------------------------------------- | | url | string | 是 | webSocket地址 |


import {IatRecorder} from 'iat-voice'
import {ref} from 'vue';
const textVal = ref('')
const url = '服务地址'
const recorder = new IatRecorder({
  url: url,
  onTextChange: function (text) {
    // 监听文本变化
  },
  onWillStatusChange: function (oldStatus, newStatus) {
    // 监听状态变化
    console.log(oldStatus, newStatus, '状态变化')
  },
})

// 开始录音
const start = () => {
  recorder.start()
}

// 结束录音
const stop = () => {
  recorder.stop()
}

文件语音识别

| 参数名 | 类型 | 是否必需 | 描述 | |------------|--------|------|-------| | session_id | string | 是 | 唯一ID | | file | blob | 是 | 录音文件 | | audio_type | string | 否 | 录音格式-支持的音频格式为wav、mp3、m4a、aac |

这里使用recorder-core插件来获取录音数据。获取录音数据诸多方法,这里只展示recorder-core的例子。

import Recorder from 'recorder-core'
import 'recorder-core/src/engine/wav.js'
import 'recorder-core/src/engine/mp3.js'
import 'recorder-core/src/engine/mp3-engine.js'
import {VoiceRecognizer} from 'iat-voice'
import {ref} from 'vue';
const rec = ref()
const recOpen = () => {
  //创建录音对象
  rec.value = Recorder({
    type: 'mp3', //录音格式,可以换成wav等其他格式
    sampleRate: 16000, //录音的采样率,越大细节越丰富越细腻
    bitRate: 16, //录音的比特率,越大音质越好
    onProcess: (
        buffers,
        powerLevel,
        bufferDuration,
        bufferSampleRate,
        newBufferIdx,
        asyncEnd,
    ) => {

    },
  })
  //打开录音,获得权限
  rec.value.open(
      () => {
        if (!rec.value) {
          console.error('未打开录音')
          return
        }
        rec.value.start()
        console.log('录音已打开')
      },
      (msg, isUserNotAllow) => {
        //用户拒绝了录音权限,或者浏览器不支持录音
        console.log(
            (isUserNotAllow ? 'UserNotAllow,' : '') + '无法录音:' + msg,
        )
      },
  )
}


const recStop = () => {
  if (!rec.value) {
    console.error('未打开录音')
    return
  }
  rec.value.stop(
      (blob, duration) => {
        //blob就是我们要的录音文件对象,可以上传,或者本地播放
        //简单利用URL生成本地文件地址,此地址只能本地使用,比如赋值给audio.src进行播放,赋值给a.href然后a.click()进行下载(a需提供download="xxx.mp3"属性)
        const localUrl = (window.URL || webkitURL).createObjectURL(blob)
        console.log('录音成功', blob, localUrl, '时长:' + duration + 'ms')

        // this.upload(blob) //把blob文件上传到服务器

        rec.value.close() //关闭录音,释放录音资源,当然可以不释放,后面可以连续调用start
        rec.value = null
        const formData = new FormData()
        formData.append('audio', blob, 'recorded_audio.wav')
        transText(blob)
      },
      (err) => {
        console.error('结束录音出错:' + err)
        rec.value.close() //关闭录音,释放录音资源,当然可以不释放,后面可以连续调用start
        rec.value = null
      },
  )
}

const transText = (blob) => {
  const recognizer = new VoiceRecognizer('服务地址')
  const session = '761877aacbcc'
  recognizer.recognize(session, blob, 'mp3')
      .then(getText => {
        console.log('识别结果:', getText());  // 获取识别结果
      })
      .catch(err => {
        console.error('识别出错:', err);
      });
}