diff --git a/README.md b/README.md index 4f42656..5c5174d 100644 --- a/README.md +++ b/README.md @@ -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", ) diff --git a/src/fishaudio/resources/tts.py b/src/fishaudio/resources/tts.py index ffe9793..3e56c70 100644 --- a/src/fishaudio/resources/tts.py +++ b/src/fishaudio/resources/tts.py @@ -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: """ @@ -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: """ @@ -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: """ @@ -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: """ @@ -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]: @@ -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: """ @@ -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: """ @@ -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: """ @@ -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: """ @@ -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, ): """ diff --git a/src/fishaudio/types/shared.py b/src/fishaudio/types/shared.py index 9e0b371..878cf9a 100644 --- a/src/fishaudio/types/shared.py +++ b/src/fishaudio/types/shared.py @@ -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' " diff --git a/tests/unit/test_deprecated_models.py b/tests/unit/test_deprecated_models.py index a725f0f..1bafe94 100644 --- a/tests/unit/test_deprecated_models.py +++ b/tests/unit/test_deprecated_models.py @@ -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): diff --git a/tests/unit/test_tts.py b/tests/unit/test_tts.py index d1fea19..dae917f 100644 --- a/tests/unit/test_tts.py +++ b/tests/unit/test_tts.py @@ -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] @@ -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.""" @@ -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() @@ -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): @@ -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( diff --git a/tests/unit/test_tts_realtime.py b/tests/unit/test_tts_realtime.py index 99e2f13..8100579 100644 --- a/tests/unit/test_tts_realtime.py +++ b/tests/unit/test_tts_realtime.py @@ -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") @@ -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 diff --git a/tests/unit/test_tts_timestamps.py b/tests/unit/test_tts_timestamps.py index ff3e028..c0858e7 100644 --- a/tests/unit/test_tts_timestamps.py +++ b/tests/unit/test_tts_timestamps.py @@ -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): @@ -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") diff --git a/tests/unit/test_websocket_headers.py b/tests/unit/test_websocket_headers.py index 81965de..caa391b 100644 --- a/tests/unit/test_websocket_headers.py +++ b/tests/unit/test_websocket_headers.py @@ -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",