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
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,12 @@ asyncio.run(main())
**Selecting a model:**

```python
# Recommended for production
production_audio = client.tts.convert(
text="Production speech",
# S3 Pro ("s3-pro") is used when no model is set
audio = client.tts.convert(text="Default model speech")

# S2.1 Pro: the default in 1.7.x and earlier
s21_audio = client.tts.convert(
text="S2.1 Pro speech",
model="s2.1-pro",
)

Expand Down
20 changes: 10 additions & 10 deletions src/fishaudio/resources/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def stream(
latency: Optional[LatencyMode] = None,
speed: Optional[float] = None,
config: TTSConfig = TTSConfig(), # noqa: B008 - never mutated
model: Union[Model, str] = "s2.1-pro",
model: Union[Model, str] = "s3-pro",
request_options: Optional[RequestOptions] = None,
) -> AudioStream:
"""
Expand Down Expand Up @@ -259,7 +259,7 @@ def convert(
latency: Optional[LatencyMode] = None,
speed: Optional[float] = None,
config: TTSConfig = TTSConfig(), # noqa: B008 - never mutated
model: Union[Model, str] = "s2.1-pro",
model: Union[Model, str] = "s3-pro",
request_options: Optional[RequestOptions] = None,
) -> bytes:
"""
Expand Down Expand Up @@ -323,7 +323,7 @@ def stream_with_timestamps(
latency: Optional[LatencyMode] = None,
speed: Optional[float] = None,
config: TTSConfig = TTSConfig(), # noqa: B008 - never mutated
model: Union[Model, str] = "s2.1-pro",
model: Union[Model, str] = "s3-pro",
request_options: Optional[RequestOptions] = None,
) -> TTSTimestampStream:
"""
Expand Down Expand Up @@ -412,7 +412,7 @@ def convert_with_timestamps(
latency: Optional[LatencyMode] = None,
speed: Optional[float] = None,
config: TTSConfig = TTSConfig(), # noqa: B008 - never mutated
model: Union[Model, str] = "s2.1-pro",
model: Union[Model, str] = "s3-pro",
request_options: Optional[RequestOptions] = None,
) -> TTSTimestampResult:
"""
Expand Down Expand Up @@ -479,7 +479,7 @@ def stream_websocket(
latency: Optional[LatencyMode] = None,
speed: Optional[float] = None,
config: TTSConfig = TTSConfig(), # noqa: B008 - never mutated
model: Union[Model, str] = "s2.1-pro",
model: Union[Model, str] = "s3-pro",
max_workers: int = 10,
ws_options: Optional[WebSocketOptions] = None,
) -> Iterator[bytes]:
Expand Down Expand Up @@ -643,7 +643,7 @@ async def stream(
latency: Optional[LatencyMode] = None,
speed: Optional[float] = None,
config: TTSConfig = TTSConfig(), # noqa: B008 - never mutated
model: Union[Model, str] = "s2.1-pro",
model: Union[Model, str] = "s3-pro",
request_options: Optional[RequestOptions] = None,
) -> AsyncAudioStream:
"""
Expand Down Expand Up @@ -737,7 +737,7 @@ async def convert(
latency: Optional[LatencyMode] = None,
speed: Optional[float] = None,
config: TTSConfig = TTSConfig(), # noqa: B008 - never mutated
model: Union[Model, str] = "s2.1-pro",
model: Union[Model, str] = "s3-pro",
request_options: Optional[RequestOptions] = None,
) -> bytes:
"""
Expand Down Expand Up @@ -802,7 +802,7 @@ async def stream_with_timestamps(
latency: Optional[LatencyMode] = None,
speed: Optional[float] = None,
config: TTSConfig = TTSConfig(), # noqa: B008 - never mutated
model: Union[Model, str] = "s2.1-pro",
model: Union[Model, str] = "s3-pro",
request_options: Optional[RequestOptions] = None,
) -> AsyncTTSTimestampStream:
"""
Expand Down Expand Up @@ -892,7 +892,7 @@ async def convert_with_timestamps(
latency: Optional[LatencyMode] = None,
speed: Optional[float] = None,
config: TTSConfig = TTSConfig(), # noqa: B008 - never mutated
model: Union[Model, str] = "s2.1-pro",
model: Union[Model, str] = "s3-pro",
request_options: Optional[RequestOptions] = None,
) -> TTSTimestampResult:
"""
Expand Down Expand Up @@ -960,7 +960,7 @@ async def stream_websocket(
latency: Optional[LatencyMode] = None,
speed: Optional[float] = None,
config: TTSConfig = TTSConfig(), # noqa: B008 - never mutated
model: Union[Model, str] = "s2.1-pro",
model: Union[Model, str] = "s3-pro",
ws_options: Optional[WebSocketOptions] = None,
):
"""
Expand Down
4 changes: 2 additions & 2 deletions src/fishaudio/types/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ def _get_response_headers(model: BaseModel) -> httpx.Headers:


# Model types
Model = Literal["s1", "s2-pro", "s2.1-pro", "s2.1-pro-free", "drama-3"]
Model = Literal["s1", "s2-pro", "s2.1-pro", "s2.1-pro-free", "drama-3", "s3-pro"]

# Deprecated models, mapped to the warning shown when one is used.
_SPEECH_1_MESSAGE = "Model '{model}' is deprecated. Use 's2.1-pro' instead."
_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' "
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_deprecated_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def test_each_model_shows_once(self):

assert [str(w.message) for w in _deprecation_warnings(record)] == [
S1_MESSAGE,
"Model 'speech-1.5' is deprecated. Use 's2.1-pro' instead.",
"Model 'speech-1.5' is deprecated. Use 's3-pro' instead.",
]

def test_always_filter_shows_every_call(self):
Expand Down
20 changes: 16 additions & 4 deletions tests/unit/test_tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_stream_basic(self, tts_client, mock_client_wrapper):

# Check headers
assert call_args[1]["headers"]["Content-Type"] == "application/msgpack"
assert call_args[1]["headers"]["model"] == "s2.1-pro" # default model
assert call_args[1]["headers"]["model"] == "s3-pro" # default model

# Check payload was msgpack encoded
assert "content" in call_args[1]
Expand All @@ -85,7 +85,7 @@ def test_convert_basic(self, tts_client, mock_client_wrapper):
# Verify request was made correctly
mock_client_wrapper.request.assert_called_once()
call_args = mock_client_wrapper.request.call_args
assert call_args[1]["headers"]["model"] == "s2.1-pro"
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."""
Expand All @@ -111,6 +111,18 @@ def test_convert_with_drama_3(self, tts_client, mock_client_wrapper):
call_args = mock_client_wrapper.request.call_args
assert call_args[1]["headers"]["model"] == "drama-3"

def test_convert_with_s3_pro(self, tts_client, mock_client_wrapper):
"""Test the s3-pro model is sent as the model header."""
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="s3-pro")

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

def test_convert_with_reference_id(self, tts_client, mock_client_wrapper):
"""Test TTS with reference voice ID."""
mock_response = Mock()
Expand Down Expand Up @@ -536,7 +548,7 @@ async def async_iter_bytes():

assert call_args[0][0] == "POST"
assert call_args[0][1] == "/v1/tts"
assert call_args[1]["headers"]["model"] == "s2.1-pro"
assert call_args[1]["headers"]["model"] == "s3-pro"

@pytest.mark.asyncio
async def test_convert_basic(self, async_tts_client, async_mock_client_wrapper):
Expand All @@ -562,7 +574,7 @@ async def async_iter_bytes():
# Verify request was made
async_mock_client_wrapper.request.assert_called_once()
call_args = async_mock_client_wrapper.request.call_args
assert call_args[1]["headers"]["model"] == "s2.1-pro"
assert call_args[1]["headers"]["model"] == "s3-pro"

@pytest.mark.asyncio
async def test_convert_with_reference_id(
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_tts_realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_stream_websocket_basic(
# Verify WebSocket connection was created
mock_connect_ws.assert_called_once()
assert mock_connect_ws.call_args[0][0] == "/v1/tts/live"
assert mock_connect_ws.call_args[1]["headers"]["model"] == "s2.1-pro"
assert mock_connect_ws.call_args[1]["headers"]["model"] == "s3-pro"

@pytest.mark.filterwarnings("ignore::FutureWarning")
@patch("fishaudio.resources.tts.connect_ws")
Expand Down Expand Up @@ -426,7 +426,7 @@ async def text_stream():
# Verify WebSocket connection was created
mock_aconnect_ws.assert_called_once()
assert mock_aconnect_ws.call_args[0][0] == "/v1/tts/live"
assert mock_aconnect_ws.call_args[1]["headers"]["model"] == "s2.1-pro"
assert mock_aconnect_ws.call_args[1]["headers"]["model"] == "s3-pro"

@pytest.mark.filterwarnings("ignore::FutureWarning")
@pytest.mark.asyncio
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/test_tts_timestamps.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,17 @@ def handler(request):
)
assert seen["timeout"]["read"] == 12.5

def test_default_model_is_s3_pro(self):
seen = {}

def handler(request):
seen["request"] = request
return httpx.Response(200, stream=_SyncBody(BODY))

_sync_tts(handler).stream_with_timestamps(text="Hello world.").close()

assert seen["request"].headers["model"] == "s3-pro"


class TestAsyncTimestamps:
async def test_request_path_and_headers(self):
Expand All @@ -412,6 +423,18 @@ def handler(request):
assert request.headers["model"] == "s2-pro"
assert ormsgpack.unpackb(request.content)["format"] == "wav"

async def test_default_model_is_s3_pro(self):
seen = {}

def handler(request):
seen["request"] = request
return httpx.Response(200, stream=_AsyncBody(BODY))

stream = await _async_tts(handler).stream_with_timestamps(text="Hello world.")
await stream.aclose()

assert seen["request"].headers["model"] == "s3-pro"

async def test_events_are_typed_and_arrive_incrementally(self):
body = _AsyncBody(BODY)
stream = await _async_tts(_ok(body)).stream_with_timestamps(text="Hi")
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_websocket_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_the_default_handshake_headers(path):
"""What a call without ws_options sends, written out."""
sent = handshake(path)

model = "transcribe-stream-1" if "asr" in path else "s2.1-pro"
model = "transcribe-stream-1" if "asr" in path else "s3-pro"
assert [name for name, _ in sent] == [
"accept",
"accept-encoding",
Expand Down