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 🙏

© 2025 – Pkg Stats / Ryan Hefner

fish-audio-sdk

v2024.12.8

Published

fish.audio platform api sdk

Downloads

321

Readme

Fish Audio SDK

JavaScript/TypeScript SDK for Fish Audio API.

Install

npm install fish-audio-sdk

Usage

Initialize a Session to use APIs. All APIs use async/await patterns.

import { Session } from 'fish-audio-sdk';

const session = new Session("your_api_key");

You can change the endpoint if needed:

const session = new Session("your_api_key", "https://your-proxy-domain");

Text to Speech

import { Session, TTSRequest } from 'fish-audio-sdk';
import * as fs from 'fs';

const session = new Session("your_api_key");

// Basic usage
const writeStream = fs.createWriteStream("output.mp3");
for await (const chunk of session.tts(new TTSRequest("Hello, world!"))) {
  writeStream.write(chunk);
}
writeStream.end();

// With options
const request = new TTSRequest("Hello, world!", {
  format: "mp3",           // 'wav' | 'pcm' | 'mp3'
  mp3Bitrate: 128,         // 64 | 128 | 192
  chunkLength: 200,        // 100-300
  normalize: true,         // Audio normalization
  latency: "balanced",     // 'normal' | 'balanced'
  prosody: {
    speed: 1.0,           // Speech speed
    volume: 0.0           // Volume adjustment
  }
});

Voice Training

You can train new voice models using reference audio:

import { Session } from 'fish-audio-sdk';
import * as fs from 'fs';

const session = new Session("your_api_key");

// Create a new voice model
const voiceData = fs.readFileSync('voice_sample.wav');
const model = await session.createModel({
  title: "My Voice Model",
  description: "Custom voice model",
  voices: [voiceData],
  texts: ["Text matching the voice sample"],
  tags: ["custom", "voice"],
  enhanceAudioQuality: true
});

Automatic Speech Recognition (ASR)

Convert audio to text with optional language detection:

import { Session, ASRRequest } from 'fish-audio-sdk';
import * as fs from 'fs';

const session = new Session("your_api_key");
const audioBuffer = fs.readFileSync('audio.mp3');

const result = await session.asr(new ASRRequest(
  audioBuffer,
  "en",              // Optional: specify language
  false              // Optional: include timestamps
));

console.log(result.text);      // Full transcription
console.log(result.duration);  // Audio duration in seconds
console.log(result.segments);  // Array of {text, start, end} segments

Model Management

List, get, and manage voice models:

import { Session } from 'fish-audio-sdk';

const session = new Session("your_api_key");

// List models with pagination and filters
const models = await session.listModels({
  pageSize: 10,
  pageNumber: 1,
  title: "search term",
  tag: ["tag1", "tag2"],
  self: true,               // Only show your models
  authorId: "user_id",
  language: ["en", "zh"],
  titleLanguage: "en",
  sortBy: "created_at"      // 'task_count' | 'created_at'
});

// Get specific model
const model = await session.getModel("model_id");

// Update model
await session.updateModel("model_id", {
  title: "Updated Title",
  description: "New description",
  visibility: "public",
  tags: ["updated", "tags"]
});

// Delete model
await session.deleteModel("model_id");

Real-time TTS with WebSocket

For streaming text-to-speech in real-time:

import { WebSocketSession, TTSRequest } from 'fish-audio-sdk';

const ws = new WebSocketSession("your_api_key");

async function* textStream() {
  yield "First chunk of text";
  yield "Second chunk of text";
  // ...
}

const request = new TTSRequest(""); // Initial empty request

// Stream audio chunks as text is processed
for await (const audioChunk of ws.tts(request, textStream())) {
  // Process audio chunk
}

await ws.close(); // Clean up when done

Error Handling

The SDK provides specific error types:

import { HttpCodeError, WebSocketError } from 'fish-audio-sdk';

try {
  await session.getModel("invalid_id");
} catch (error) {
  if (error instanceof HttpCodeError) {
    console.log(`HTTP Error ${error.status}: ${error.message}`);
  } else if (error instanceof WebSocketError) {
    console.log(`WebSocket Error: ${error.message}`);
  }
}

Account Management

Check API credits and package information:

const credits = await session.getApiCredit();
console.log(`Available credits: ${credits.credit}`);

const package = await session.getPackage();
console.log(`Package type: ${package.type}`);
console.log(`Balance: ${package.balance}/${package.total}`);

License

[License terms]

Contributing

[Contributing guidelines]