Skip to main content

fishaudio.resources.voices

Voice management namespace client. Install the Python SDK first: pip install fish-audio-sdk.

VoicesClient Objects

Synchronous voice management operations.

list

List available voices/models. Arguments:
  • page_size - Number of results per page
  • page_number - Page number (1-indexed)
  • title - Filter by title
  • tags - Filter by tags (single tag or list)
  • self_only - Only return user’s own voices
  • author_id - Filter by author ID
  • language - Filter by language(s)
  • title_language - Filter by title language(s)
  • sort_by - Sort field (“task_count” or “created_at”)
  • request_options - Request-level overrides
Returns: Paginated response with total count and voice items Example:

get

Get voice by ID. Arguments:
  • voice_id - Voice model ID
  • request_options - Request-level overrides
Returns: Voice model details Example:

create

Create/clone a new voice. Arguments:
  • title - Voice model name
  • voices - List of audio file bytes for training
  • description - Voice description
  • texts - Transcripts for voice samples
  • tags - Tags for categorization
  • cover_image - Cover image bytes
  • visibility - Visibility setting (public, unlist, private)
  • train_mode - Training mode (currently only “fast” supported)
  • enhance_audio_quality - Whether to enhance audio quality
  • request_options - Request-level overrides
Returns: Created voice model Example:

update

Update voice metadata. Arguments:
  • voice_id - Voice model ID
  • title - New title
  • description - New description
  • cover_image - New cover image bytes
  • visibility - New visibility setting
  • tags - New tags
  • request_options - Request-level overrides
Example:

delete

Delete a voice. Arguments:
  • voice_id - Voice model ID
  • request_options - Request-level overrides
Example:

AsyncVoicesClient Objects

Asynchronous voice management operations.

list

List available voices/models (async). See sync version for details.

get

Get voice by ID (async). See sync version for details.

create

Create/clone a new voice (async). See sync version for details.

update

Update voice metadata (async). See sync version for details.

delete

Delete a voice (async). See sync version for details.

fishaudio.resources.account

Account namespace client for billing and credits.

AccountClient Objects

Synchronous account operations.

get_credits

Get API credit balance. Arguments:
  • check_free_credit - Whether to check free credit availability
  • request_options - Request-level overrides
Returns: Credits information Example:

get_package

Get package information. Arguments:
  • request_options - Request-level overrides
Returns: Package information Example:

AsyncAccountClient Objects

Asynchronous account operations.

get_credits

Get API credit balance (async). Arguments:
  • check_free_credit - Whether to check free credit availability
  • request_options - Request-level overrides
Returns: Credits information Example:

get_package

Get package information (async). Arguments:
  • request_options - Request-level overrides
Returns: Package information Example:

fishaudio.resources.tts

TTS (Text-to-Speech) namespace client.

TTSClient Objects

Synchronous TTS operations.

stream

Stream text-to-speech audio chunks. Arguments:
  • text - Text to synthesize
  • reference_id - Voice reference ID (overrides config.reference_id if provided)
  • references - Reference audio samples (overrides config.references if provided)
  • format - Audio format - “mp3”, “wav”, “pcm”, or “opus” (overrides config.format if provided)
  • latency - Latency mode - “normal” or “balanced” (overrides config.latency if provided)
  • speed - Speech speed multiplier, e.g. 1.5 for 1.5x speed (overrides config.prosody.speed if provided)
  • config - TTS configuration (audio settings, voice, model parameters)
  • model - TTS model to use
  • request_options - Request-level overrides
Returns: AudioStream object that can be iterated for audio chunks Example:

convert

Convert text to speech and return complete audio as bytes. This is a convenience method that streams all audio chunks and combines them. For chunk-by-chunk processing, use stream() instead. Arguments:
  • text - Text to synthesize
  • reference_id - Voice reference ID (overrides config.reference_id if provided)
  • references - Reference audio samples (overrides config.references if provided)
  • format - Audio format - “mp3”, “wav”, “pcm”, or “opus” (overrides config.format if provided)
  • latency - Latency mode - “normal” or “balanced” (overrides config.latency if provided)
  • speed - Speech speed multiplier, e.g. 1.5 for 1.5x speed (overrides config.prosody.speed if provided)
  • config - TTS configuration (audio settings, voice, model parameters)
  • model - TTS model to use
  • request_options - Request-level overrides
Returns: Complete audio as bytes Example:

