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
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ s21_audio = client.tts.convert(
model="s2.1-pro",
)

# Free to use, including on a new account with no API credit
# S3 Pro Free: the same model at $0 under fair-use limits, for testing and
# prototyping, including on a $0 API balance. The earlier name "s2.1-pro-free"
# is still accepted and is served by s3-pro-free.
free_audio = client.tts.convert(
text="Free speech",
model="s2.1-pro-free",
model="s3-pro-free",
)

# Drama 3: our most expressive model (uses API credit)
Expand Down Expand Up @@ -180,26 +182,26 @@ with client.tts.stream_with_timestamps(text="Long content...", format="opus") as

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`.

`s1` and `transcribe-1` are deprecated and will be retired on December 31, 2026. After that date, requests that specify them are served by `s2.1-pro` and `transcribe-1-pro`. Using a deprecated model emits a `FutureWarning`; with Python's default warning filters it is shown once per calling line. A coroutine scheduled with `asyncio.create_task` or `gather` runs from asyncio's code, so its warning points there and is shown once in all. See [Model Deprecations](https://docs.fish.audio/developer-guide/models-pricing/deprecations).
`s1` and `transcribe-1` are deprecated and will be retired on December 31, 2026. After that date, requests that specify them are served by `s3-pro` and `transcribe-2-pro`. Using a deprecated model emits a `FutureWarning`; with Python's default warning filters it is shown once per calling line. A coroutine scheduled with `asyncio.create_task` or `gather` runs from asyncio's code, so its warning points there and is shown once in all. See [Model Deprecations](https://docs.fish.audio/developer-guide/models-pricing/deprecations).

[Learn more](https://docs.fish.audio/developer-guide/sdk-guide/python/text-to-speech)

### Speech-to-Text

```python
# transcribe-1-pro is the recommended model; without model, the request runs on transcribe-1,
# which is deprecated and will be retired on December 31, 2026.
# transcribe-2-pro is the recommended model; without model, the request runs on transcribe-1,
# which is deprecated and will be retired on December 31, 2026 (then served by transcribe-2-pro).
with open("meeting.wav", "rb") as f:
result = client.asr.transcribe(audio=f.read(), model="transcribe-1-pro")
result = client.asr.transcribe(audio=f.read(), model="transcribe-2-pro")

# On transcribe-1-pro, text keeps <|speaker:N|> markers; speaker_turns has clean text per speaker.
# On transcribe-2-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)
# Speaker turns (transcribe-2-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}")

