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

voice-sdk-4u

v1.0.2

Published

一个简单易语音录制和传输 SDK,支持按住说话、WebSocket 传输等功能。 ## 功能特性 - 按住说话录音功能 实时音频采集和处理 WebSocket 音频数据传输 自动权限检查和提示 支持音频 Worklet 处理 自动重连机制 ## 安装 ```bash npm install voice-sdk-4u ``` 或直接在浏览器中引入: ```html <script src="dist/voice-sdk-4u.js"></script> ``` ##

Readme

Voice SDK

一个简单易语音录制和传输 SDK,支持按住说话、WebSocket 传输等功能。

功能特性

  • 按住说话录音功能 实时音频采集和处理 WebSocket 音频数据传输 自动权限检查和提示 支持音频 Worklet 处理 自动重连机制

安装

npm install voice-sdk-4u

或直接在浏览器中引入:

<script src="dist/voice-sdk-4u.js"></script>

快速开始

基础用法

// 创建 SDK 实例
const sdk = new VoiceSDK({
    wsUrl: 'ws://your-server-url',
    onError: (error) => console.error('错误:', error),
    onSuccess: (result) => console.log('收到服务器响应:', result)
});
// 初始化
await sdk.init();
// 开始录音
await sdk.startRecording();
// 停止录音
sdk.stopRecording();
// 销毁实例
sdk.destroy();

完整示例

const sdk = new VoiceSDK({
    wsUrl: 'ws://your-server-url',
    useWorklet: true, // 是否使用 AudioWorklet
    audioConfig: { // 自定义音频配置
    sampleRate: 44100,
    channelCount: 1,
    bitsPerSample: 16
},
onError: (error) => {
    // 错误处理
    console.error('发生错误:', error);
    // 可以根据不同错误类型显示不同提示
    if (error.message === '麦克风权限被拒绝') {
        alert('请允许使用麦克风');
    }
},
onSuccess: (result) => {
    // 处理服务器返回的数据
    console.log('服务器响应:', result);
}
});
// 按住说话示例
const recordButton = document.getElementById('recordBtn');
// 确保在使用前初始化
sdk.init().catch(console.error);
recordButton.addEventListener('mousedown', async () => {
    try {
        await sdk.startRecording();
    } catch (error) {
        console.error('开始录音失败:', error);
    }
    });
recordButton.addEventListener('mouseup', () => {
    sdk.stopRecording();
});
    // 页面卸载时清理资源
    window.addEventListener('unload', () => {
    sdk.destroy();
});

API 文档

VoiceSDK 配置选项

| 参数 | 类型 | 必填 | 默认值 | 说明 | | ----------- | -------- | ---- | ------ | ------------------------------ | | wsUrl | string | 是 | - | WebSocket 服务器地址 | | useWorklet | boolean | 否 | true | 是否使用 AudioWorklet 处理音频 | | audioConfig | object | 否 | 见下方 | 音频配置项 | | onError | function | 否 | - | 错误回调函数 | | onSuccess | function | 否 | - | 成功回调函数 |

默认音频配置

{
sampleRate: 16000, // 采样率
channelCount: 1, // 声道数
bitsPerSample: 16 // 采样位数
}

错误类型

SDK 可能抛出的错误:

  • 未检测到麦克风设备: 设备没有麦克风或麦克风被禁用
  • 麦克风权限被拒绝: 用户拒绝了麦克风访问权限
  • WebSocket 连接失败: 无法连接到服务器
  • 录音失败: 录音过程中发生错误

浏览器兼容性

  • Chrome 70+
  • Firefox 75+
  • Safari 14.1+
  • Edge 79+

注意事项

  1. 确保在 HTTPS 环境下使用,或在 localhost 开发
  2. 使用前必须调用 init() 方法进行初始化
  3. 注意及时调用 destroy() 方法释放资源
  4. 建议在 try-catch 中使用异步方法

API 接口说明

handleHidePerson() 数字人隐藏

sdk.handleHidePerson();

handleShowPerson() 数字人显示

sdk.handleShowPerson();

文本转语音播报 handleTextToSpeech(text)

/***@
 * @param {string} text - 要播报的文本
 * @returns {void}
 */
sdk.handleTextToSpeech('你好!');

文本聊天 handleTextChat(text)

/***@
 * @param {string} text - 要聊天的文本
 * @returns {void}
 */
sdk.handleTextChat('今天天气真不错!');