Skip to content
Merged
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
29 changes: 21 additions & 8 deletions developer-guide/best-practices/real-time-streaming.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,16 @@ Install the Python SDK first: `pip install fish-audio-sdk`.

# Stream text word by word
def stream_text():
text = "Hello, this is being generated in real time"
text = "[warmly] Hello, this is being generated in real time."
for word in text.split():
yield word + " "

# Generate speech as text streams
audio_stream = client.tts.stream_websocket(
stream_text(),
reference_id="your_voice_model_id",
temperature=0.7, # Controls variation
top_p=0.7, # Controls diversity
latency="balanced"
model="s3-pro",
latency="balanced",
)

with open("output.mp3", "wb") as f:
Expand Down Expand Up @@ -165,14 +164,28 @@ Install the Python SDK first: `pip install fish-audio-sdk`.

### Voice Control

**Temperature** (0.1 - 1.0):
On `s3-pro` the service sets the sampling: `temperature` and `top_p` are accepted but don't change the audio. Steer the delivery with `[bracket]` directions in the text instead, as in the example above.

On older models, pass them in `TTSConfig`. `stream_websocket()` has no `temperature` or `top_p` argument of its own.

**Temperature** (0.0 - 1.0, default 0.7):
- Lower: More consistent, predictable
- Higher: More varied, expressive

**Top-p** (0.1 - 1.0):
**Top-p** (0.0 - 1.0, default 0.7):
- Lower: More focused
- Higher: More diverse

```python
from fishaudio.types import TTSConfig

audio_stream = client.tts.stream_websocket(
stream_text(),
model="s2.1-pro",
config=TTSConfig(temperature=0.5, top_p=0.7),
)
```

## Real-time Applications

### Chatbot Integration
Expand Down Expand Up @@ -446,14 +459,14 @@ Add emotions dynamically:
<Tab title="Python">
```python
def emotional_speech(text, emotion):
emotional_text = f"({emotion}) {text}"
emotional_text = f"[{emotion}] {text}"
stream_speech(emotional_text)
```
</Tab>
<Tab title="JavaScript">
```javascript
function emotionalSpeech(text, emotion) {
const emotionalText = `(${emotion}) ${text}`;
const emotionalText = `[${emotion}] ${text}`;
streamSpeech(emotionalText);
}
```
Expand Down
2 changes: 1 addition & 1 deletion developer-guide/integrations/livekit.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Fish Audio integrates with LiveKit through the `fishaudio` plugin, providing tex
## Prerequisites

