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-ie11

v0.0.2

Published

IE11 兼容的设备录音版 IatRecorder(仅设备录音,零运行时依赖,UMD 全局名 IatRecorder)

Readme

iat-voice-ie11

IE11 兼容的设备录音版 IatRecorder。从 iat-voice 中抽离出"设备/阵列麦录音"路径,去除全部 Web Audio API 依赖(getUserMedia / AudioContext / Worker),转译为 ES5 并内联 polyfill,可直接在 IE11 运行。

仅支持设备录音(由本地硬件设备完成录音,浏览器通过 WebSocket 中转音频数据)。不含浏览器麦克风录音——该能力依赖 IE11 不支持的 Web Audio API。

特性

  • ✅ IE11 可用(产物为纯 ES5,已通过 es-check es5
  • ✅ 零运行时依赖(Promise / Set / TextEncoder/TextDecoder 等 polyfill 已打包进产物)
  • ✅ UMD 格式,支持 <script> 全局引入、CommonJS、AMD

安装

npm install iat-voice-ie11

或直接用 CDN / 本地 script 引入:

<script src="https://unpkg.com/iat-voice-ie11"></script>
<!-- 引入后全局可用 window.IatRecorder -->

使用

// CommonJS
var IatRecorder = require('iat-voice-ie11');

// 或 <script> 引入后直接用全局 IatRecorder

var recorder = new IatRecorder({
  passage: 2,        // 取第几通道(1 或 2)
  time: 500,         // 发送间隔相关参数
  url: 'ws://后端识别服务地址/ws/sessions/{sessionId}?api_key=...&sign=...&timestamp=...',
  onTextChange: function (val) {
    // device_type === 2 为设备直出结果,取 val.data.result
    // 否则取 val.text
    if (val.device_type === 2) {
      console.log('识别结果:', val.data.result);
    } else {
      console.log('识别结果:', val.text);
    }
  },
  onWillStatusChange: function (oldStatus, newStatus) {
    console.log('状态:', oldStatus, '->', newStatus);
  },
  onSendErrorMessage: function (msg, error) {
    console.log('错误:', msg, error);
  }
});

// 连接设备(留空则用默认 127.0.0.1:12280)
recorder.machineConnect('127.0.0.1:12280');

// 开始录音
recorder.machineStart();

// 停止录音
recorder.machineStop();

// 断开
recorder.machineDisconnectDemo();

// 导出本次录音的 PCM 数据(触发下载)
recorder.getMachineData();

构造参数

| 参数 | 类型 | 默认 | 说明 | |---|---|---|---| | url | string | — | 后端识别服务 WebSocket 地址 | | passage | number | 2 | 采集的语音通道(1 / 2) | | time | number | 100 | 发送数据的间隔系数 | | heartbeatInterval | number | 30000 | 心跳发送间隔(ms) | | heartbeatTimeout | number | 30000 | 心跳超时(ms) | | onTextChange | function | — | 识别结果回调 | | onWillStatusChange | function | — | 状态变化回调 (old, new) | | onSendErrorMessage | function | — | 错误/日志回调 |

主要方法

| 方法 | 说明 | |---|---| | machineConnect(ws) | 连接设备 WebSocket(ws://{ws}/record)并连接后端识别服务 | | machineStart() | 通知设备开始录音 | | machineStop() | 通知设备停止录音并关闭连接 | | machineDisconnectDemo() | 用户手动断开全部连接 | | getMachineData() | 合并本次录音 PCM 并触发下载 |

状态值(onWillStatusChange 的 newStatus)

| 状态 | 含义 | |---|---| | null | 初始/未连接 | | init | 后端 WebSocket 正在建立 | | ing | 已连接,录音/识别进行中 | | pause | 已停止录音 | | end | 连接已结束 | | disconnected | 设备连接断开 | | reconnecting:N | 第 N 次重连中 | | offline | 重连次数耗尽 | | error | 连接错误 |

onTextChange 回调数据

{
  text,         // 文本(device_type 非 2 时使用)
  data,         // 原始结果对象(device_type === 2 时取 data.result)
  duration,     // 当前录音时长(秒)
  device_type   // 1 = 后端识别流;2 = 设备直出结果
}

完整 HTML 接入示例

url 通常需要一个 sessionId(UUID)和一个签名 sign。签名规则由后端约定,下例复刻常见的 MD5(timestamp|sessionId|secret),用 crypto-js 计算。IE11 下 crypto-js 全量 UMD 包原生兼容;uuid npm 包不兼容 IE11,示例用手写的 ES5 版本。

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
</head>
<body>
  <button id="connect">连接</button>
  <button id="start">开始</button>
  <button id="stop">停止</button>
  <div id="result"></div>

  <script src="https://unpkg.com/crypto-js@4/crypto-js.js"></script>
  <script src="https://unpkg.com/iat-voice-ie11"></script>
  <script>
    // IE11 兼容的 uuid v4(测试场景足够;生产可换更强的随机源)
    function uuidv4() {
      return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        var r = (Math.random() * 16) | 0;
        var v = c === 'x' ? r : (r & 0x3) | 0x8;
        return v.toString(16);
      });
    }
    function genSign(sessionId, timestamp, secret) {
      return CryptoJS.MD5(timestamp + '|' + sessionId + '|' + secret).toString();
    }

    var recorder = null;
    document.getElementById('connect').onclick = function () {
      var uuid = uuidv4();
      var ts = Math.floor(new Date().getTime() / 1000);
      var sign = genSign(uuid, ts, '你的签名密钥');
      var url = 'ws://后端地址/ws/sessions/' + uuid +
        '?api_key=你的apiKey&sign=' + sign + '&timestamp=' + ts;

      recorder = new IatRecorder({
        passage: 2,
        time: 500,
        url: url,
        onTextChange: function (val) {
          var text = val.device_type === 2 ? (val.data && val.data.result) : val.text;
          document.getElementById('result').innerHTML += (text || '');
        },
        onWillStatusChange: function (o, n) { console.log('状态', o, '->', n); }
      });
      recorder.machineConnect('127.0.0.1:12280'); // 设备地址
    };
    document.getElementById('start').onclick = function () { recorder && recorder.machineStart(); };
    document.getElementById('stop').onclick = function () { recorder && recorder.machineStop(); };
  </script>
</body>
</html>

典型调用流程

machineConnect()  →  状态变为 ing  →  machineStart()  →  说话(设备推流,onTextChange 持续回调)
                                          ↓
                                     machineStop()  →  getMachineData()(可选,下载 PCM)

兼容性

  • 目标浏览器:IE11
  • 依赖的浏览器能力:WebSocketArrayBuffer / Uint8Array / DataViewBlob / FileReaderURL.createObjectURL(IE11 原生支持)
  • 产物已内联 core-js(Promise / Set / Array.from 等)与 TextEncoder/TextDecoder polyfill,无需额外引入

IE11 注意事项

  • 页面建议加 <meta http-equiv="X-UA-Compatible" content="IE=edge" />,强制使用最高文档模式
  • 不要用 file:// 直接打开页面,需通过 HTTP/HTTPS 服务访问,否则 WebSocket 可能受限
  • crypto-js 请引用全量 UMD 包(如 crypto-js/crypto-js.js),按需子模块在部分环境下加载顺序敏感

License

MIT