stream_with_timestamps

Stream text-to-speech audio together with word-level timestamps. Each event carries the next audio bytes and the newest timing snapshot. The returned stream keeps the timings up to date in stream.segments. Arguments:
  • text - Text to synthesize
  • reference_id - Voice reference ID (overrides config.reference_id if provided)
  • references - Reference audio samples (overrides config.references if provided)
  • format - Audio format - “mp3”, “wav”, “pcm”, or “opus” (overrides config.format if provided). “opus” is the best fit for playing audio while it streams; “wav” and “pcm” are uncompressed, which keeps sample positions exact.
  • latency - Latency mode - “normal” or “balanced” (overrides config.latency if provided)
  • speed - Speech speed multiplier, e.g. 1.5 for 1.5x speed (overrides config.prosody.speed if provided)
  • config - TTS configuration (audio settings, voice, model parameters)
  • model - TTS model to use
  • request_options - Request-level overrides
Returns: TTSTimestampStream that yields TTSTimestampEvent objects Example:

convert_with_timestamps

Convert text to speech and return the audio with word-level timestamps. This is a convenience method that reads the whole stream. To use audio and timings while they arrive, use stream_with_timestamps() instead. Arguments:
  • text - Text to synthesize
  • reference_id - Voice reference ID (overrides config.reference_id if provided)
  • references - Reference audio samples (overrides config.references if provided)
  • format - Audio format - “mp3”, “wav”, “pcm”, or “opus” (overrides config.format if provided). “opus” is the best fit for playing audio while it streams; “wav” and “pcm” are uncompressed, which keeps sample positions exact.
  • latency - Latency mode - “normal” or “balanced” (overrides config.latency if provided)
  • speed - Speech speed multiplier, e.g. 1.5 for 1.5x speed (overrides config.prosody.speed if provided)
  • config - TTS configuration (audio settings, voice, model parameters)
  • model - TTS model to use
  • request_options - Request-level overrides
Returns: TTSTimestampResult with the complete audio, the timing of each word in seconds from the start of the audio, and the audio duration. When the API has no timings for the text (for example text without words), segments is empty and duration is None. Example:

stream_websocket

Stream text and receive audio in real-time via WebSocket. Perfect for conversational AI, live captioning, and streaming applications. Arguments:
  • text_stream - Iterator of text chunks to stream
  • reference_id - Voice reference ID (overrides config.reference_id if provided)
  • references - Reference audio samples (overrides config.references if provided)
  • format - Audio format - “mp3”, “wav”, “pcm”, or “opus” (overrides config.format if provided)
  • latency - Latency mode - “normal” or “balanced” (overrides config.latency if provided)
  • speed - Speech speed multiplier, e.g. 1.5 for 1.5x speed (overrides config.prosody.speed if provided)
  • config - TTS configuration (audio settings, voice, model parameters)
  • model - TTS model to use
  • max_workers - ThreadPoolExecutor workers for concurrent sender
  • ws_options - WebSocket connection options for configuring timeouts, message size limits, etc. Useful for long-running generations that may exceed default timeout values. See WebSocketOptions class for available parameters.
Returns: Iterator of audio bytes Example:

AsyncTTSClient Objects

Asynchronous TTS operations.

stream

Stream text-to-speech audio chunks (async). Arguments:
  • text - Text to synthesize
  • reference_id - Voice reference ID (overrides config.reference_id if provided)
  • references - Reference audio samples (overrides config.references if provided)
  • format - Audio format - “mp3”, “wav”, “pcm”, or “opus” (overrides config.format if provided)
  • latency - Latency mode - “normal” or “balanced” (overrides config.latency if provided)
  • speed - Speech speed multiplier, e.g. 1.5 for 1.5x speed (overrides config.prosody.speed if provided)
  • config - TTS configuration (audio settings, voice, model parameters)
  • model - TTS model to use
  • request_options - Request-level overrides
Returns: AsyncAudioStream object that can be iterated for audio chunks Example:

convert

Convert text to speech and return complete audio as bytes (async). This is a convenience method that streams all audio chunks and combines them. For chunk-by-chunk processing, use stream() instead. Arguments:
  • text - Text to synthesize
  • reference_id - Voice reference ID (overrides config.reference_id if provided)
  • references - Reference audio samples (overrides config.references if provided)
  • format - Audio format - “mp3”, “wav”, “pcm”, or “opus” (overrides config.format if provided)
  • latency - Latency mode - “normal” or “balanced” (overrides config.latency if provided)
  • speed - Speech speed multiplier, e.g. 1.5 for 1.5x speed (overrides config.prosody.speed if provided)
  • config - TTS configuration (audio settings, voice, model parameters)
  • model - TTS model to use
  • request_options - Request-level overrides
