Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions .mintlify/skills/fish-audio-sdk/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
name: fish-audio-sdk
description: Write code with the official Fish Audio SDKs, Python (`fishaudio`, PyPI `fish-audio-sdk`) and JavaScript/TypeScript (`fish-audio`). Use when the user wants text-to-speech, speech-to-text, voice cloning / voice-model management, or realtime WebSocket TTS through the installed SDK rather than raw HTTP. Covers install and auth, sync + async Python, the TypeScript client, exact method signatures and defaults, model selection (including the S2.1 typing caveat), the real exception types, and the Python↔JavaScript naming differences. For raw REST/WebSocket calls without an SDK (curl, unsupported languages, edge runtimes), use the `fish-audio-api` skill instead.
description: Write code with the official Fish Audio SDKs, Python (`fishaudio`, PyPI `fish-audio-sdk`) and JavaScript/TypeScript (`fish-audio`). Use when the user wants text-to-speech, speech-to-text (including realtime transcription in JavaScript), voice cloning / voice-model management, or realtime WebSocket TTS through the installed SDK rather than raw HTTP. Covers install and auth, sync + async Python, the TypeScript client, exact method signatures and defaults, model selection (including the S2.1 typing caveat), the real exception types, and the Python↔JavaScript naming differences. For raw REST/WebSocket calls without an SDK (curl, unsupported languages, edge runtimes), use the `fish-audio-api` skill instead.
---

# Fish Audio SDK Skill

Use this skill to generate correct, runnable code with the **official Fish Audio SDKs**:

- **Python**: package `fish-audio-sdk` on PyPI, imported as `fishaudio`. (The same wheel still ships a separate legacy `fish_audio_sdk` package. Do **not** mix them; everything here is the modern `fishaudio` package.)
- **JavaScript / TypeScript**: package `fish-audio` on npm, imported as `FishAudioClient`.
- **JavaScript / TypeScript**: package `fish-audio` on npm (0.2.0), imported as `FishAudioClient`. Node.js 20+; `import` and `require` both work.

If the user wants raw `curl` / HTTP / WebSocket without installing an SDK, use the **`fish-audio-api`** skill instead.

Expand All @@ -18,10 +18,10 @@

- **Auth:** both SDKs read the API key from the `FISH_API_KEY` environment variable automatically. Get keys at `https://fish.audio/app/api-keys`. Never hardcode a key.
- **Base URL:** `https://api.fish.audio` (override with `base_url=` in Python / `baseUrl:` in JS).
- **TTS models:** the API supports `s1` (deprecated), `s2-pro`, `s2.1-pro` (recommended for production), and `s2.1-pro-free` (free tier). Do not choose `s1` for new code: S1 is deprecated and will be retired on December 31, 2026. After that date, requests that specify `s1` are served by `s2.1-pro` (migration: `https://docs.fish.audio/developer-guide/models-pricing/migrate-from-s1`). The Python SDK (`fish-audio-sdk` 1.4.0 and later) defaults to `s2.1-pro`; its `Model` type names `s1`, `s2-pro`, `s2.1-pro`, `s2.1-pro-free` and `drama-3` and accepts any other string, so no `# type: ignore` is needed (1.3.0 and earlier defaulted to `s2-pro` and typed only `s1` / `s2-pro`). The JS package on npm (`fish-audio` 0.1.0) types `backend` without `s2-pro` or `s2.1-pro` and defaults it to `"s1"` at runtime (its README says `"s2-pro"`), so in JS always pass `backend` explicitly. The JS SDK forwards the model value without runtime validation, so `"s2.1-pro"` works over the wire, but TypeScript flags it, so add an `as` cast, or use the `fish-audio-api` skill for raw calls. `speech-1.5` / `speech-1.6` are **deprecated**. In Python pass `model="s2.1-pro"` (keyword); in JS pass the **positional** `backend` argument.
- **ASR models:** use `transcribe-1-pro` (recommended: speaker turns, long recordings, emotion cues). Neither SDK has an ASR `model` argument: send the `model: transcribe-1-pro` HTTP header on every request (Python `RequestOptions(additional_headers=...)`, JS `requestOptions.headers`). A request without it is served and billed as `transcribe-1`, the model for short recordings. See [references/speech-to-text.md](references/speech-to-text.md).
- **TTS models:** the API supports `s1` (deprecated), `s2-pro`, `s2.1-pro` (recommended for production), and `s2.1-pro-free` (free tier). Do not choose `s1` for new code: S1 is deprecated and will be retired on December 31, 2026. After that date, requests that specify `s1` are served by `s2.1-pro` (migration: `https://docs.fish.audio/developer-guide/models-pricing/migrate-from-s1`). The Python SDK (`fish-audio-sdk` 1.4.0 and later) defaults to `s2.1-pro`; its `Model` type names `s1`, `s2-pro`, `s2.1-pro`, `s2.1-pro-free` and `drama-3` and accepts any other string, so no `# type: ignore` is needed (1.3.0 and earlier defaulted to `s2-pro` and typed only `s1` / `s2-pro`). The JS SDK (`fish-audio` 0.2.0) defaults to `"s2.1-pro"`, and its `Backends` type names `s2.1-pro`, `s2.1-pro-free`, `drama-3`, `s2-pro`, `s1` and accepts any other string, so no cast is needed. `fish-audio` 0.1.0 defaulted to the deprecated `"s1"`; if a project is on 0.1.0, upgrade it or pass the model explicitly. `speech-1.5` / `speech-1.6` are **deprecated**. In Python pass `model="s2.1-pro"` (keyword); in JS pass the **positional** `backend` argument.
- **ASR models:** use `transcribe-1-pro` (recommended: speaker turns, long recordings, emotion cues). It is selected by the `model` HTTP header: in JS pass `model: "transcribe-1-pro"` in the `convert()` request (`fish-audio` 0.2.0+), in Python send the header with `RequestOptions(additional_headers=...)`. A request without it is served and billed as `transcribe-1`, the model for short recordings. See [references/speech-to-text.md](references/speech-to-text.md).
- **Audio formats:** `mp3` (default), `wav`, `pcm`, `opus`.
- **Playback in examples:** `play()` shells out to a system audio tool: Python uses **ffmpeg/ffplay** (or `mpv`), JS uses **ffplay**. It is for local/desktop use; in a server, `save()` to a file or stream the bytes instead. See [references/installation.md](references/installation.md).

