Skip to main content

fishaudio.core.client_wrapper

HTTP client wrapper for managing requests and authentication. Install the Python SDK first: pip install fish-audio-sdk.

BaseClientWrapper Objects

Base wrapper with shared logic for sync/async clients.

get_headers

Build headers including authentication and user agent.

ClientWrapper Objects

Wrapper for httpx.Client that handles authentication and error handling.

request

Make an HTTP request with error handling. Arguments:
  • method - HTTP method (GET, POST, etc.)
  • path - API endpoint path
  • request_options - Optional request-level overrides
  • stream - If True, return as soon as the response headers arrive and leave the body unread. The caller must consume it with iter_bytes() and then call close() on the response.
  • **kwargs - Additional arguments to pass to httpx.request
Returns: httpx.Response object Raises:
  • APIError - On non-2xx responses

client

Get underlying httpx.Client for advanced usage (e.g., WebSockets).

close

Close the HTTP client.

AsyncClientWrapper Objects

Wrapper for httpx.AsyncClient that handles authentication and error handling.

request

Make an async HTTP request with error handling. Arguments:
  • method - HTTP method (GET, POST, etc.)
  • path - API endpoint path
  • request_options - Optional request-level overrides
  • stream - If True, return as soon as the response headers arrive and leave the body unread. The caller must consume it with aiter_bytes() and then call aclose() on the response.
  • **kwargs - Additional arguments to pass to httpx.request
Returns: httpx.Response object Raises:
  • APIError - On non-2xx responses

client

Get underlying httpx.AsyncClient for advanced usage (e.g., WebSockets).

close

Close the HTTP client.

fishaudio.core.request_options

Request-level options for API calls.

RequestOptions Objects

Options that can be provided on a per-request basis to override client defaults. Attributes:
  • timeout - Override the client’s default timeout (in seconds)
  • max_retries - Accepted but not used: the client does not retry requests
  • additional_headers - Additional headers to include in the request
  • additional_query_params - Additional query parameters to include

get_timeout

Convert timeout to httpx.Timeout if set.

fishaudio.core.iterators

Audio stream wrappers with collection utilities.

AudioStream Objects

Wrapper for sync audio byte streams with collection utilities. This class wraps an iterator of audio bytes and provides a convenient .collect() method to gather all chunks into a single bytes object. Examples:

__init__

Initialize the audio iterator wrapper. Arguments:
  • iterator - The underlying iterator of audio bytes
  • on_close - Called by close() to release the underlying resource, for example the open HTTP response

__iter__

Allow direct iteration over audio chunks.

close

Stop the stream and release the underlying connection. Safe to call more than once, and before iteration has started.

collect

Collect all audio chunks into a single bytes object. This consumes the iterator and returns all audio data as bytes. After calling this method, the iterator cannot be used again. Returns: Complete audio data as bytes Examples:

AsyncAudioStream Objects

Wrapper for async audio byte streams with collection utilities. This class wraps an async iterator of audio bytes and provides a convenient .collect() method to gather all chunks into a single bytes object. Examples:

__init__

Initialize the async audio iterator wrapper. Arguments:
  • async_iterator - The underlying async iterator of audio bytes
  • on_close - Awaited by aclose() to release the underlying resource, for example the open HTTP response

__aiter__

Allow direct async iteration over audio chunks.

aclose

Stop the stream and release the underlying connection. Safe to call more than once, and before iteration has started.

collect

Collect all audio chunks into a single bytes object. This consumes the async iterator and returns all audio data as bytes. After calling this method, the iterator cannot be used again. Returns: Complete audio data as bytes Examples:

TTSTimestampStream Objects

Sync stream of text-to-speech audio with timestamps. Iterating yields TTSTimestampEvent objects as the server produces them. While you iterate, segments holds the timings received so far, measured from the start of the complete audio. Alternatively, call collect() instead of iterating to get the complete audio with its final timings. Examples:

__init__

Initialize the stream. Arguments:
  • iterator - The underlying iterator of events
  • on_close - Called by close() to release the underlying resource, for example the open HTTP response

segments

Timings received so far, in speaking order. Times are in seconds from the start of the complete audio. Entries near the end can still be corrected by later events, so read this again after each event instead of appending to an earlier copy. Empty until the first timings arrive, and it stays empty when the API has no timings for the text (for example text without words). The audio still arrives in full.

close

Stop the stream and release the underlying connection. Safe to call more than once, and before iteration has started.

collect

Read the whole stream and return the complete audio with its timings. Call this instead of iterating, not after it. Events that were already yielded are not kept, so the complete audio can no longer be returned once iteration has started; in that case use the audio you received and read segments when the stream ends. Returns: TTSTimestampResult with the complete audio and final timings. When the API has no timings for the text, segments is empty and duration is None; the audio is still complete. Raises:
  • RuntimeError - If iteration has already started

AsyncTTSTimestampStream Objects

Async stream of text-to-speech audio with timestamps. Iterating yields TTSTimestampEvent objects as the server produces them. While you iterate, segments holds the timings received so far, measured from the start of the complete audio. Alternatively, call collect() instead of iterating to get the complete audio with its final timings. Examples:

__init__

Initialize the stream. Arguments:
  • async_iterator - The underlying async iterator of events
  • on_close - Awaited by aclose() to release the underlying resource, for example the open HTTP response

segments

Timings received so far, in speaking order. Times are in seconds from the start of the complete audio. Entries near the end can still be corrected by later events, so read this again after each event instead of appending to an earlier copy. Empty until the first timings arrive, and it stays empty when the API has no timings for the text (for example text without words). The audio still arrives in full.

aclose

Stop the stream and release the underlying connection. Safe to call more than once, and before iteration has started.

collect

Read the whole stream and return the complete audio with its timings. Call this instead of iterating, not after it. Events that were already yielded are not kept, so the complete audio can no longer be returned once iteration has started; in that case use the audio you received and read segments when the stream ends. Returns: TTSTimestampResult with the complete audio and final timings. When the API has no timings for the text, segments is empty and duration is None; the audio is still complete. Raises:
  • RuntimeError - If iteration has already started

fishaudio.core.websocket_options

WebSocket-level options for WebSocket connections.

WebSocketOptions Objects

Options for configuring WebSocket connections. These options are passed directly to httpx_ws’s connect_ws/aconnect_ws functions. For complete documentation, see https://frankie567.github.io/httpx-ws/reference/httpx_ws/ Attributes:
  • keepalive_ping_timeout_seconds - Maximum delay the client will wait for an answer to its Ping event. If the delay is exceeded, WebSocketNetworkError will be raised and the connection closed. Default: 20 seconds.
  • keepalive_ping_interval_seconds - Interval at which the client will automatically send a Ping event to keep the connection alive. Default: 20 seconds. None keeps the default; it does not turn the pings off.
  • max_message_size_bytes - Message size in bytes to receive from the server. Default: 65536 bytes (64 KiB).
  • queue_size - Size of the queue where received messages will be held until they are consumed. If the queue is full, the client will stop receiving messages from the server until the queue has room available. Default: 512.
Notes: Parameter descriptions adapted from httpx_ws documentation.

to_httpx_ws_kwargs

Convert to kwargs dict for httpx_ws aconnect_ws/connect_ws.

fishaudio.core.omit

OMIT sentinel for distinguishing None from not-provided parameters.