Returns: Complete audio as bytes Example:

stream_with_timestamps

Stream text-to-speech audio together with word-level timestamps (async). Each event carries the next audio bytes and the newest timing snapshot. The returned stream keeps the timings up to date in stream.segments. Arguments:
  • text - Text to synthesize
  • reference_id - Voice reference ID (overrides config.reference_id if provided)
  • references - Reference audio samples (overrides config.references if provided)
  • format - Audio format - “mp3”, “wav”, “pcm”, or “opus” (overrides config.format if provided). “opus” is the best fit for playing audio while it streams; “wav” and “pcm” are uncompressed, which keeps sample positions exact.
  • latency - Latency mode - “normal” or “balanced” (overrides config.latency if provided)
  • speed - Speech speed multiplier, e.g. 1.5 for 1.5x speed (overrides config.prosody.speed if provided)
  • config - TTS configuration (audio settings, voice, model parameters)
  • model - TTS model to use
  • request_options - Request-level overrides
Returns: AsyncTTSTimestampStream that yields TTSTimestampEvent objects Example:

convert_with_timestamps

Convert text to speech and return the audio with word-level timestamps (async). This is a convenience method that reads the whole stream. To use audio and timings while they arrive, use stream_with_timestamps() instead. Arguments:
  • text - Text to synthesize
  • reference_id - Voice reference ID (overrides config.reference_id if provided)
  • references - Reference audio samples (overrides config.references if provided)
  • format - Audio format - “mp3”, “wav”, “pcm”, or “opus” (overrides config.format if provided). “opus” is the best fit for playing audio while it streams; “wav” and “pcm” are uncompressed, which keeps sample positions exact.
  • latency - Latency mode - “normal” or “balanced” (overrides config.latency if provided)
  • speed - Speech speed multiplier, e.g. 1.5 for 1.5x speed (overrides config.prosody.speed if provided)
  • config - TTS configuration (audio settings, voice, model parameters)
  • model - TTS model to use
  • request_options - Request-level overrides
Returns: TTSTimestampResult with the complete audio, the timing of each word in seconds from the start of the audio, and the audio duration. When the API has no timings for the text (for example text without words), segments is empty and duration is None. Example:

stream_websocket

Stream text and receive audio in real-time via WebSocket (async). Perfect for conversational AI, live captioning, and streaming applications. Arguments:
  • text_stream - Async iterator of text chunks to stream
  • reference_id - Voice reference ID (overrides config.reference_id if provided)
  • references - Reference audio samples (overrides config.references if provided)
  • format - Audio format - “mp3”, “wav”, “pcm”, or “opus” (overrides config.format if provided)
  • latency - Latency mode - “normal” or “balanced” (overrides config.latency if provided)
  • speed - Speech speed multiplier, e.g. 1.5 for 1.5x speed (overrides config.prosody.speed if provided)
  • config - TTS configuration (audio settings, voice, model parameters)
  • model - TTS model to use
  • ws_options - WebSocket connection options for configuring timeouts, message size limits, etc. Useful for long-running generations that may exceed default timeout values. See WebSocketOptions class for available parameters.
Returns: Async iterator of audio bytes Example:

fishaudio.resources.realtime

Real-time WebSocket streaming helpers.

iter_websocket_audio

Process WebSocket audio messages (sync). Receives messages from WebSocket, yields audio chunks, handles errors. Unknown events are ignored and iteration continues. Arguments:
  • ws - WebSocket connection from httpx_ws.connect_ws
Yields: Audio bytes Raises:
  • WebSocketError - On disconnect or error finish event

aiter_websocket_audio

Process WebSocket audio messages (async). Receives messages from WebSocket, yields audio chunks, handles errors. Unknown events are ignored and iteration continues. Arguments:
  • ws - WebSocket connection from httpx_ws.aconnect_ws
Yields: Audio bytes Raises:
  • WebSocketError - On disconnect or error finish event

fishaudio.resources.asr

ASR (Automatic Speech Recognition) namespace client.

ASRClient Objects

Synchronous ASR operations.

transcribe