Check warning on line 24 in .mintlify/skills/fish-audio-sdk/SKILL.md

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'ffplay'?

## Quick start: Python

Expand Down Expand Up @@ -63,32 +63,29 @@
// convert() returns audio you can play or pipe to a file
const audio = await client.textToSpeech.convert({
text: "Hello from Fish Audio!",
}); // npm 0.1.0 defaults to the deprecated "s1"; pass a model as shown below
}); // defaults to "s2.1-pro" (fish-audio 0.2.0+)
await play(audio); // local playback (needs ffplay)
```

To pick a model in JS, pass `backend` as the **positional** argument (not a named option):

```ts
import type { Backends } from "fish-audio";

// The cast is needed because the npm 0.1.0 `Backends` type omits "s2.1-pro".
const audio = await client.textToSpeech.convert(
{ text: "Hi" },
"s2.1-pro" as Backends
"s2.1-pro-free"
);
```

## Capabilities → references

| Task | Reference |
| ---------------------------------------------------------------- | ------------------------------------------------------------ |
| Install, auth, playback deps, verify a key | [references/installation.md](references/installation.md) |
| Text-to-Speech (convert, stream, formats, prosody, model select) | [references/text-to-speech.md](references/text-to-speech.md) |
| Voice cloning (instant references + persistent voice models) | [references/voice-cloning.md](references/voice-cloning.md) |
| Speech-to-Text (models, timestamps, fields the SDK drops) | [references/speech-to-text.md](references/speech-to-text.md) |
| Realtime WebSocket TTS (stream text → audio) | [references/websocket.md](references/websocket.md) |
| Errors, retries, and timeouts (the **real** exception types) | [references/errors.md](references/errors.md) |
| Task | Reference |
| ------------------------------------------------------------------------- | ------------------------------------------------------------ |
| Install, auth, playback deps, verify a key | [references/installation.md](references/installation.md) |

Check warning on line 83 in .mintlify/skills/fish-audio-sdk/SKILL.md

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'deps'?
| Text-to-Speech (convert, stream, formats, prosody, model select) | [references/text-to-speech.md](references/text-to-speech.md) |
| Voice cloning (instant references + persistent voice models) | [references/voice-cloning.md](references/voice-cloning.md) |
| Speech-to-Text (models, timestamps, fields the SDK drops, realtime in JS) | [references/speech-to-text.md](references/speech-to-text.md) |
| Realtime WebSocket TTS (stream text → audio) | [references/websocket.md](references/websocket.md) |
| Errors, retries, and timeouts (the **real** exception types) | [references/errors.md](references/errors.md) |

## Python ↔ JavaScript name map

Expand All @@ -102,14 +99,15 @@
| Realtime WebSocket | `client.tts.stream_websocket(text_stream)` | `client.textToSpeech.convertRealtime(request, textStream)` |
| TTS + word timestamps | `client.tts.convert_with_timestamps(text=...)` | not in the SDK; call the HTTP endpoint |
| Speech-to-Text | `client.asr.transcribe(audio=...)` | `client.speechToText.convert({ audio })` |
| Realtime STT | see the Python SDK reference | `client.speechToText.convertRealtime(request, audio)` |
| List voice models | `client.voices.list()` | `client.voices.search()` |
| Get voice model | `client.voices.get(id)` | `client.voices.get(id)` |
| Create voice (clone) | `client.voices.create(title=..., voices=[bytes])` | `client.voices.ivc.create({ title, voices: [File] })` |
| Update / delete voice | `client.voices.update(id, ...)` / `delete(id)` | `client.voices.update(id, ...)` / `delete(id)` |
| Credit balance | `client.account.get_credits()` | `client.user.get_api_credit()` |
| Subscription package | `client.account.get_package()` | `client.user.get_package()` |
| Choose model | `model="s2.1-pro"` keyword arg | positional `backend` arg, e.g. `convert(req, "s2-pro")` |

Check warning on line 109 in .mintlify/skills/fish-audio-sdk/SKILL.md

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'arg'?

Check warning on line 109 in .mintlify/skills/fish-audio-sdk/SKILL.md

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'arg'?
| ASR model (header) | `RequestOptions(additional_headers=...)` | `convert(req, { headers: { model: "transcribe-1-pro" } })` |
| ASR model (header) | `RequestOptions(additional_headers=...)` | `convert({ audio, model: "transcribe-1-pro" })` |

## Decision shortcuts

Expand All @@ -119,7 +117,8 @@
- **Clone a voice instantly from a clip** → pass `references=[ReferenceAudio(audio=..., text=...)]` (Python) / `references: [{ audio, text }]` (JS). See [voice-cloning](references/voice-cloning.md).
- **Persistent custom voice to reuse** → create a voice model, then use its `id` as `reference_id`.
- **Stream tokens from an LLM and play speech as it arrives** → `tts.stream_websocket` (Python) / `textToSpeech.convertRealtime` (JS). See [websocket](references/websocket.md).
- **Transcribe audio** → `asr.transcribe` (Python) / `speechToText.convert` (JS) with the `model: transcribe-1-pro` header (recommended; without it, the request runs on `transcribe-1`). Pro request fields, `speaker_turns`, `request_id`, and the language fields need raw HTTP in Python (`fish-audio-sdk` 1.3.0). See [speech-to-text](references/speech-to-text.md).
- **Transcribe audio** → `asr.transcribe` (Python) / `speechToText.convert` (JS) with `transcribe-1-pro` selected (recommended; without it, the request runs on `transcribe-1`). Pro request fields, `speaker_turns`, `request_id`, and the language fields need raw HTTP in Python (`fish-audio-sdk` 1.3.0). See [speech-to-text](references/speech-to-text.md).
- **Transcribe live audio turn by turn** → `speechToText.convertRealtime` (JS, Node.js only); see the realtime section of the speech-to-text reference.

## Gotchas (verified against the SDK source)

Expand Down
22 changes: 16 additions & 6 deletions .mintlify/skills/fish-audio-sdk/references/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
| Exception | When | Attributes |
| --------------------- | ---------------------------------------------- | --------------------------------- |
| `APIError` | base for HTTP errors | `.status`, `.message`, `.body` |
| `AuthenticationError` | 401 (bad/missing key) | (APIError) |

Check warning on line 12 in .mintlify/skills/fish-audio-sdk/references/errors.md

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'APIError'?
| `PermissionError` | 403 | (APIError) |

Check warning on line 13 in .mintlify/skills/fish-audio-sdk/references/errors.md

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'APIError'?
| `NotFoundError` | 404 (voice id not found) | (APIError) |

Check warning on line 14 in .mintlify/skills/fish-audio-sdk/references/errors.md

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'APIError'?
| `RateLimitError` | 429 | (APIError) |

Check warning on line 15 in .mintlify/skills/fish-audio-sdk/references/errors.md

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'APIError'?
| `ServerError` | 5xx | (APIError) |

Check warning on line 16 in .mintlify/skills/fish-audio-sdk/references/errors.md

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'APIError'?
| `WebSocketError` | realtime stream failed | — |
| `DependencyError` | missing system tool (e.g. ffmpeg for `play()`) | `.dependency`, `.install_command` |

Check warning on line 18 in .mintlify/skills/fish-audio-sdk/references/errors.md

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'ffmpeg'?

```python
from fishaudio import FishAudio
Expand Down Expand Up @@ -88,15 +88,25 @@
}
```

What the JS client actually throws:
What the JS client actually throws for ordinary HTTP requests (`convert`, `voices.*`, `user.*`, ...):

| Error | When |
| ----------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| Error | When |
| ----------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| `UnprocessableEntityError` (extends `FishAudioError`) | 422, the **only** typed HTTP subclass thrown; `.body` is `{ detail: [{ loc, msg, type }] }` |
| `FishAudioError` | every other non-2xx response; read `.statusCode`, `.body`, `.rawResponse` |
| `FishAudioTimeoutError` | request exceeded the timeout |
| `FishAudioError` | every other non-2xx response; read `.statusCode`, `.body`, `.rawResponse` |
| `FishAudioTimeoutError` | request exceeded the timeout |

> The package also exports `BadRequestError`, `UnauthorizedError`, `ForbiddenError`, `NotFoundError`, and `TooEarlyError`, but the current client throws a generic `FishAudioError` for those statuses. **Branch on `err.statusCode`** rather than relying on `instanceof NotFoundError`.
> For HTTP requests, the package also exports `BadRequestError`, `UnauthorizedError`, `ForbiddenError`, `NotFoundError`, and `TooEarlyError`, but the client throws a generic `FishAudioError` for those statuses. **Branch on `err.statusCode`** rather than relying on `instanceof NotFoundError`.

Realtime speech-to-text (`speechToText.convertRealtime`) throws from the `for await` loop:

| Error | When |
| ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `BadRequestError` / `UnauthorizedError` / `ForbiddenError` / `NotFoundError` | the WebSocket handshake was refused with 400 / 401 / 403 / 404 (an invalid API key gives `UnauthorizedError`) |
| `FishAudioError` | the handshake was refused with any other status, such as 402 or 429; read `.statusCode` and `.body` |
| `RealtimeSTTError` (extends `FishAudioError`) | the session failed or the connection was lost; read `.errorType`, `.closeCode`, `.requestId`, and `.statusCode` when it is set |

All of these extend `FishAudioError`. `err.statusCode` is set when the handshake is refused. On a `RealtimeSTTError` it can be `undefined`: a lost connection has a `closeCode` but no HTTP status, so handle connection errors without relying on a status.

### Retries & timeouts (JavaScript)

Expand All @@ -116,7 +126,7 @@

## Inspecting raw responses (JS)

Every method returns an awaitable that also exposes the raw response:

Check warning on line 129 in .mintlify/skills/fish-audio-sdk/references/errors.md

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'awaitable'?

```ts
const { data, rawResponse } = await client.textToSpeech
Expand Down
4 changes: 3 additions & 1 deletion .mintlify/skills/fish-audio-sdk/references/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
# or: pnpm add fish-audio / yarn add fish-audio
```

- Requires Node.js 18+ (uses the global `fetch` / Web Streams).
- Requires Node.js 20+ (uses the global `fetch`, `File` and Web Streams).
- Ships ES module and CommonJS builds: `import { FishAudioClient } from "fish-audio"` and `const { FishAudioClient } = require("fish-audio")` both work (`require` needs `fish-audio` 0.2.0+).
- The WebSocket methods (`textToSpeech.convertRealtime`, `speechToText.convertRealtime`) are Node.js only.

## Authentication

Expand Down Expand Up @@ -61,9 +63,9 @@
The `play()` helper is for local/desktop use and shells out to a system tool:

- **Python:** needs `ffmpeg` (or pass `use_ffmpeg=False` to try `mpv`). Install the `[utils]` extra. Missing tools raise `DependencyError` with the install command.
- **JavaScript:** spawns `ffplay` (from ffmpeg) and is **Node-only**.

Check warning on line 66 in .mintlify/skills/fish-audio-sdk/references/installation.md

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'ffmpeg'?

Install ffmpeg:

Check warning on line 68 in .mintlify/skills/fish-audio-sdk/references/installation.md

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'ffmpeg'?

```bash
# macOS
Expand Down
Loading
Loading