From b7aa184b92d0e1571012cd99ac4d033c25ee6e5d Mon Sep 17 00:00:00 2001 From: Felix Lu <58391009+lumpinif@users.noreply.github.com> Date: Wed, 2 Dec 2026 10:29:37 -0800 Subject: [PATCH 1/4] docs(integrations): fix the Pipecat import and Python floors The Pipecat guide imported FishAudioTTSService from pipecat.services.fish, which is empty in current pipecat-ai (1.17.0), and used os without importing it. Import from pipecat.services.fish.tts, add import os, use the Settings form (reference_id, model_id and params are deprecated since 0.0.105), and set model to s3-pro since Pipecat defaults to s2.1-pro. pipecat-ai requires Python 3.11 and livekit-plugins-fishaudio 3.10; on older Pythons pip resolves to releases without the import or the plugin. --- developer-guide/integrations/livekit.mdx | 2 +- developer-guide/integrations/pipecat.mdx | 34 ++++++++++++++---------- 2 files changed, 21 insertions(+), 15 deletions(-) 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 ) ``` From 0d8df9f033728154fdb9278a0d157c469246fccc Mon Sep 17 00:00:00 2001 From: Felix Lu <58391009+lumpinif@users.noreply.github.com> Date: Wed, 2 Dec 2026 10:30:45 -0800 Subject: [PATCH 2/4] docs(best-practices): make the real-time Python sample run on the current SDK stream_websocket() has no temperature or top_p argument, so the first sample raised TypeError on copy. Drop them, set model="s3-pro", and steer delivery with a [bracket] cue instead. The Voice Control section now says that s3-pro ignores the sampling knobs and shows TTSConfig for older models. Emotion injection uses [brackets], which S2 and S3 Pro read; the (parentheses) form was S1's. --- .../best-practices/real-time-streaming.mdx | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) 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); } ``` From 916b1d087b38041786f365f1c325e46ffda2b114 Mon Sep 17 00:00:00 2001 From: Felix Lu <58391009+lumpinif@users.noreply.github.com> Date: Wed, 2 Dec 2026 10:32:53 -0800 Subject: [PATCH 3/4] docs(realtime): stream playback through one player instead of play() fishaudio.utils.play() joins everything it is given and starts a new ffplay per call. The realtime guide called it per chunk (a separate player per fragment, with gaps) and the LLM-to-speech recipe called it on the whole stream (no sound until the last chunk). Both now feed one ffplay process through a pipe, and say what play() does. --- .../cookbook/realtime-llm-to-speech.mdx | 16 ++++++++++++++-- features/text-to-speech/realtime.mdx | 14 ++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) 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..c6d36833 100644 --- a/developer-guide/sdk-guide/cookbook/realtime-llm-to-speech.mdx +++ b/developer-guide/sdk-guide/cookbook/realtime-llm-to-speech.mdx @@ -18,8 +18,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 +29,17 @@ 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 +player = subprocess.Popen( + ["ffplay", "-nodisp", "-autoexit", "-loglevel", "error", "-i", "-"], + stdin=subprocess.PIPE, +) +for chunk in audio_stream: + player.stdin.write(chunk) # or forward it: send_to_client(chunk) + player.stdin.flush() +player.stdin.close() +player.wait() ``` ```python Asynchronous @@ -51,6 +61,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..6660fb03 100644 --- a/features/text-to-speech/realtime.mdx +++ b/features/text-to-speech/realtime.mdx @@ -100,8 +100,8 @@ When text arrives token by token, feed a generator to `stream_websocket`. It ope ```python Python +import subprocess from fishaudio import FishAudio -from fishaudio.utils import play client = FishAudio() @@ -110,8 +110,16 @@ def llm_tokens(): for token in ["The ", "first ", "move ", "sets ", "everything ", "in ", "motion."]: yield token +# One ffplay process (part of ffmpeg) plays the whole reply from a pipe +player = subprocess.Popen( + ["ffplay", "-nodisp", "-autoexit", "-loglevel", "error", "-i", "-"], + stdin=subprocess.PIPE, +) for chunk in client.tts.stream_websocket(llm_tokens(), reference_id="YOUR_VOICE_ID"): - play(chunk) # play each chunk the moment it arrives + player.stdin.write(chunk) # play each chunk the moment it arrives + player.stdin.flush() +player.stdin.close() +player.wait() ``` ```bash API (WebSocket) @@ -122,6 +130,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 From fb50b5d4b99fb3408a5feecea86ccfe1a74a4d3e Mon Sep 17 00:00:00 2001 From: Felix Lu <58391009+lumpinif@users.noreply.github.com> Date: Wed, 2 Dec 2026 17:46:19 -0800 Subject: [PATCH 4/4] docs(realtime): reap the player on stream errors, state the ffplay prerequisite, adapt the cookbook test --- .../cookbook/realtime-llm-to-speech.mdx | 17 +++++++++-------- features/text-to-speech/realtime.mdx | 17 ++++++++--------- tests/cookbooks/specs.py | 8 +++++++- tests/cookbooks/test_cookbooks.py | 2 ++ 4 files changed, 26 insertions(+), 18 deletions(-) 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 c6d36833..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. @@ -30,16 +32,15 @@ def llm_tokens(): audio_stream = client.tts.stream_websocket(llm_tokens(), reference_id="", model="s3-pro") -# One ffplay process (part of ffmpeg) plays the audio from a pipe as it arrives -player = subprocess.Popen( +# 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, -) -for chunk in audio_stream: - player.stdin.write(chunk) # or forward it: send_to_client(chunk) - player.stdin.flush() -player.stdin.close() -player.wait() +) as player: + for chunk in audio_stream: + player.stdin.write(chunk) # or forward it: send_to_client(chunk) + player.stdin.flush() ``` ```python Asynchronous diff --git a/features/text-to-speech/realtime.mdx b/features/text-to-speech/realtime.mdx index 6660fb03..f30b1bfc 100644 --- a/features/text-to-speech/realtime.mdx +++ b/features/text-to-speech/realtime.mdx @@ -96,7 +96,7 @@ 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 @@ -110,16 +110,15 @@ def llm_tokens(): for token in ["The ", "first ", "move ", "sets ", "everything ", "in ", "motion."]: yield token -# One ffplay process (part of ffmpeg) plays the whole reply from a pipe -player = subprocess.Popen( +# 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, -) -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() -player.stdin.close() -player.wait() +) 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) 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.