From 4d54f09b4e1acc7d2b3168826c34d5c36d95296b Mon Sep 17 00:00:00 2001 From: Felix Lu <58391009+lumpinif@users.noreply.github.com> Date: Wed, 2 Dec 2026 10:56:34 -0800 Subject: [PATCH 1/2] fix(tts): accept latency "low" The API accepts latency "low" (OpenAPI enum: low, normal, balanced), and the TypeScript SDK already offers it, but LatencyMode only allowed "normal" and "balanced", so TTSConfig and TTSRequest rejected it. What the docstrings say about "low" follows the S3 Pro model card and a live check on 2026-12-02 (median time to first audio bytes, 8 runs): s3-pro 0.26 s with low vs 0.29 s with balanced; s3-pro-free accepts it without a speed-up (the model card: not available there); s2.1-pro showed no speed-up either. --- src/fishaudio/resources/tts.py | 20 ++++++++++---------- src/fishaudio/types/shared.py | 6 ++++-- src/fishaudio/types/tts.py | 4 +++- tests/unit/test_tts.py | 15 +++++++++++++++ tests/unit/test_types.py | 20 ++++++++++++++++++++ 5 files changed, 52 insertions(+), 13 deletions(-) diff --git a/src/fishaudio/resources/tts.py b/src/fishaudio/resources/tts.py index 3e56c70..2926b7a 100644 --- a/src/fishaudio/resources/tts.py +++ b/src/fishaudio/resources/tts.py @@ -179,7 +179,7 @@ def stream( reference_id: Voice reference ID (overrides config.reference_id if provided) references: Reference audio samples (overrides config.references if provided) format: Audio format - "mp3", "wav", "pcm", or "opus" (overrides config.format if provided) - latency: Latency mode - "normal" or "balanced" (overrides config.latency if provided) + latency: Latency mode - "normal", "balanced" or "low" (overrides config.latency if provided) speed: Speech speed multiplier, e.g. 1.5 for 1.5x speed (overrides config.prosody.speed if provided) config: TTS configuration (audio settings, voice, model parameters) model: TTS model to use. Deprecated models ("s1", which will be @@ -273,7 +273,7 @@ def convert( reference_id: Voice reference ID (overrides config.reference_id if provided) references: Reference audio samples (overrides config.references if provided) format: Audio format - "mp3", "wav", "pcm", or "opus" (overrides config.format if provided) - latency: Latency mode - "normal" or "balanced" (overrides config.latency if provided) + latency: Latency mode - "normal", "balanced" or "low" (overrides config.latency if provided) speed: Speech speed multiplier, e.g. 1.5 for 1.5x speed (overrides config.prosody.speed if provided) config: TTS configuration (audio settings, voice, model parameters) model: TTS model to use. Deprecated models ("s1", which will be @@ -339,7 +339,7 @@ def stream_with_timestamps( format: Audio format - "mp3", "wav", "pcm", or "opus" (overrides config.format if provided). "opus" is the best fit for playing audio while it streams; "wav" and "pcm" are uncompressed, which keeps sample positions exact. - latency: Latency mode - "normal" or "balanced" (overrides config.latency if provided) + latency: Latency mode - "normal", "balanced" or "low" (overrides config.latency if provided) speed: Speech speed multiplier, e.g. 1.5 for 1.5x speed (overrides config.prosody.speed if provided) config: TTS configuration (audio settings, voice, model parameters) model: TTS model to use. Deprecated models ("s1", which will be @@ -428,7 +428,7 @@ def convert_with_timestamps( format: Audio format - "mp3", "wav", "pcm", or "opus" (overrides config.format if provided). "opus" is the best fit for playing audio while it streams; "wav" and "pcm" are uncompressed, which keeps sample positions exact. - latency: Latency mode - "normal" or "balanced" (overrides config.latency if provided) + latency: Latency mode - "normal", "balanced" or "low" (overrides config.latency if provided) speed: Speech speed multiplier, e.g. 1.5 for 1.5x speed (overrides config.prosody.speed if provided) config: TTS configuration (audio settings, voice, model parameters) model: TTS model to use. Deprecated models ("s1", which will be @@ -493,7 +493,7 @@ def stream_websocket( reference_id: Voice reference ID (overrides config.reference_id if provided) references: Reference audio samples (overrides config.references if provided) format: Audio format - "mp3", "wav", "pcm", or "opus" (overrides config.format if provided) - latency: Latency mode - "normal" or "balanced" (overrides config.latency if provided) + latency: Latency mode - "normal", "balanced" or "low" (overrides config.latency if provided) speed: Speech speed multiplier, e.g. 1.5 for 1.5x speed (overrides config.prosody.speed if provided) config: TTS configuration (audio settings, voice, model parameters) model: TTS model to use. Deprecated models ("s1", which will be @@ -654,7 +654,7 @@ async def stream( reference_id: Voice reference ID (overrides config.reference_id if provided) references: Reference audio samples (overrides config.references if provided) format: Audio format - "mp3", "wav", "pcm", or "opus" (overrides config.format if provided) - latency: Latency mode - "normal" or "balanced" (overrides config.latency if provided) + latency: Latency mode - "normal", "balanced" or "low" (overrides config.latency if provided) speed: Speech speed multiplier, e.g. 1.5 for 1.5x speed (overrides config.prosody.speed if provided) config: TTS configuration (audio settings, voice, model parameters) model: TTS model to use. Deprecated models ("s1", which will be @@ -751,7 +751,7 @@ async def convert( reference_id: Voice reference ID (overrides config.reference_id if provided) references: Reference audio samples (overrides config.references if provided) format: Audio format - "mp3", "wav", "pcm", or "opus" (overrides config.format if provided) - latency: Latency mode - "normal" or "balanced" (overrides config.latency if provided) + latency: Latency mode - "normal", "balanced" or "low" (overrides config.latency if provided) speed: Speech speed multiplier, e.g. 1.5 for 1.5x speed (overrides config.prosody.speed if provided) config: TTS configuration (audio settings, voice, model parameters) model: TTS model to use. Deprecated models ("s1", which will be @@ -818,7 +818,7 @@ async def stream_with_timestamps( format: Audio format - "mp3", "wav", "pcm", or "opus" (overrides config.format if provided). "opus" is the best fit for playing audio while it streams; "wav" and "pcm" are uncompressed, which keeps sample positions exact. - latency: Latency mode - "normal" or "balanced" (overrides config.latency if provided) + latency: Latency mode - "normal", "balanced" or "low" (overrides config.latency if provided) speed: Speech speed multiplier, e.g. 1.5 for 1.5x speed (overrides config.prosody.speed if provided) config: TTS configuration (audio settings, voice, model parameters) model: TTS model to use. Deprecated models ("s1", which will be @@ -908,7 +908,7 @@ async def convert_with_timestamps( format: Audio format - "mp3", "wav", "pcm", or "opus" (overrides config.format if provided). "opus" is the best fit for playing audio while it streams; "wav" and "pcm" are uncompressed, which keeps sample positions exact. - latency: Latency mode - "normal" or "balanced" (overrides config.latency if provided) + latency: Latency mode - "normal", "balanced" or "low" (overrides config.latency if provided) speed: Speech speed multiplier, e.g. 1.5 for 1.5x speed (overrides config.prosody.speed if provided) config: TTS configuration (audio settings, voice, model parameters) model: TTS model to use. Deprecated models ("s1", which will be @@ -973,7 +973,7 @@ async def stream_websocket( reference_id: Voice reference ID (overrides config.reference_id if provided) references: Reference audio samples (overrides config.references if provided) format: Audio format - "mp3", "wav", "pcm", or "opus" (overrides config.format if provided) - latency: Latency mode - "normal" or "balanced" (overrides config.latency if provided) + latency: Latency mode - "normal", "balanced" or "low" (overrides config.latency if provided) speed: Speech speed multiplier, e.g. 1.5 for 1.5x speed (overrides config.prosody.speed if provided) config: TTS configuration (audio settings, voice, model parameters) model: TTS model to use. Deprecated models ("s1", which will be diff --git a/src/fishaudio/types/shared.py b/src/fishaudio/types/shared.py index 90de043..017b7a1 100644 --- a/src/fishaudio/types/shared.py +++ b/src/fishaudio/types/shared.py @@ -132,5 +132,7 @@ def warn_if_deprecated_model( # Model state types ModelState = Literal["created", "training", "trained", "failed"] -# Latency modes -LatencyMode = Literal["normal", "balanced"] +# Latency modes. "low" gives earlier first audio on s3-pro. It is not available +# on s3-pro-free, which accepts it without a speed-up; s2.1-pro showed no +# speed-up either. +LatencyMode = Literal["low", "normal", "balanced"] diff --git a/src/fishaudio/types/tts.py b/src/fishaudio/types/tts.py index d56cf2e..fff6110 100644 --- a/src/fishaudio/types/tts.py +++ b/src/fishaudio/types/tts.py @@ -68,7 +68,8 @@ class TTSConfig(BaseModel): normalize: Whether to normalize/clean the input text. Default: True chunk_length: Characters per generation chunk. Range: 100-300. Default: 200. Lower values = faster initial response, higher values = better quality - latency: Generation mode. Options: "normal" (higher quality), "balanced" (faster). Default: "balanced" + latency: Generation mode. Options: "normal" (higher quality), "balanced" (faster), + "low" (earlier first audio on s3-pro). Default: "balanced" reference_id: Voice model ID from fish.audio (e.g., "802e3bc2b27e49c2995d23ef70e6ac89"). Find IDs in voice URLs or via voices.list() references: List of reference audio samples for instant voice cloning. Default: [] @@ -129,6 +130,7 @@ class TTSRequest(BaseModel): reference_id: Voice model ID for using a specific voice. Default: None normalize: Whether to normalize/clean the input text. Default: True latency: Generation mode. Options: "normal", "balanced". Default: "balanced" + "low" is also accepted; it gives earlier first audio on s3-pro. prosody: Speech speed and volume settings. Default: None top_p: Nucleus sampling for token selection. Range: 0.0-1.0. Default: 0.7 temperature: Randomness in generation. Range: 0.0-1.0. Default: 0.7 diff --git a/tests/unit/test_tts.py b/tests/unit/test_tts.py index 882d382..8d9ba17 100644 --- a/tests/unit/test_tts.py +++ b/tests/unit/test_tts.py @@ -415,6 +415,21 @@ def test_convert_with_latency_parameter(self, tts_client, mock_client_wrapper): payload = ormsgpack.unpackb(call_args[1]["content"]) assert payload["latency"] == "normal" + def test_convert_with_low_latency(self, tts_client, mock_client_wrapper): + """latency="low", as a parameter or in the config, is sent as "low".""" + mock_response = Mock() + mock_response.iter_bytes.return_value = iter([b"audio"]) + mock_client_wrapper.request.return_value = mock_response + + tts_client.convert(text="Hello", latency="low") + payload = ormsgpack.unpackb(mock_client_wrapper.request.call_args[1]["content"]) + assert payload["latency"] == "low" + + mock_response.iter_bytes.return_value = iter([b"audio"]) + tts_client.convert(text="Hello", config=TTSConfig(latency="low")) + payload = ormsgpack.unpackb(mock_client_wrapper.request.call_args[1]["content"]) + assert payload["latency"] == "low" + def test_convert_with_speed_parameter(self, tts_client, mock_client_wrapper): """Test TTS with speed as direct parameter.""" mock_response = Mock() diff --git a/tests/unit/test_types.py b/tests/unit/test_types.py index 3e171c1..8a844c7 100644 --- a/tests/unit/test_types.py +++ b/tests/unit/test_types.py @@ -1,7 +1,11 @@ """Tests for type definitions.""" +import typing from decimal import Decimal +import pytest +from pydantic import ValidationError + from fishaudio.types import ( ASRResponse, ASRSegment, @@ -15,6 +19,7 @@ TTSRequest, Voice, ) +from fishaudio.types.shared import LatencyMode class TestVoice: @@ -190,6 +195,21 @@ def test_tts_config_custom_new_parameters(self): assert config.condition_on_previous_chunks is False assert config.early_stop_threshold == 0.8 + def test_latency_mode_names_every_api_value(self): + """LatencyMode offers the three values the API accepts, including low.""" + assert set(typing.get_args(LatencyMode)) == {"low", "normal", "balanced"} + + @pytest.mark.parametrize("latency", ["low", "normal", "balanced"]) + def test_tts_config_and_request_accept_latency(self, latency): + """TTSConfig and TTSRequest accept each latency value.""" + assert TTSConfig(latency=latency).latency == latency + assert TTSRequest(text="Hi", latency=latency).latency == latency + + def test_tts_config_rejects_unknown_latency(self): + """A latency value the API does not know is rejected before sending.""" + with pytest.raises(ValidationError): + TTSConfig(latency="fastest") # ty: ignore[invalid-argument-type] + def test_tts_request_defaults(self): """Test TTSRequest default values including new parameters.""" request = TTSRequest(text="Hello world") From a96a84de2a26ef626001da76a994b4bebb27a837 Mon Sep 17 00:00:00 2001 From: Felix Lu <58391009+lumpinif@users.noreply.github.com> Date: Wed, 2 Dec 2026 10:56:34 -0800 Subject: [PATCH 2/2] docs: save to a file first in the README quick start play() runs ffplay and raises DependencyError when it is not on PATH, so the first example failed on a clean machine after a paid request. The quick start now saves to output.mp3. Playing is an optional block that reads that file and names its requirements (ffplay, or the [utils] extra with use_ffmpeg=False, plus PortAudio on Linux). The [utils] install comment says what it adds. --- README.md | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4569f8a..bf3ee90 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ The official Python library for the Fish Audio API ```bash pip install fish-audio-sdk -# With audio playback utilities +# To play audio without FFmpeg (adds sounddevice and soundfile) pip install "fish-audio-sdk[utils]" ``` @@ -56,15 +56,12 @@ client = FishAudio(api_key="your_api_key") ```python from fishaudio import FishAudio -from fishaudio.utils import play, save +from fishaudio.utils import save client = FishAudio() -# Generate audio +# Generate audio (MP3 by default) and save it to a file audio = client.tts.convert(text="Hello, world!") - -# Play or save -play(audio) save(audio, "output.mp3") ``` @@ -73,19 +70,31 @@ save(audio, "output.mp3") ```python import asyncio from fishaudio import AsyncFishAudio -from fishaudio.utils import play, save +from fishaudio.utils import save async def main(): client = AsyncFishAudio() audio = await client.tts.convert(text="Hello, world!") - play(audio) save(audio, "output.mp3") 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`. + +```python +from fishaudio.utils import play + +with open("output.mp3", "rb") as f: + audio = f.read() + +play(audio) # needs ffplay on PATH +# Or, without FFmpeg, after pip install "fish-audio-sdk[utils]": +# play(audio, use_ffmpeg=False) +``` + ## Core Features ### Text-to-Speech @@ -144,7 +153,7 @@ config = TTSConfig( prosody=Prosody(speed=1.2, volume=-5), reference_id="933563129e564b19a115bedd57b7406a", format="wav", - latency="balanced", + latency="balanced", # or "normal" (quality), "low" (earlier first audio on s3-pro) ) # Reuse across generations