Transcribe audio to text. Arguments:
  • audio - Audio file bytes
  • language - Language code (e.g., “en”, “zh”). Auto-detected if not provided.
  • include_timestamps - Whether to include timestamp information for segments (and speaker turns, on models that return them)
  • model - ASR model, e.g. “transcribe-1-pro” (recommended). Sent as the model header and takes precedence over one in request_options. If not provided and request_options sets no model header, the request runs on the API’s default model, transcribe-1
  • request_options - Request-level overrides
Returns: ASRResponse with transcription text, duration (in seconds), and segments, plus language, request ID and speaker turns when the API returns them Example:

stream_websocket

Stream audio and receive transcripts in real-time via WebSocket. Audio is divided into turns. Each turn ends with one committed event that holds its final transcript; with drafts=True you also get live draft events while the turn is open. The session ends with a session_done event once audio_stream is exhausted. By default the transcript text starts with a speaker tag, e.g. <|speaker:0|> Hello., and can contain sound tags such as [laughter]. Pass diarize=False for text without speaker tags; sound tags are turned off with config=ASRRealtimeConfig(results=ASRResults(tag_audio_events=False)). Arguments:
  • audio_stream - Iterator of raw audio chunks: 16-bit little-endian mono PCM, ideally 20-40 ms each, sent as you capture them. It can also yield control messages (e.g. ASRFinalizeEvent()), which are sent at that position in the audio
  • sample_rate - Sample rate of the audio in Hz: 8000, 12000, 16000, 22050, 24000, 32000, 44100 or 48000 (overrides config.sample_rate if provided)
  • turn_detection - When a turn ends - “auto” (the server judges that the user has finished), “vad” (after a fixed silence) or “manual” (when you send finalize) (overrides config.turn_detection.mode if provided)
  • eager - Send eager_end_of_turn events in auto mode (overrides config.turn_detection.eager if provided)
  • drafts - Send live draft events (overrides config.results.drafts if provided)
  • diarize - Speaker tags such as <|speaker:0|> in the transcript text. The server adds them by default; pass False for text without speaker tags (overrides config.results.diarize if provided)
  • terms - Names, products and jargon to recognize (overrides config.context.terms if provided)
  • config - Session configuration (audio, turn detection, results, context)
  • model - Realtime speech-to-text model
  • ws_options - WebSocket connection options for configuring timeouts, message size limits, etc. See WebSocketOptions class for available parameters.
Returns:
  • ASRRealtimeStream - an iterator of typed events (check event.type), with methods to send control messages during the session: finalize(), agent_speaking(), add_context() and configure()
Raises:
  • ASRRealtimeError - If the server reports an error that ends the session, or closes the connection abnormally (see error_type and close_code)
  • APIError - If the connection is refused (e.g. AuthenticationError for 401)
  • WebSocketError - If the connection is lost
Example:

AsyncASRClient Objects

Asynchronous ASR operations.

transcribe

Transcribe audio to text (async). Arguments:
  • audio - Audio file bytes
  • language - Language code (e.g., “en”, “zh”). Auto-detected if not provided.
  • include_timestamps - Whether to include timestamp information for segments (and speaker turns, on models that return them)
  • model - ASR model, e.g. “transcribe-1-pro” (recommended). Sent as the model header and takes precedence over one in request_options. If not provided and request_options sets no model header, the request runs on the API’s default model, transcribe-1
  • request_options - Request-level overrides
Returns: ASRResponse with transcription text, duration (in seconds), and segments, plus language, request ID and speaker turns when the API returns them Example:

stream_websocket

