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.
from fishaudio import FishAudio
client = FishAudio(api_key="your_api_key")
Quick Start
Synchronous:
from fishaudio import FishAudio
from fishaudio.utils import play, save
client = FishAudio()
# Generate audio
audio = client.tts.convert(text="Hello, world!")
# Play or save
play(audio)
save(audio, "output.mp3")
Asynchronous:
import asyncio
from fishaudio import AsyncFishAudio
from fishaudio.utils import play, save
async def main():
client = AsyncFishAudio()
audio = await client.tts.convert(text="Hello, world!")
play(audio)
save(audio, "output.mp3")
asyncio.run(main())
Core Features
Text-to-Speech
Selecting a model:
# Recommended for production
production_audio = client.tts.convert(
text="Production speech",
model="s2.1-pro",
)
# Free to use, including on a new account with no API credit
free_audio = client.tts.convert(
text="Free speech",
model="s2.1-pro-free",
)
# Drama 3: our most expressive model (uses API credit)
drama_audio = client.tts.convert(
text="Expressive speech",
model="drama-3",
)
With custom voice:
# Use a specific voice by ID
audio = client.tts.convert(
text="Custom voice",
reference_id="802e3bc2b27e49c2995d23ef70e6ac89"
)
# Stream and process chunks as they arrive
for chunk in client.tts.stream(text="Long content..."):
send_to_websocket(chunk)
# Or collect all chunks
audio = client.tts.stream(text="Hello!").collect()
Word-level timestamps:
# Audio plus the start and end time of every word, for captions, highlighting or lip-sync
result = client.tts.convert_with_timestamps(text="Hello! Welcome to Fish Audio.")
save(result.audio, "output.mp3")
for segment in result.segments:
print(f"{segment.start:.2f}s - {segment.end:.2f}s {segment.text}")
# Or use audio and timings while they arrive
with client.tts.stream_with_timestamps(text="Long content...", format="opus") as stream:
for event in stream:
send_to_player(event.audio)
update_captions(stream.segments) # timings so far, in seconds from the start
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.
# transcribe-1-pro is the recommended model; without model, the request runs on transcribe-1.
with open("meeting.wav", "rb") as f:
result = client.asr.transcribe(audio=f.read(), model="transcribe-1-pro")
# On transcribe-1-pro, text keeps <|speaker:N|> markers; speaker_turns has clean text per speaker.
print(result.text)
# Word-level timestamps
for segment in result.segments:
print(f"[{segment.start:.2f}s - {segment.end:.2f}s] {segment.text}")
# Speaker turns (transcribe-1-pro, returned with timestamps)
for turn in result.speaker_turns or []:
print(f"[{turn.start:.2f}s - {turn.end:.2f}s] {turn.speaker}: {turn.text}")
# Language of the transcript, when the API returns it
print(result.language_code) # e.g. "en"
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:
import wave
def audio_chunks():
with wave.open("speech.wav", "rb") as wav: # 16-bit mono PCM, 16 kHz
while chunk := wav.readframes(640): # 40 ms
yield chunk
# diarize=False gives plain text; by default it starts with a speaker tag: "<|speaker:0|> Hello."
for event in client.asr.stream_websocket(
audio_chunks(), sample_rate=16000, drafts=True, diarize=False
):
if event.type == "draft": # live text of the open turn, not final
print("...", event.text)
elif event.type == "committed": # final transcript of the turn
print(event.text)
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.
from fishaudio.types import ReferenceAudio
# Clone voice on-the-fly
with open("reference.wav", "rb") as f:
audio = client.tts.convert(
text="Cloned voice speaking",
references=[ReferenceAudio(
audio=f.read(),
text="Text spoken in reference"
)]
)
Persistent voice models:
# Create voice model for reuse
with open("voice_sample.wav", "rb") as f:
voice = client.voices.create(
title="My Voice",
voices=[f.read()],
description="Custom voice clone"
)
# Use the created model
audio = client.tts.convert(
text="Using my saved voice",
reference_id=voice.id
)
Text to Speech (TTS) library for Python 3. Works without internet connection or delay. Supports multiple TTS engines, including Sapi5, nsss, and espeak.