- A [Fish Audio account](https://fish.audio) with an API key
- Python 3.9 or higher
- Python 3.10 or higher (`livekit-plugins-fishaudio` requires it)

## Installation

Expand Down
34 changes: 20 additions & 14 deletions developer-guide/integrations/pipecat.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Pipecat"

Check warning on line 2 in developer-guide/integrations/pipecat.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'Pipecat'?
description: "Build voice AI agents with Fish Audio and Pipecat"

Check warning on line 3 in developer-guide/integrations/pipecat.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'Pipecat'?
icon: "/images/pipecat-logo.svg"
---
import { AudioTranscript } from '/snippets/audio-transcript.jsx';
Expand All @@ -13,16 +13,16 @@

[Pipecat](https://github.com/pipecat-ai/pipecat) is an open source framework for building voice and multimodal conversational AI. It handles the orchestration of audio, AI services, and conversation pipelines so you can focus on what makes your agent unique.

Fish Audio integrates with Pipecat through `FishAudioTTSService`, which provides real-time text-to-speech synthesis using WebSocket streaming for low-latency conversational applications.

Check warning on line 16 in developer-guide/integrations/pipecat.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'Pipecat'?

## Prerequisites

- A [Fish Audio account](https://fish.audio) with an API key
- Python 3.9 or higher
- Python 3.11 or higher (current `pipecat-ai` releases require it)

## Installation

Install Pipecat with Fish Audio support:

Check warning on line 25 in developer-guide/integrations/pipecat.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'Pipecat'?

```bash
pip install "pipecat-ai[fish]"
Expand All @@ -38,41 +38,47 @@

## Basic usage

Add `FishAudioTTSService` to your Pipecat pipeline:

Check warning on line 41 in developer-guide/integrations/pipecat.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'Pipecat'?

```python
from pipecat.services.fish import FishAudioTTSService
import os

from pipecat.services.fish.tts import FishAudioTTSService

tts = FishAudioTTSService(
api_key=os.getenv("FISH_API_KEY"),
reference_id="your_voice_model_id", # Optional: use a specific voice
model_id="s2.1-pro",
params=FishAudioTTSService.InputParams(
latency="normal",
prosody_speed=1.0
)
settings=FishAudioTTSService.Settings(
model="s3-pro",
voice="your_voice_model_id", # Optional: use a specific voice
latency="balanced",
prosody_speed=1.0,
),
)
```

Pipecat sends `s2.1-pro` unless you set `model`, so set it to use S3 Pro.

Check warning on line 59 in developer-guide/integrations/pipecat.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'Pipecat'?

### Key parameters

| Parameter | Description |
|-----------|-------------|
| `api_key` | Your Fish Audio API key |
| `reference_id` | Voice model ID from the [Fish Audio library](https://fish.audio/discovery/) |
| `model_id` | TTS model version (default: `s2.1-pro`) |
| `output_format` | Audio format: `pcm`, `mp3`, `wav`, or `opus` |
| `settings.model` | TTS model, for example `s3-pro` (Pipecat's default is `s2.1-pro`) |

Check warning on line 66 in developer-guide/integrations/pipecat.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'Pipecat's'?
| `settings.voice` | Voice model ID from the [Fish Audio library](https://fish.audio/discovery/) (the API calls it `reference_id`) |
| `output_format` | Audio format: `pcm`, `mp3`, `wav`, or `opus` (default: `pcm`) |

Older Pipecat examples pass `reference_id`, `model_id` and `params=FishAudioTTSService.InputParams(...)`. These are deprecated since Pipecat 0.0.105 and will be removed in 2.0; `settings` replaces all three.

Check warning on line 70 in developer-guide/integrations/pipecat.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'Pipecat'?

Check warning on line 70 in developer-guide/integrations/pipecat.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'Pipecat'?

### Prosody controls

Customize speech characteristics with `InputParams`:
Customize speech characteristics with `Settings`:

```python
params=FishAudioTTSService.InputParams(
settings=FishAudioTTSService.Settings(
latency="balanced", # "normal" or "balanced"
prosody_speed=1.2, # 0.5 to 2.0
prosody_volume=0, # Volume adjustment in dB
normalize=True # Audio normalization
normalize=True, # Audio normalization
)
```

Expand Down
17 changes: 15 additions & 2 deletions developer-guide/sdk-guide/cookbook/realtime-llm-to-speech.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

<Prerequisites />

The synchronous recipe plays audio with `ffplay`, which comes with [FFmpeg](https://ffmpeg.org/download.html). Install FFmpeg so that `ffplay` is on your `PATH`.

Check warning on line 13 in developer-guide/sdk-guide/cookbook/realtime-llm-to-speech.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'FFmpeg'?

## Recipe

[`stream_websocket()`](/api-reference/sdk/python/resources#stream_websocket) takes an iterable of text chunks and yields audio chunks in real time. Feed it your LLM's token stream and play or forward the audio as it's produced.
Expand All @@ -18,8 +20,8 @@

<CodeGroup>
```python Synchronous
import subprocess
from fishaudio import FishAudio
from fishaudio.utils import play

client = FishAudio()

Expand All @@ -29,7 +31,16 @@
yield token

audio_stream = client.tts.stream_websocket(llm_tokens(), reference_id="<voice-id>", model="s3-pro")
play(audio_stream) # or: for chunk in audio_stream: send_to_client(chunk)

# One ffplay process (part of ffmpeg) plays the audio from a pipe as it arrives.
# Leaving the with block closes the pipe and waits for ffplay, even if the stream fails.
with subprocess.Popen(
["ffplay", "-nodisp", "-autoexit", "-loglevel", "error", "-i", "-"],
stdin=subprocess.PIPE,
) as player:
for chunk in audio_stream:
player.stdin.write(chunk) # or forward it: send_to_client(chunk)
player.stdin.flush()
```

```python Asynchronous
Expand All @@ -51,6 +62,8 @@
```
</CodeGroup>

`fishaudio.utils.play()` collects the whole stream before it starts playing, so it suits finished audio, not this recipe.

## Force generation at a boundary

By default the engine buffers text until it has enough for natural prosody. Yield a [`FlushEvent`](/api-reference/sdk/python/types#flushevent-objects) to force synthesis of what's buffered, useful for turn-taking in a conversation:
Expand Down
17 changes: 13 additions & 4 deletions features/text-to-speech/realtime.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@

## Stream from an LLM

When text arrives token by token, feed a generator to `stream_websocket`. It opens a WebSocket, sends text as you produce it, and yields audio chunks back, so speech keeps pace with your model.
When text arrives token by token, feed a generator to `stream_websocket`. It opens a WebSocket, sends text as you produce it, and yields audio chunks back, so speech keeps pace with your model. The Python example plays the reply with `ffplay`, which comes with [FFmpeg](https://ffmpeg.org/download.html); install FFmpeg so that `ffplay` is on your `PATH`.

Check warning on line 99 in features/text-to-speech/realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'FFmpeg'?

<CodeGroup>
```python Python
import subprocess
from fishaudio import FishAudio
from fishaudio.utils import play

client = FishAudio()

Expand All @@ -110,8 +110,15 @@
for token in ["The ", "first ", "move ", "sets ", "everything ", "in ", "motion."]:
yield token

for chunk in client.tts.stream_websocket(llm_tokens(), reference_id="YOUR_VOICE_ID"):
play(chunk) # play each chunk the moment it arrives
# One ffplay process (part of ffmpeg) plays the whole reply from a pipe.
# Leaving the with block closes the pipe and waits for ffplay, even if the stream fails.
with subprocess.Popen(
["ffplay", "-nodisp", "-autoexit", "-loglevel", "error", "-i", "-"],
stdin=subprocess.PIPE,
) as player:
for chunk in client.tts.stream_websocket(llm_tokens(), reference_id="YOUR_VOICE_ID"):
player.stdin.write(chunk) # play each chunk the moment it arrives
player.stdin.flush()
```

```bash API (WebSocket)
Expand All @@ -122,6 +129,8 @@
```
</CodeGroup>

`fishaudio.utils.play()` is not a streaming player: it collects every chunk it is given before it starts playing, and each call starts a new player. Calling it per chunk plays fragments one after another with a gap, and calling it on the stream waits for the last chunk.

## Implementation details

### Which mode to use
Expand Down
8 changes: 7 additions & 1 deletion tests/cookbooks/specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ def print(*args, **kwargs):
{
"name": "sync websocket + play",
"block": 0,
"subs": {"<voice-id>": PUBLIC_VOICE, "play(audio_stream)": "consume(audio_stream)"},
# Stand in for ffplay with a process that drains the pipe, and capture the streamed bytes.
"subs": {
"<voice-id>": PUBLIC_VOICE,
'["ffplay", "-nodisp", "-autoexit", "-loglevel", "error", "-i", "-"]':
'[__import__("sys").executable, "-c", "import sys; sys.stdin.buffer.read()"]',
"for chunk in audio_stream:": "for chunk in consume(audio_stream):",
},
"consumed": True,
},
{"name": "async websocket to file", "block": 1, "file": ("out.mp3", "mp3")},
Expand Down
2 changes: 2 additions & 0 deletions tests/cookbooks/test_cookbooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def test_cookbook_recipe(spec, case, shims, base_client, work_cwd):

code = blocks[case["block"]]["code"]
for old, new in case.get("subs", {}).items():
# A substitution that no longer matches would run the recipe unadapted; fail loudly instead.
assert old in code, f"{spec['slug']}: substitution {old!r} not found in block {case['block']}"
code = code.replace(old, new)

# Continuation snippets assume types imported by an earlier block on the page; provide them.
Expand Down
Loading