Stream audio and receive transcripts in real-time via WebSocket (async). Audio is divided into turns. Each turn ends with one committed event that holds its final transcript; with drafts=True you also get live draft events while the turn is open. The session ends with a session_done event once audio_stream is exhausted. By default the transcript text starts with a speaker tag, e.g. <|speaker:0|> Hello., and can contain sound tags such as [laughter]. Pass diarize=False for text without speaker tags; sound tags are turned off with config=ASRRealtimeConfig(results=ASRResults(tag_audio_events=False)). Arguments:
  • audio_stream - Async iterator of raw audio chunks: 16-bit little-endian mono PCM, ideally 20-40 ms each, sent as you capture them. It can also yield control messages (e.g. ASRFinalizeEvent()), which are sent at that position in the audio
  • sample_rate - Sample rate of the audio in Hz: 8000, 12000, 16000, 22050, 24000, 32000, 44100 or 48000 (overrides config.sample_rate if provided)
  • turn_detection - When a turn ends - “auto” (the server judges that the user has finished), “vad” (after a fixed silence) or “manual” (when you send finalize) (overrides config.turn_detection.mode if provided)
  • eager - Send eager_end_of_turn events in auto mode (overrides config.turn_detection.eager if provided)
  • drafts - Send live draft events (overrides config.results.drafts if provided)
  • diarize - Speaker tags such as <|speaker:0|> in the transcript text. The server adds them by default; pass False for text without speaker tags (overrides config.results.diarize if provided)
  • terms - Names, products and jargon to recognize (overrides config.context.terms if provided)
  • config - Session configuration (audio, turn detection, results, context)
  • model - Realtime speech-to-text model
  • ws_options - WebSocket connection options for configuring timeouts, message size limits, etc. See WebSocketOptions class for available parameters.
Returns:
  • AsyncASRRealtimeStream - an async iterator of typed events (check event.type), with methods to send control messages during the session: finalize(), agent_speaking(), add_context() and configure()
Raises:
  • ASRRealtimeError - If the server reports an error that ends the session, or closes the connection abnormally (see error_type and close_code)
  • APIError - If the connection is refused (e.g. AuthenticationError for 401)
  • WebSocketError - If the connection is lost
Example:

fishaudio.resources.asr_realtime

Realtime speech-to-text sessions over WebSocket.

encode_config

Pack the config message that opens a session.

encode_message

Pack an audio chunk or a control message for the wire.

decode_event

Parse a server message. Returns None for message types this SDK does not know.

ASRRealtimeStream Objects

A realtime speech-to-text session (sync). Iterate it for the server’s events. The connection opens on the first iteration and closes when the session ends, when an error is raised, or when you leave the loop early. Use it as a context manager (or call close()) if you keep a reference to it after leaving the loop. The audio stream is read on a background thread. When the session ends before the audio does, that thread stops as soon as the audio stream yields its next chunk, and closes the stream if it is a generator. The SDK cannot interrupt an audio stream that is blocked waiting for audio (for example a microphone read with no timeout): make your audio source end, or yield regularly, so the thread can exit. Closing does not wait for a server that has stopped reading: a write that is still pending after half a second is interrupted by cutting the connection, without a close frame. Read the events from one thread at a time. The control methods send a message at the current position in the audio stream; they can be called from any thread once session_started has been received.

close

Close the connection. Safe to call more than once.

send

Send a control message. Raises:
  • WebSocketError - If the session is not open (not started yet, or closed)

finalize

Commit the current turn now (push-to-talk: the button was released).

agent_speaking

Tell the server that your voice agent started or stopped speaking.

add_context

Add conversation context, typically each line your agent speaks.

configure

Change settings during the session. The server answers with a configured event.

keepalive

Keep an idle session open. Rarely needed: WebSocket pings count as activity.

AsyncASRRealtimeStream Objects

A realtime speech-to-text session (async). Iterate it with async for for the server’s events. The connection opens on the first iteration and closes when the session ends, when an error is raised, or when you leave the loop early. Use it as an async context manager (or call aclose()) if you keep a reference to it after leaving the loop. Closing cancels the task that reads the audio stream and closes the stream if it is an async generator. Up to 256 events are buffered for a consumer that reads slowly; beyond that the session stops reading from the server until the consumer catches up. Read the events from one task at a time: a read started while another is waiting raises RuntimeError. A read that was cancelled (for example by asyncio.wait_for) loses nothing; just read again. The control methods send a message at the current position in the audio stream; they can be awaited once session_started has been received. Keep reading: when you stop, the SDK buffers a few hundred events and then stops reading from the connection, which also stops it answering keepalive pings. A consumer that stays stalled past the keepalive timeout (20 s by default, see ws_options) while events keep arriving loses the connection.

aclose

Close the connection. Safe to call more than once.

send

Send a control message. Raises:
  • WebSocketError - If the session is not open (not started yet, or closed)

finalize

Commit the current turn now (push-to-talk: the button was released).

agent_speaking

Tell the server that your voice agent started or stopped speaking.

add_context

Add conversation context, typically each line your agent speaks.

configure

Change settings during the session. The server answers with a configured event.

keepalive

Keep an idle session open. Rarely needed: WebSocket pings count as activity.