Skip to content
Open
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
12 changes: 6 additions & 6 deletions api-reference/sdk/python/client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
# Generate speech
audio = client.tts.convert(text="Hello world")
with open("output.mp3", "wb") as f:
for chunk in audio:
f.write(chunk)
f.write(audio)

# List voices
voices = client.voices.list(page_size=20)
Expand All @@ -37,7 +36,7 @@
#### \_\_init\_\_

```python
def __init__(*,

Check warning on line 39 in api-reference/sdk/python/client.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean '__init__'?
api_key: Optional[str] = None,
base_url: str = "https://api.fish.audio",
timeout: float = 240.0,
Expand All @@ -55,7 +54,7 @@

<a id="fishaudio.client.FishAudio.tts"></a>

#### tts

Check warning on line 57 in api-reference/sdk/python/client.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'tts'?

```python
@property
Expand All @@ -66,7 +65,7 @@

<a id="fishaudio.client.FishAudio.asr"></a>

#### asr

Check warning on line 68 in api-reference/sdk/python/client.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'asr'?

```python
@property
Expand Down Expand Up @@ -120,16 +119,17 @@
**Example**:

```python
import asyncio

from fishaudio import AsyncFishAudio

async def main():
client = AsyncFishAudio(api_key="your_api_key")

# Generate speech
audio = client.tts.convert(text="Hello world")
async with aiofiles.open("output.mp3", "wb") as f:
async for chunk in audio:
await f.write(chunk)
audio = await client.tts.convert(text="Hello world")
with open("output.mp3", "wb") as f:
f.write(audio)

# List voices
voices = await client.voices.list(page_size=20)
Expand Down Expand Up @@ -161,7 +161,7 @@

<a id="fishaudio.client.AsyncFishAudio.tts"></a>

#### tts

Check warning on line 164 in api-reference/sdk/python/client.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'tts'?

