diff --git a/developer-guide/best-practices/real-time-streaming.mdx b/developer-guide/best-practices/real-time-streaming.mdx
index 9354dd69..d89897f2 100644
--- a/developer-guide/best-practices/real-time-streaming.mdx
+++ b/developer-guide/best-practices/real-time-streaming.mdx
@@ -54,7 +54,7 @@ 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 + " "
@@ -62,9 +62,8 @@ Install the Python SDK first: `pip install fish-audio-sdk`.
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:
@@ -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
@@ -446,14 +459,14 @@ Add emotions dynamically:
```python
def emotional_speech(text, emotion):
- emotional_text = f"({emotion}) {text}"
+ emotional_text = f"[{emotion}] {text}"
stream_speech(emotional_text)
```
```javascript
function emotionalSpeech(text, emotion) {
- const emotionalText = `(${emotion}) ${text}`;
+ const emotionalText = `[${emotion}] ${text}`;
streamSpeech(emotionalText);
}
```
diff --git a/developer-guide/integrations/livekit.mdx b/developer-guide/integrations/livekit.mdx
index 226ce70e..3ae5c2cd 100644
--- a/developer-guide/integrations/livekit.mdx
+++ b/developer-guide/integrations/livekit.mdx
@@ -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
diff --git a/developer-guide/integrations/pipecat.mdx b/developer-guide/integrations/pipecat.mdx
index 9b0a72ec..486175ef 100644
--- a/developer-guide/integrations/pipecat.mdx
+++ b/developer-guide/integrations/pipecat.mdx
@@ -18,7 +18,7 @@ Fish Audio integrates with Pipecat through `FishAudioTTSService`, which provides
## 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
@@ -41,38 +41,44 @@ export FISH_API_KEY=your_api_key_here
Add `FishAudioTTSService` to your Pipecat pipeline:
```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.
+
### 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`) |
+| `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.
### 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
)
```
diff --git a/developer-guide/sdk-guide/cookbook/realtime-llm-to-speech.mdx b/developer-guide/sdk-guide/cookbook/realtime-llm-to-speech.mdx
index bf37d23f..a5c2e806 100644
--- a/developer-guide/sdk-guide/cookbook/realtime-llm-to-speech.mdx
+++ b/developer-guide/sdk-guide/cookbook/realtime-llm-to-speech.mdx
@@ -10,6 +10,8 @@ import Prerequisites from "/snippets/prerequisites.mdx";
+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`.
+
## 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.
@@ -18,8 +20,8 @@ Install the Python SDK first: `pip install fish-audio-sdk`.
```python Synchronous
+import subprocess
from fishaudio import FishAudio
-from fishaudio.utils import play
client = FishAudio()
@@ -29,7 +31,16 @@ def llm_tokens():
yield token
audio_stream = client.tts.stream_websocket(llm_tokens(), reference_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
@@ -51,6 +62,8 @@ asyncio.run(main())
```
+`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:
diff --git a/features/text-to-speech/realtime.mdx b/features/text-to-speech/realtime.mdx
index 10201dfb..f30b1bfc 100644
--- a/features/text-to-speech/realtime.mdx
+++ b/features/text-to-speech/realtime.mdx
@@ -96,12 +96,12 @@ file.end();
## 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`.
```python Python
+import subprocess
from fishaudio import FishAudio
-from fishaudio.utils import play
client = FishAudio()
@@ -110,8 +110,15 @@ def llm_tokens():
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)
@@ -122,6 +129,8 @@ for chunk in client.tts.stream_websocket(llm_tokens(), reference_id="YOUR_VOICE_
```
+`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
diff --git a/tests/cookbooks/specs.py b/tests/cookbooks/specs.py
index 2007c248..6073e8ea 100644
--- a/tests/cookbooks/specs.py
+++ b/tests/cookbooks/specs.py
@@ -54,7 +54,13 @@ def print(*args, **kwargs):
{
"name": "sync websocket + play",
"block": 0,
- "subs": {"": 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": {
+ "": 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")},
diff --git a/tests/cookbooks/test_cookbooks.py b/tests/cookbooks/test_cookbooks.py
index c46b7065..95973971 100644
--- a/tests/cookbooks/test_cookbooks.py
+++ b/tests/cookbooks/test_cookbooks.py
@@ -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.