Skip to main content
Fish Audio Python SDK

Fish Audio Python SDK

PyPI version Python Version PyPI - Downloads codecov License The official Python library for the Fish Audio API Documentation: Python SDK Guide | API Reference
[!IMPORTANT]

Changes to PyPI Versioning

For existing users on Fish Audio Python SDK, please note that the starting version is now 1.0.0. The last version before this was 2025.6.3. You may need to adjust your version constraints accordingly. The original API in the fish_audio_sdk package has NOT been removed, but you will not receive any updates if you continue using the old versioning scheme. The simplest fix is to update your dependency to fish-audio-sdk>=1.0.0 to continue receiving updates, or by pinning to a specific version like fish-audio-sdk==1.0.0 when installing via your package manager. There are no changes to the API itself in this transition. If you’re using the legacy fish_audio_sdk and would like to switch to the newer, more robust fishaudio package, see the migration guide to upgrade.

Installation

Authentication

Get your API key from fish.audio/app/api-keys:
Or provide directly:

Quick Start

Synchronous:
Asynchronous:
Playing the audio (optional): play runs the ffplay program from FFmpeg, which must be on your PATH; without it, play raises DependencyError. To play without FFmpeg, install the [utils] extra (on Linux, sounddevice also needs the PortAudio library, such as libportaudio2) and pass use_ffmpeg=False.

Core Features

Text-to-Speech

Selecting a model:
With custom voice:
With speed control:
Reusable configuration:
Chunk-by-chunk processing:
Word-level timestamps:
Text without words (only punctuation, or a sound tag such as [sigh]) still produces audio, but the API has no timings for it: segments is then empty and result.duration is None. s1 and transcribe-1 are deprecated and will be retired on December 31, 2026. After that date, requests that specify them are served by s3-pro and transcribe-2-pro. Using a deprecated model emits a FutureWarning; with Python’s default warning filters it is shown once per calling line. A coroutine scheduled with asyncio.create_task or gather runs from asyncio’s code, so its warning points there and is shown once in all. See Model Deprecations. Learn more

Speech-to-Text

Learn more Realtime (Preview): stream live audio to transcribe-stream-1 and get the transcript turn by turn. Send 16-bit mono PCM in 20–40 ms chunks as you capture it:
With AsyncFishAudio, pass an async iterator and use async for. The returned stream also sends control messages during the session, such as stream.finalize() for push-to-talk and stream.agent_speaking(True) for voice agents. Learn more

Real-time Streaming

Stream dynamically generated text for conversational AI and live applications: Synchronous:
Asynchronous:
Learn more

Voice Cloning

Instant cloning:
Persistent voice models:
Learn more

Resource Clients

Tracing

To continue your trace in the Fish Audio API, send a W3C traceparent header on each request. Use one of the ways below. A traceparent that the OpenTelemetry instrumentation sends replaces one you set yourself. With OpenTelemetry, configure a tracer provider and enable opentelemetry-instrumentation-httpx. HTTP calls and the WebSocket handshakes of tts.stream_websocket() and asr.stream_websocket() then carry the current trace: the same trace id, under a client span that the instrumentation creates. A WebSocket stream connects when you first iterate it, so iterate it inside your span.
Without OpenTelemetry, pass the header with each call:
Or give the client an httpx_client with a request event hook, which runs for HTTP calls and WebSocket handshakes alike (with AsyncFishAudio, use an httpx.AsyncClient and an async hook). A client you pass in keeps its own settings, so set its timeout: httpx’s default is 5 seconds.

Error Handling

Every APIError carries the headers of the error response. When you contact support, include the trace id and the error code. Either can be absent.
A tts.stream_websocket handshake that the server refuses raises httpx_ws.WebSocketUpgradeError; read the same headers from e.response.headers.

Trace IDs

Responses to speech and transcription requests carry an x-fish-trace-id header. Include it when you contact support about a request, also one that succeeded but sounds wrong. The stream that tts.stream() returns has the response headers:
The same headers attribute is on the streams of tts.stream_with_timestamps() and asr.stream_websocket() (empty until the connection opens on the first iteration), and on the results of tts.convert_with_timestamps() and asr.transcribe() (the latter also has request_id). tts.convert() returns only the audio; use tts.stream() as above when you need the headers. tts.stream_websocket() does not expose them yet.

Resources

License

This project is licensed under the Apache-2.0 License - see the LICENSE file for details.