Expand Down
12 changes: 6 additions & 6 deletions src/fishaudio/resources/asr.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ def transcribe(
language: Language code (e.g., "en", "zh"). Auto-detected if not provided.
include_timestamps: Whether to include timestamp information for segments
(and speaker turns, on models that return them)
model: ASR model, e.g. "transcribe-1-pro" (recommended). Sent as the
model: ASR model, e.g. "transcribe-2-pro" (recommended). Sent as the
``model`` header and takes precedence over one in request_options.
If not provided and request_options sets no ``model`` header, the
request runs on the API's default model, transcribe-1.
transcribe-1 is deprecated and will be retired on December 31,
2026; after that date, the requests it serves, including those
with no ``model`` header, are served by transcribe-1-pro.
with no ``model`` header, are served by transcribe-2-pro.
Passing "transcribe-1" emits a FutureWarning.
request_options: Request-level overrides

Expand All @@ -124,7 +124,7 @@ def transcribe(
audio_bytes = f.read()

result = client.asr.transcribe(
audio=audio_bytes, model="transcribe-1-pro"
audio=audio_bytes, model="transcribe-2-pro"
)
print(result.text)
for segment in result.segments:
Expand Down Expand Up @@ -299,13 +299,13 @@ async def transcribe(
language: Language code (e.g., "en", "zh"). Auto-detected if not provided.
include_timestamps: Whether to include timestamp information for segments
(and speaker turns, on models that return them)
model: ASR model, e.g. "transcribe-1-pro" (recommended). Sent as the
model: ASR model, e.g. "transcribe-2-pro" (recommended). Sent as the
``model`` header and takes precedence over one in request_options.
If not provided and request_options sets no ``model`` header, the
request runs on the API's default model, transcribe-1.
transcribe-1 is deprecated and will be retired on December 31,
2026; after that date, the requests it serves, including those
with no ``model`` header, are served by transcribe-1-pro.
with no ``model`` header, are served by transcribe-2-pro.
Passing "transcribe-1" emits a FutureWarning.
request_options: Request-level overrides

Expand All @@ -321,7 +321,7 @@ async def transcribe(
audio_bytes = await f.read()

result = await client.asr.transcribe(
audio=audio_bytes, model="transcribe-1-pro"
audio=audio_bytes, model="transcribe-2-pro"
)
print(result.text)
for segment in result.segments:
Expand Down
16 changes: 10 additions & 6 deletions src/fishaudio/types/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,25 @@ def _get_response_headers(model: BaseModel) -> httpx.Headers:
return model.__dict__.get("_response_headers", httpx.Headers())


# Model types
Model = Literal["s1", "s2-pro", "s2.1-pro", "s2.1-pro-free", "drama-3", "s3-pro"]
# Model types. "s3-pro-free" is the free tier of S3 Pro (fair-use limits).
# "s2.1-pro-free" is its earlier name: the API still accepts it and serves it
# with s3-pro-free.
Model = Literal[
"s1", "s2-pro", "s2.1-pro", "s2.1-pro-free", "drama-3", "s3-pro", "s3-pro-free"
]

# Deprecated models, mapped to the warning shown when one is used.
_SPEECH_1_MESSAGE = "Model '{model}' is deprecated. Use 's3-pro' instead."
_S1_MESSAGE = (
"Model 's1' is deprecated and will be retired on December 31, 2026. "
"After that date, requests that specify 's1' are served by 's2.1-pro' "
"and billed as 's2.1-pro'. Use 's2.1-pro' instead."
"After that date, requests that specify 's1' are served by 's3-pro' "
"and billed as 's3-pro'. Use 's3-pro' instead."
)
_TRANSCRIBE_1_MESSAGE = (
"Model 'transcribe-1' is deprecated and will be retired on December 31, "
"2026. After that date, requests that specify 'transcribe-1' are served "
"by 'transcribe-1-pro' and billed as 'transcribe-1-pro'. "
"Use 'transcribe-1-pro' instead."
"by 'transcribe-2-pro' and billed as 'transcribe-2-pro'. "
"Use 'transcribe-2-pro' instead."
)

DEPRECATED_TTS_MODELS: dict[str, str] = {
Expand Down
14 changes: 8 additions & 6 deletions tests/unit/test_deprecated_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@

S1_MESSAGE = (
"Model 's1' is deprecated and will be retired on December 31, 2026. "
"After that date, requests that specify 's1' are served by 's2.1-pro' "
"and billed as 's2.1-pro'. Use 's2.1-pro' instead."
"After that date, requests that specify 's1' are served by 's3-pro' "
"and billed as 's3-pro'. Use 's3-pro' instead."
)
TRANSCRIBE_1_MESSAGE = (
"Model 'transcribe-1' is deprecated and will be retired on December 31, "
"2026. After that date, requests that specify 'transcribe-1' are served "
"by 'transcribe-1-pro' and billed as 'transcribe-1-pro'. "
"Use 'transcribe-1-pro' instead."
"by 'transcribe-2-pro' and billed as 'transcribe-2-pro'. "
"Use 'transcribe-2-pro' instead."
)


Expand Down Expand Up @@ -327,7 +327,8 @@ def work() -> None:
class TestCurrentModelsDoNotWarn:
@pytest.mark.parametrize("call", SYNC_TTS, ids=_ids)
@pytest.mark.parametrize(
"model", ["s2.1-pro", "s2.1-pro-free", "s2-pro", "drama-3"]
"model",
["s3-pro", "s3-pro-free", "s2.1-pro", "s2.1-pro-free", "s2-pro", "drama-3"],
)
def test_sync_tts(self, call, model):
with warnings.catch_warnings():
Expand All @@ -337,7 +338,8 @@ def test_sync_tts(self, call, model):
@pytest.mark.asyncio
@pytest.mark.parametrize("call", ASYNC_TTS, ids=_ids)
@pytest.mark.parametrize(
"model", ["s2.1-pro", "s2.1-pro-free", "s2-pro", "drama-3"]
"model",
["s3-pro", "s3-pro-free", "s2.1-pro", "s2.1-pro-free", "s2-pro", "drama-3"],
)
async def test_async_tts(self, call, model):
with warnings.catch_warnings():
Expand Down
17 changes: 13 additions & 4 deletions tests/unit/test_tts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Tests for TTS namespace client."""

import typing
from unittest.mock import AsyncMock, Mock

import ormsgpack
Expand All @@ -8,6 +9,7 @@
from fishaudio.core import AsyncClientWrapper, ClientWrapper, RequestOptions
from fishaudio.resources.tts import AsyncTTSClient, TTSClient
from fishaudio.types import Prosody, ReferenceAudio, TTSConfig
from fishaudio.types.shared import Model


@pytest.fixture
Expand Down Expand Up @@ -87,17 +89,24 @@ def test_convert_basic(self, tts_client, mock_client_wrapper):
call_args = mock_client_wrapper.request.call_args
assert call_args[1]["headers"]["model"] == "s3-pro"

def test_convert_with_free_model(self, tts_client, mock_client_wrapper):
"""Test the free s2.1-pro-free model is sent as the model header."""
def test_model_type_names_the_free_tier(self):
"""The Model type names s3-pro-free and keeps its earlier name."""
names = typing.get_args(Model)
assert "s3-pro-free" in names
assert "s2.1-pro-free" in names

@pytest.mark.parametrize("model", ["s3-pro-free", "s2.1-pro-free"])
def test_convert_with_free_model(self, tts_client, mock_client_wrapper, model):
"""Test the free model (and its earlier name) is sent unchanged."""
mock_response = Mock()
mock_response.iter_bytes.return_value = iter([b"audio"])
mock_client_wrapper.request.return_value = mock_response

audio = tts_client.convert(text="Hello world", model="s2.1-pro-free")
audio = tts_client.convert(text="Hello world", model=model)

assert audio == b"audio"
call_args = mock_client_wrapper.request.call_args
assert call_args[1]["headers"]["model"] == "s2.1-pro-free"
assert call_args[1]["headers"]["model"] == model

def test_convert_with_drama_3(self, tts_client, mock_client_wrapper):
"""Test the drama-3 model is sent as the model header."""
Expand Down