```python
@property
Expand All @@ -172,7 +172,7 @@

<a id="fishaudio.client.AsyncFishAudio.asr"></a>

#### asr

Check warning on line 175 in api-reference/sdk/python/client.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'asr'?

```python
@property
Expand Down
43 changes: 37 additions & 6 deletions api-reference/sdk/python/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[![PyPI version](https://img.shields.io/pypi/v/fish-audio-sdk.svg)](https://badge.fury.io/py/fish-audio-sdk)
[![Python Version](https://img.shields.io/badge/python-3.9+-blue)](https://pypi.org/project/fish-audio-sdk/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/fish-audio-sdk)](https://pypi.org/project/fish-audio-sdk/)
[![codecov](https://img.shields.io/codecov/c/github/fishaudio/fish-audio-python)](https://codecov.io/gh/fishaudio/fish-audio-python)

Check warning on line 17 in api-reference/sdk/python/overview.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'codecov'?
[![License](https://img.shields.io/github/license/fishaudio/fish-audio-python)](https://github.com/fishaudio/fish-audio-python/blob/main/LICENSE)

The official Python library for the Fish Audio API
Expand Down Expand Up @@ -88,7 +88,7 @@
asyncio.run(main())
```

**Playing the audio (optional):** `play` runs the `ffplay` program from [FFmpeg](https://ffmpeg.org/download.html), 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`.

Check warning on line 91 in api-reference/sdk/python/overview.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'FFmpeg'?

```python
from fishaudio.utils import play
Expand Down Expand Up @@ -150,6 +150,21 @@
)
```

**Language of the text:**

```python
# On s2.1-pro, "$300" is read as pesos with es-MX and as dólares with es.
# s3-pro, the default, normalizes a regional tag with its base language and
# reads this "$300" as pesos with es and es-MX alike.
audio = client.tts.convert(
text="La entrada cuesta $300.",
model="s2.1-pro",
language="es-MX",
)
```

`language` is a BCP-47 tag such as `en`, `es-MX` or `zh-CN`. Regional conventions (`es-MX` against `es`) apply on `s2.1-pro`, `s2-pro` and `s1`; `s3-pro` reads a regional tag as its base language. It only changes how numbers, dates, units and symbols are spelled out before synthesis (and word-timestamp alignment); it does not change the voice or accent. Without it, the API detects the language of each chunk, which is also the right choice for text that mixes languages. It is accepted by every text-to-speech method and by `TTSConfig`; on `stream_websocket` it applies to the whole session. See [supported normalization languages](https://docs.fish.audio/features/text-to-speech#supported-normalization-languages).

**Reusable configuration:**

```python
Expand Down Expand Up @@ -197,15 +212,16 @@

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](https://docs.fish.audio/developer-guide/models-pricing/deprecations).
`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. A transcription that names no model runs on the API's default model (`transcribe-1` until it is retired, `transcribe-2-pro` after) and emits a `FutureWarning`, shown as the deprecation warnings above are; pass a model (the `model` argument or a `model` header) to silence it. Write the model ID exactly, for example `transcribe-2-pro`: the API runs a name it does not know on its default model, and the SDK does not check names. A model that only an httpx request hook or auth flow adds is not seen, so such a request still gets the warning; if you also turn warnings into errors, pass `model` in the call. See [Model Deprecations](https://docs.fish.audio/developer-guide/models-pricing/deprecations).

Check warning on line 215 in api-reference/sdk/python/overview.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'asyncio's'?

Check warning on line 215 in api-reference/sdk/python/overview.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'httpx'?

[Learn more](https://docs.fish.audio/developer-guide/sdk-guide/python/text-to-speech)

### Speech-to-Text

```python
# transcribe-2-pro is the recommended model; without model, the request runs on transcribe-1,
# which is deprecated and will be retired on December 31, 2026 (then served by transcribe-2-pro).
# which is deprecated and will be retired on December 31, 2026 (then served by transcribe-2-pro),
# and emits a FutureWarning.
with open("meeting.wav", "rb") as f:
result = client.asr.transcribe(audio=f.read(), model="transcribe-2-pro")

Expand All @@ -222,8 +238,20 @@

# Language of the transcript, when the API returns it
print(result.language_code) # e.g. "en"

# Plain transcript on transcribe-2-pro: no speaker markers, no cues such as [laughter]
with open("meeting.wav", "rb") as f:
plain = client.asr.transcribe(
audio=f.read(),
model="transcribe-2-pro",
diarize=False,
tag_audio_events=False,
)
print(plain.text)
```

The Pro models also take `num_speakers`, `min_speakers` and `max_speakers` (speaker-count hints), and `transcribe-2-pro` takes `text_format="spoken"` (numbers in words), `verbatim=False` (asks the model to leave out fillers and false starts) and `keyterms=["Fish Audio", ...]` (terms to spell as listed). Options left as `None` are not sent; the API ignores those a model does not use.

[Learn more](https://docs.fish.audio/developer-guide/sdk-guide/python/speech-to-text)

**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:
Expand Down Expand Up @@ -361,7 +389,7 @@
)
```

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.

Check warning on line 392 in api-reference/sdk/python/overview.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'httpx's'?

```python
import httpx
Expand All @@ -383,9 +411,9 @@

```python
from fishaudio.exceptions import (
APIError,
AuthenticationError,
RateLimitError,
ValidationError,
FishAudioError,
)

Expand All @@ -395,12 +423,15 @@
print("Invalid API key")
except RateLimitError:
print("Rate limit exceeded")
except ValidationError as e:
print(f"Invalid request: {e}")
except APIError as e:
# Any other error response, such as 400 for a request the API rejects
print(f"API error {e.status}: {e.message}")
except FishAudioError as e:
print(f"API error: {e}")
print(f"Error: {e}")
```

A value the SDK can check before sending, such as a `speed` outside 0.5 to 2.0, raises pydantic's `ValidationError` instead, and no request is sent. `fishaudio.exceptions.ValidationError` is not raised by the SDK.

Check warning on line 433 in api-reference/sdk/python/overview.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'pydantic's'?

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.

```python
Expand Down
Loading
Loading