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

@englifespace/volcengine-tts-sdk

v1.0.0

Published

TTS系统SDK

Readme

TTS System SDK

这是一个集成了 Kimi AI 和火山引擎 (Volcengine) TTS 的全栈 SDK,提供了开箱即用的服务端和客户端解决方案,支持流式对话和语音合成。

特性

  • 🚀 全栈解决方案:包含服务端和客户端 SDK
  • 🤖 AI 集成:内置 Kimi AI (Moonshot AI) 支持
  • 🗣️ 高质量语音:集成火山引擎 TTS,支持流式语音合成
  • 📡 WebSocket 通信:基于 WebSocket 的实时双向通信
  • 📝 流式文本:支持 AI 回复的流式输出
  • 🎵 流式音频:支持音频数据的流式传输和播放
  • 🔌 自动重连:客户端支持断线自动重连
  • 📊 统计数据:提供详细的性能和使用统计
  • 📦 类型安全:完全使用 TypeScript 编写,提供完整的类型定义

安装

npm install @englifespace/volcengine-tts-sdk
# 或
bun add @englifespace/volcengine-tts-sdk

快速开始

服务端

服务端 SDK 负责处理 WebSocket 连接、与 Kimi AI 对话以及调用火山引擎 TTS 服务。

前置要求: 确保设置了以下环境变量:

  • KIMI_API_KEY: Moonshot AI API Key
  • KIMI_BASE_URL: Moonshot AI Base URL (例如 https://api.moonshot.cn/v1)
  • VOLCENGINE_APP_ID: 火山引擎 App ID
  • VOLCENGINE_APP_KEY: 火山引擎 Access Token
  • VOLCENGINE_TTS_WS: 火山引擎 TTS WebSocket URL (例如 wss://openspeech.bytedance.com/api/v1/tts/ws_binary)
import { createTTSServer } from '@englifespace/volcengine-tts-sdk/server';

const server = createTTSServer({
  server: {
    port: 8080,
    host: '0.0.0.0'
  },
  ai: {
    model: 'kimi-k2-0711-preview',
    systemPrompt: '你是一个友好的助手...'
  }
});

async function start() {
  try {
    await server.start();
    console.log('Server running on port 8080');
  } catch (error) {
    console.error('Failed to start server:', error);
  }
}

start();

客户端

客户端 SDK 负责连接服务端、发送消息、接收音频流并播放。

import { createTTSClient } from '@englifespace/volcengine-tts-sdk/client';

const client = createTTSClient({
  client: {
    serverUrl: 'ws://localhost:8080/tts',
    autoConnect: true
  }
});

// 设置事件回调
client.setCallbacks({
  onConnectionEstablished: () => {
    console.log('Connected!');
  },
  onTextChunk: (event) => {
    console.log('AI Text:', event.data.content);
  },
  onAudioChunk: (event) => {
    // SDK 内部会自动处理音频缓冲,这里可以获取原始数据
  },
  onSentenceComplete: (event) => {
    console.log('Sentence finished:', event.data.sentence);
  }
});

// 开始连接(如果在配置中设置了 autoConnect: true 则不需要手动调用)
// await client.connect();

// 发送消息开始对话
async function chat() {
  try {
    await client.startConversation('你好,请用英语介绍一下你自己。');
  } catch (error) {
    console.error('Chat error:', error);
  }
}

本地开发

如果你想在本地开发或修改此 SDK:

  1. 克隆项目

    git clone <repository-url>
    cd volcengine-tts-sdk
  2. 安装依赖 本项目使用 Bun 进行包管理。

    bun install
  3. 构建项目

    bun run build

    构建产物将输出到 dist/ 目录。

API 参考

服务端配置 (TTSConfig)

interface TTSConfig {
  server?: {
    port?: number;      // 默认 8080
    host?: string;      // 默认 '0.0.0.0'
    corsOrigin?: string; // 默认 '*'
  };
  ai?: {
    apiKey?: string;
    baseURL?: string;
    model?: string;     // 默认 'kimi-k2-0711-preview'
    systemPrompt?: string;
  };
  tts?: {
    provider?: 'volcengine';
    // 其他 TTS 配置...
  };
}

客户端 API

startConversation(userMessage: string)

开始一轮新的对话。

synthesizeText(text: string, options?: SynthesisOptions)

仅进行文字转语音合成(不经过 AI 对话)。

stop() / disconnect()

断开连接并停止当前播放。

事件回调

  • onConnectionEstablished: 连接建立
  • onConversationStarted: 对话开始
  • onTextChunk: 收到 AI 文本片段
  • onSentenceStart: 句子开始处理
  • onAudioChunk: 收到音频片段
  • onSentenceComplete: 句子处理完成
  • onChatComplete: 整轮对话完成
  • onError: 发生错误

License

ISC