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

@tslfe/ai-sdk

v1.0.11

Published

tsl ai sdk

Readme

@tslfe/ai-sdk

一个功能强大的 AI 语音交互 SDK,支持语音录制、语音识别、语音合成、语音唤醒和智能对话等功能。

特性

  • 🎤 语音录制 - 支持实时录音和音频处理
  • 🗣️ 语音识别 - 集成多种 ASR 引擎,支持实时语音转文字
  • 🔊 语音合成 - 支持多种 TTS 引擎,包括字节跳动、阿里云等
  • 🎯 语音唤醒 - 基于 ONNX 模型的离线语音唤醒
  • 🤖 智能对话 - 集成多种 LLM 模型,支持流式对话
  • 📊 数据可视化 - 内置图表展示功能
  • 🎨 音频可视化 - 支持波形图、频谱图等多种可视化效果

安装

npm install @tslfe/ai-sdk

快速开始

基础用法

import { createllm, createAudioRecorder } from "@tslfe/ai-sdk";

// 创建LLM实例
const llm = createllm({
  application: "your-app-name",
  recordConfig: {
    type: "sentence",
    waveView: {
      enable: true,
      el: "#wave-container"
    }
  },
  tts: {
    enable: true,
    type: "bytedance"
  }
});

// 监听事件
llm.on("data", (data) => {
  console.log("收到数据:", data);
});

llm.on("connected", () => {
  console.log("连接成功");
});

语音录制

import { createAudioRecorder } from "@tslfe/ai-sdk";

const recorder = createAudioRecorder({});

// 初始化录音
recorder.init(
  () => console.log("录音初始化成功"),
  (error) => console.error("录音初始化失败:", error)
);

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

// 监听录音事件
recorder.on("audio", ({ text, type }) => {
  console.log("音频数据:", text);
});

语音唤醒


// 初始化语音唤醒
recorder.initWakeup();

// 监听唤醒事件
recorder.on("wakeup", (isWakeup) => {
  if (isWakeup) {
    console.log("语音唤醒成功");
  }
});

API 文档

createllm(config)

创建 LLM 实例,用于智能对话和语音交互。

参数

  • config.application (string) - 应用名称,必填
  • config.recordConfig (AudioRecordConfig) - 录音配置
  • config.clientId (string) - 客户端 ID,可选
  • config.notifications (string[]) - 通知配置
  • config.tts (object) - 语音合成配置
  • config.wakeup (object) - 语音唤醒配置

返回值

返回 LLMInstance 实例,包含以下方法:

  • inputMessage(text, type) - 发送文本消息
  • on(event, callback) - 监听事件
  • off(event, callback) - 取消监听
  • close() - 关闭连接

createAudioRecorder(config)

创建音频录制实例。

参数

  • config.type ('sentence' | 'live') - 录音类型
  • config.mode ('normal' | 'wakeup') - 录音模式
  • config.waveView (object) - 波形可视化配置
  • config.powerLevelLimit (number) - 音量阈值
  • config.remainTime (number) - 停顿时间

返回值

返回 AudioInstance 实例,包含以下方法:

  • init(success, fail) - 初始化录音
  • start() - 开始录音
  • stop() - 停止录音
  • close() - 关闭录音
  • on(event, callback) - 监听事件

事件系统

LLM 事件

  • connected - WebSocket 连接成功
  • data - 接收到数据
  • progress - 处理进度
  • close - 连接关闭

录音事件

  • start - 开始录音
  • stop - 停止录音
  • audio - 音频数据
  • wakeup - 语音唤醒结果
  • error - 错误事件

配置选项

录音配置 (AudioRecordConfig)

interface AudioRecordConfig {
  mode?: "normal" | "wakeup";
  type?: "sentence" | "live";
  waveView?: {
    el?: string;
    enable?: boolean;
    type?: "FrequencyHistogramView" | "WaveView" | "WaveSurferView";
    options?: any;
  };
  powerLevelLimit?: number;
  remainTime?: number;
  stopTime?: number;
  maximumTime?: number;
}

LLM 配置 (LLMConfig)

interface LLMConfig {
  recordConfig: AudioRecordConfig;
  application: string;
  clientId?: string;
  notifications?: string[];
  autoInitRecorder?: boolean;
  notify: 0 | 1;
  tts?: {
    enable?: boolean;
    type?: string;
    params?: object;
  };
}

支持的 TTS 引擎

  • 字节跳动 TTS
  • 阿里云 TTS
  • 自定义 TTS 引擎

开发

安装依赖

yarn install

开发模式

yarn serve

构建

yarn compile