From 8bd5ee2d46522ffd6f6a490a81ea808631c129ad Mon Sep 17 00:00:00 2001 From: Felix Lu <58391009+lumpinif@users.noreply.github.com> Date: Wed, 2 Dec 2026 19:32:30 -0800 Subject: [PATCH 1/4] fix(asr): notice when a transcription is sent without a model A transcription with no model runs on the API default, transcribe-1, which retires on 2026-12-31; after that such requests are served and billed as transcribe-2-pro and transcripts can change. Only a named transcribe-1 warned. A request that carries no model (no argument, no model header in request_options or on the httpx client) now emits a FutureWarning, once per process, with the same text as the other Fish Audio SDKs. Passing any model silences it. The default model, the named-transcribe-1 notice and the requests themselves are unchanged. --- README.md | 5 +- src/fishaudio/resources/asr.py | 31 ++++--- src/fishaudio/types/shared.py | 35 ++++++++ tests/unit/test_deprecated_models.py | 126 +++++++++++++++++++++++++-- 4 files changed, 178 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 94b4d84..f204eae 100644 --- a/README.md +++ b/README.md @@ -191,7 +191,7 @@ 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 `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). +`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. A transcription that names no model runs on the API default, `transcribe-1`, and emits a `FutureWarning` once per process; pass any model (the `model` argument or a `model` header) to silence it. A model that only an httpx request hook adds is not seen, so such a request still gets it. 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) @@ -199,7 +199,8 @@ Text without words (only punctuation, or a sound tag such as `[sigh]`) still pro ```python # 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). +# which is deprecated and will be retired on December 31, 2026 (then served by transcribe-2-pro), +# and emits a FutureWarning once per process. with open("meeting.wav", "rb") as f: result = client.asr.transcribe(audio=f.read(), model="transcribe-2-pro") diff --git a/src/fishaudio/resources/asr.py b/src/fishaudio/resources/asr.py index 3699273..1a3b4f5 100644 --- a/src/fishaudio/resources/asr.py +++ b/src/fishaudio/resources/asr.py @@ -28,6 +28,7 @@ DEPRECATED_ASR_MODELS, _set_response_headers, warn_if_deprecated_model, + warn_if_no_asr_model, ) from .asr_realtime import REALTIME_PATH, ASRRealtimeStream, AsyncASRRealtimeStream @@ -110,8 +111,11 @@ def transcribe( 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-2-pro. - Pass model="transcribe-2-pro" to move to it now; a request - without a model gets no warning. "transcribe-1" given as + A request that carries no model emits a FutureWarning, once + per process; pass any model (this argument or a ``model`` + header) to silence it. A model that only an httpx request + hook adds is not seen, so such a request still gets it. + "transcribe-1" given as ``model``, or as a ``model`` header in request_options when ``model`` is not given, emits a FutureWarning; one set only in a custom httpx client's headers is not seen. @@ -136,9 +140,11 @@ def transcribe( print(f"{segment.start}-{segment.end}: {segment.text}") ``` """ - warn_if_deprecated_model( - _requested_model(model, request_options), DEPRECATED_ASR_MODELS - ) + requested = _requested_model(model, request_options) + warn_if_deprecated_model(requested, DEPRECATED_ASR_MODELS) + # httpx adds the client's own headers to a request that has none of + # its own, so a model header there counts too. + warn_if_no_asr_model(requested or self._client.client.headers.get("model")) # Build request payload payload = { @@ -312,8 +318,11 @@ async def transcribe( 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-2-pro. - Pass model="transcribe-2-pro" to move to it now; a request - without a model gets no warning. "transcribe-1" given as + A request that carries no model emits a FutureWarning, once + per process; pass any model (this argument or a ``model`` + header) to silence it. A model that only an httpx request + hook adds is not seen, so such a request still gets it. + "transcribe-1" given as ``model``, or as a ``model`` header in request_options when ``model`` is not given, emits a FutureWarning; one set only in a custom httpx client's headers is not seen. @@ -338,9 +347,11 @@ async def transcribe( print(f"{segment.start}-{segment.end}: {segment.text}") ``` """ - warn_if_deprecated_model( - _requested_model(model, request_options), DEPRECATED_ASR_MODELS - ) + requested = _requested_model(model, request_options) + warn_if_deprecated_model(requested, DEPRECATED_ASR_MODELS) + # httpx adds the client's own headers to a request that has none of + # its own, so a model header there counts too. + warn_if_no_asr_model(requested or self._client.client.headers.get("model")) # Build request payload payload = { diff --git a/src/fishaudio/types/shared.py b/src/fishaudio/types/shared.py index 017b7a1..c573992 100644 --- a/src/fishaudio/types/shared.py +++ b/src/fishaudio/types/shared.py @@ -1,6 +1,7 @@ """Shared types used across the SDK.""" import sys +import threading import warnings from collections.abc import Mapping from types import FrameType @@ -62,6 +63,16 @@ def _get_response_headers(model: BaseModel) -> httpx.Headers: "speech-1.6": _SPEECH_1_MESSAGE.format(model="speech-1.6"), "s1": _S1_MESSAGE, } +# A transcription sent without a model runs on the API default, transcribe-1. +# The same words in every Fish Audio SDK. +_NO_ASR_MODEL_MESSAGE = ( + "No speech-to-text model was specified, so this request runs on the API " + "default, 'transcribe-1'. 'transcribe-1' will be retired on December 31, " + "2026. After that date, requests without a model are served by " + "'transcribe-2-pro' and billed as 'transcribe-2-pro', and transcripts can " + "include speaker markers and audio-event tags. Specify a model to choose " + "now, for example 'transcribe-2-pro'." +) DEPRECATED_ASR_MODELS: dict[str, str] = { "transcribe-1": _TRANSCRIBE_1_MESSAGE, } @@ -120,6 +131,30 @@ def warn_if_deprecated_model( warnings.warn(message, FutureWarning, stacklevel=_stacklevel_outside_package()) +_no_asr_model_warned = False +_no_asr_model_lock = threading.Lock() + + +def warn_if_no_asr_model(model: Optional[str]) -> None: + """Emit a FutureWarning, once per process, when a transcription names no + model: the API then runs it on its default, transcribe-1, which retires. + + Once per process, not once per calling line as warn_if_deprecated_model: + the caller never wrote "transcribe-1", so one notice is enough. It is + attributed to the line that called the SDK method, as that one is. + """ + global _no_asr_model_warned + if model: + return + with _no_asr_model_lock: + if _no_asr_model_warned: + return + _no_asr_model_warned = True + warnings.warn( + _NO_ASR_MODEL_MESSAGE, FutureWarning, stacklevel=_stacklevel_outside_package() + ) + + # Audio format types AudioFormat = Literal["wav", "pcm", "mp3", "opus"] diff --git a/tests/unit/test_deprecated_models.py b/tests/unit/test_deprecated_models.py index 2c27278..3b412d4 100644 --- a/tests/unit/test_deprecated_models.py +++ b/tests/unit/test_deprecated_models.py @@ -11,6 +11,7 @@ from typing import Any, Optional from unittest.mock import Mock, patch +import httpx import pytest from fishaudio.core import AsyncClientWrapper, ClientWrapper, RequestOptions @@ -359,13 +360,6 @@ async def test_async_asr(self, call): warnings.simplefilter("error") await _run_async(call, "transcribe-1-pro") - def test_asr_without_model(self): - """No model named: no warning, although the API default is transcribe-1.""" - with warnings.catch_warnings(): - warnings.simplefilter("error") - with pytest.raises(_Stop): - ASRClient(_sync_wrapper()).transcribe(audio=b"audio") - def test_tts_default_model(self): with warnings.catch_warnings(): warnings.simplefilter("error") @@ -385,6 +379,124 @@ def test_model_ids_match_exactly(self): warn_if_deprecated_model(model) +NO_MODEL_MESSAGE = ( + "No speech-to-text model was specified, so this request runs on the API " + "default, 'transcribe-1'. 'transcribe-1' will be retired on December 31, " + "2026. After that date, requests without a model are served by " + "'transcribe-2-pro' and billed as 'transcribe-2-pro', and transcripts can " + "include speaker markers and audio-event tags. Specify a model to choose " + "now, for example 'transcribe-2-pro'." +) + + +def _asr_wrapper(make: Callable[[], Mock], headers: Any = None) -> Mock: + wrapper = make() + wrapper.client.headers = httpx.Headers(headers) + return wrapper + + +class TestASRWithoutModel: + """No model on the request: the API runs it on transcribe-1, which + retires, so the caller is told, once per process.""" + + @pytest.fixture(autouse=True) + def fresh_process(self, monkeypatch): + # raising=False: the same tests also run against releases without it. + monkeypatch.setattr(shared, "_no_asr_model_warned", False, raising=False) + + def test_sync_warns_once_at_the_call(self): + client = ASRClient(_asr_wrapper(_sync_wrapper)) + with warnings.catch_warnings(record=True) as record: + warnings.simplefilter("always") + with pytest.raises(_Stop): + line = _line() + 1 + client.transcribe(audio=b"audio") + for _ in range(2): # later calls, other lines: no repeat + with pytest.raises(_Stop): + client.transcribe(audio=b"audio") + + emitted = _deprecation_warnings(record) + assert [(w.filename, w.lineno) for w in emitted] == [(__file__, line)] + assert str(emitted[0].message) == NO_MODEL_MESSAGE + + @pytest.mark.asyncio + async def test_async_warns_once_at_the_await(self): + client = AsyncASRClient(_asr_wrapper(_async_wrapper)) + with warnings.catch_warnings(record=True) as record: + warnings.simplefilter("always") + with pytest.raises(_Stop): + line = _line() + 1 + await client.transcribe(audio=b"audio") + with pytest.raises(_Stop): + await client.transcribe(audio=b"audio") + + emitted = _deprecation_warnings(record) + assert [(w.filename, w.lineno) for w in emitted] == [(__file__, line)] + assert str(emitted[0].message) == NO_MODEL_MESSAGE + + def test_sync_and_async_share_the_one_notice(self): + with warnings.catch_warnings(record=True) as record: + warnings.simplefilter("always") + with pytest.raises(_Stop): + ASRClient(_asr_wrapper(_sync_wrapper)).transcribe(audio=b"audio") + with pytest.raises(_Stop): + asyncio.run( + AsyncASRClient(_asr_wrapper(_async_wrapper)).transcribe( + audio=b"audio" + ) + ) + assert len(_deprecation_warnings(record)) == 1 + + @pytest.mark.parametrize( + "how", + ["argument", "request_options", "client_headers"], + ) + @pytest.mark.parametrize("model", ["transcribe-2-pro", "transcribe-1-pro"]) + def test_any_model_silences_it(self, how, model): + headers = {"Model": model} if how == "client_headers" else None + client = ASRClient(_asr_wrapper(_sync_wrapper, headers)) + kwargs: dict[str, Any] = {} + if how == "argument": + kwargs["model"] = model + elif how == "request_options": + kwargs["request_options"] = RequestOptions( + additional_headers={"Model": model} + ) + with warnings.catch_warnings(): + warnings.simplefilter("error") + with pytest.raises(_Stop): + client.transcribe(audio=b"audio", **kwargs) + + def test_named_transcribe_1_keeps_its_own_notice_only(self): + client = ASRClient(_asr_wrapper(_sync_wrapper)) + with warnings.catch_warnings(record=True) as record: + warnings.simplefilter("always") + with pytest.raises(_Stop): + client.transcribe(audio=b"audio", model="transcribe-1") + with pytest.raises(_Stop): + client.transcribe(audio=b"audio") + assert [str(w.message) for w in _deprecation_warnings(record)] == [ + TRANSCRIBE_1_MESSAGE, + NO_MODEL_MESSAGE, + ] + + def test_concurrent_calls_warn_once(self): + client = ASRClient(_asr_wrapper(_sync_wrapper)) + + def call(): + with pytest.raises(_Stop): + client.transcribe(audio=b"audio") + + with warnings.catch_warnings(record=True) as record: + warnings.simplefilter("always") + threads = [threading.Thread(target=call) for _ in range(8)] + for thread in threads: + thread.start() + for thread in threads: + thread.join() + assert len(_deprecation_warnings(record)) == 1 + + def _line() -> int: """The line number of the caller of this function.""" return sys._getframe(1).f_lineno From e638babd42891c17194e40c28694ed3bf6c7a15d Mon Sep 17 00:00:00 2001 From: Felix Lu <58391009+lumpinif@users.noreply.github.com> Date: Wed, 2 Dec 2026 19:43:11 -0800 Subject: [PATCH 2/4] feat(asr): word the no-model notice for requests sent after the retirement The notice said a request without a model runs on 'transcribe-1', which is false for a request sent after 2026-12-31. It now says the request runs on the API's default model, which is 'transcribe-1' until it is retired, and keeps the rest of the common text shared with the other Fish Audio SDKs. The README sentence and the code comment say the same. --- README.md | 2 +- src/fishaudio/types/shared.py | 15 ++++++++------- tests/unit/test_deprecated_models.py | 12 ++++++------ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f204eae..cd535c5 100644 --- a/README.md +++ b/README.md @@ -191,7 +191,7 @@ 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 `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. A transcription that names no model runs on the API default, `transcribe-1`, and emits a `FutureWarning` once per process; pass any model (the `model` argument or a `model` header) to silence it. A model that only an httpx request hook adds is not seen, so such a request still gets it. 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. A transcription that names no model runs on the API's default model (`transcribe-1` until it is retired, `transcribe-2-pro` after) and emits a `FutureWarning` once per process; pass any model (the `model` argument or a `model` header) to silence it. A model that only an httpx request hook adds is not seen, so such a request still gets it. 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) diff --git a/src/fishaudio/types/shared.py b/src/fishaudio/types/shared.py index c573992..6584492 100644 --- a/src/fishaudio/types/shared.py +++ b/src/fishaudio/types/shared.py @@ -63,15 +63,16 @@ def _get_response_headers(model: BaseModel) -> httpx.Headers: "speech-1.6": _SPEECH_1_MESSAGE.format(model="speech-1.6"), "s1": _S1_MESSAGE, } -# A transcription sent without a model runs on the API default, transcribe-1. +# A transcription sent without a model runs on the API default: transcribe-1 +# until 2026-12-31, transcribe-2-pro after. # The same words in every Fish Audio SDK. _NO_ASR_MODEL_MESSAGE = ( - "No speech-to-text model was specified, so this request runs on the API " - "default, 'transcribe-1'. 'transcribe-1' will be retired on December 31, " - "2026. After that date, requests without a model are served by " - "'transcribe-2-pro' and billed as 'transcribe-2-pro', and transcripts can " - "include speaker markers and audio-event tags. Specify a model to choose " - "now, for example 'transcribe-2-pro'." + "No speech-to-text model was specified, so this request runs on the API's " + "default model. The default is 'transcribe-1' until it is retired on " + "December 31, 2026. After that date, requests without a model are served " + "by 'transcribe-2-pro' and billed as 'transcribe-2-pro', and transcripts " + "can include speaker markers and audio-event tags. Specify a model to " + "choose it yourself, for example 'transcribe-2-pro'." ) DEPRECATED_ASR_MODELS: dict[str, str] = { "transcribe-1": _TRANSCRIBE_1_MESSAGE, diff --git a/tests/unit/test_deprecated_models.py b/tests/unit/test_deprecated_models.py index 3b412d4..d0e35b5 100644 --- a/tests/unit/test_deprecated_models.py +++ b/tests/unit/test_deprecated_models.py @@ -380,12 +380,12 @@ def test_model_ids_match_exactly(self): NO_MODEL_MESSAGE = ( - "No speech-to-text model was specified, so this request runs on the API " - "default, 'transcribe-1'. 'transcribe-1' will be retired on December 31, " - "2026. After that date, requests without a model are served by " - "'transcribe-2-pro' and billed as 'transcribe-2-pro', and transcripts can " - "include speaker markers and audio-event tags. Specify a model to choose " - "now, for example 'transcribe-2-pro'." + "No speech-to-text model was specified, so this request runs on the API's " + "default model. The default is 'transcribe-1' until it is retired on " + "December 31, 2026. After that date, requests without a model are served " + "by 'transcribe-2-pro' and billed as 'transcribe-2-pro', and transcripts " + "can include speaker markers and audio-event tags. Specify a model to " + "choose it yourself, for example 'transcribe-2-pro'." ) From ab6012154ea1fa3874ce2eaa8baefc1f639449e3 Mon Sep 17 00:00:00 2001 From: Felix Lu <58391009+lumpinif@users.noreply.github.com> Date: Wed, 2 Dec 2026 19:46:20 -0800 Subject: [PATCH 3/4] fix(asr): let warning filters decide the no-model notice; an empty model is none The notice was given once per process through a module flag and a lock. That broke the caller's warning filters: under an "error" filter the first call raised and a retry went through, a call under "ignore" used the notice up, and a forked child could block on a lock held in the parent. It is now a plain FutureWarning, as for a named deprecated model, so the default filter shows it once per calling line, "error" raises on every call before anything is sent, and "ignore" hides only what it covers. The model the request sends is decided as httpx merges it: the argument, then a model header in request_options, then the httpx client's own header, each skipped only when absent. An empty value then means no model. Before, model="" warned only when the client had no model header, although the request sent the same empty header either way. --- README.md | 4 +- src/fishaudio/resources/asr.py | 38 +++++--- src/fishaudio/types/shared.py | 24 ++---- tests/unit/test_deprecated_models.py | 124 +++++++++++++++++++-------- 4 files changed, 124 insertions(+), 66 deletions(-) diff --git a/README.md b/README.md index cd535c5..41afd8f 100644 --- a/README.md +++ b/README.md @@ -191,7 +191,7 @@ 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 `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. A transcription that names no model runs on the API's default model (`transcribe-1` until it is retired, `transcribe-2-pro` after) and emits a `FutureWarning` once per process; pass any model (the `model` argument or a `model` header) to silence it. A model that only an httpx request hook adds is not seen, so such a request still gets it. 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. A transcription that names no model runs on the API's default model (`transcribe-1` until it is retired, `transcribe-2-pro` after) and emits a `FutureWarning`, shown as the deprecation warnings above are; pass any non-empty model (the `model` argument or a `model` header) to silence it. A model that only an httpx request hook adds is not seen, so such a request still gets it. 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) @@ -200,7 +200,7 @@ Text without words (only punctuation, or a sound tag such as `[sigh]`) still pro ```python # 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), -# and emits a FutureWarning once per process. +# and emits a FutureWarning. with open("meeting.wav", "rb") as f: result = client.asr.transcribe(audio=f.read(), model="transcribe-2-pro") diff --git a/src/fishaudio/resources/asr.py b/src/fishaudio/resources/asr.py index 1a3b4f5..076b510 100644 --- a/src/fishaudio/resources/asr.py +++ b/src/fishaudio/resources/asr.py @@ -3,6 +3,7 @@ from collections.abc import AsyncIterable, Iterable from typing import Optional, Union +import httpx import ormsgpack from httpx_ws import aconnect_ws, connect_ws @@ -48,6 +49,23 @@ def _requested_model( return None +def _sent_model( + model: Optional[str], + request_options: Optional[RequestOptions], + client_headers: httpx.Headers, +) -> Optional[str]: + """Return the model header the request sends, as httpx will merge it. + + The method argument wins, then a model header in request_options, then a + model header on the httpx client itself. Each one is skipped only when it + is absent (None), so an empty value is sent as it is. + """ + requested = _requested_model(model, request_options) + if requested is not None: + return requested + return client_headers.get("model") + + def _realtime_config( config: ASRRealtimeConfig, *, @@ -111,8 +129,8 @@ def transcribe( 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-2-pro. - A request that carries no model emits a FutureWarning, once - per process; pass any model (this argument or a ``model`` + A request that carries no model, or an empty one, emits a + FutureWarning; pass a model (this argument or a ``model`` header) to silence it. A model that only an httpx request hook adds is not seen, so such a request still gets it. "transcribe-1" given as @@ -142,9 +160,9 @@ def transcribe( """ requested = _requested_model(model, request_options) warn_if_deprecated_model(requested, DEPRECATED_ASR_MODELS) - # httpx adds the client's own headers to a request that has none of - # its own, so a model header there counts too. - warn_if_no_asr_model(requested or self._client.client.headers.get("model")) + warn_if_no_asr_model( + _sent_model(model, request_options, self._client.client.headers) + ) # Build request payload payload = { @@ -318,8 +336,8 @@ async def transcribe( 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-2-pro. - A request that carries no model emits a FutureWarning, once - per process; pass any model (this argument or a ``model`` + A request that carries no model, or an empty one, emits a + FutureWarning; pass a model (this argument or a ``model`` header) to silence it. A model that only an httpx request hook adds is not seen, so such a request still gets it. "transcribe-1" given as @@ -349,9 +367,9 @@ async def transcribe( """ requested = _requested_model(model, request_options) warn_if_deprecated_model(requested, DEPRECATED_ASR_MODELS) - # httpx adds the client's own headers to a request that has none of - # its own, so a model header there counts too. - warn_if_no_asr_model(requested or self._client.client.headers.get("model")) + warn_if_no_asr_model( + _sent_model(model, request_options, self._client.client.headers) + ) # Build request payload payload = { diff --git a/src/fishaudio/types/shared.py b/src/fishaudio/types/shared.py index 6584492..ad5f08b 100644 --- a/src/fishaudio/types/shared.py +++ b/src/fishaudio/types/shared.py @@ -1,7 +1,6 @@ """Shared types used across the SDK.""" import sys -import threading import warnings from collections.abc import Mapping from types import FrameType @@ -132,25 +131,18 @@ def warn_if_deprecated_model( warnings.warn(message, FutureWarning, stacklevel=_stacklevel_outside_package()) -_no_asr_model_warned = False -_no_asr_model_lock = threading.Lock() - - def warn_if_no_asr_model(model: Optional[str]) -> None: - """Emit a FutureWarning, once per process, when a transcription names no - model: the API then runs it on its default, transcribe-1, which retires. - - Once per process, not once per calling line as warn_if_deprecated_model: - the caller never wrote "transcribe-1", so one notice is enough. It is - attributed to the line that called the SDK method, as that one is. + """Emit a FutureWarning when a transcription is sent without a model. + + ``model`` is the value the request sends; None or an empty string means + none, and the API then runs the request on its default model. Attributed to + the line that called the SDK method, as warn_if_deprecated_model is, so + Python's warning filters decide how often it is shown: by default once + per such line; under an "error" filter it raises on every call, before + the request is sent. """ - global _no_asr_model_warned if model: return - with _no_asr_model_lock: - if _no_asr_model_warned: - return - _no_asr_model_warned = True warnings.warn( _NO_ASR_MODEL_MESSAGE, FutureWarning, stacklevel=_stacklevel_outside_package() ) diff --git a/tests/unit/test_deprecated_models.py b/tests/unit/test_deprecated_models.py index d0e35b5..405f482 100644 --- a/tests/unit/test_deprecated_models.py +++ b/tests/unit/test_deprecated_models.py @@ -396,56 +396,81 @@ def _asr_wrapper(make: Callable[[], Mock], headers: Any = None) -> Mock: class TestASRWithoutModel: - """No model on the request: the API runs it on transcribe-1, which - retires, so the caller is told, once per process.""" + """No model on the request: the API runs it on its default model, which + is transcribe-1 until it retires, so the caller is told. Python's warning + filters decide how often, as for a named deprecated model.""" - @pytest.fixture(autouse=True) - def fresh_process(self, monkeypatch): - # raising=False: the same tests also run against releases without it. - monkeypatch.setattr(shared, "_no_asr_model_warned", False, raising=False) - - def test_sync_warns_once_at_the_call(self): + def test_sync_warns_at_the_call(self): client = ASRClient(_asr_wrapper(_sync_wrapper)) with warnings.catch_warnings(record=True) as record: warnings.simplefilter("always") with pytest.raises(_Stop): line = _line() + 1 client.transcribe(audio=b"audio") - for _ in range(2): # later calls, other lines: no repeat - with pytest.raises(_Stop): - client.transcribe(audio=b"audio") emitted = _deprecation_warnings(record) assert [(w.filename, w.lineno) for w in emitted] == [(__file__, line)] assert str(emitted[0].message) == NO_MODEL_MESSAGE @pytest.mark.asyncio - async def test_async_warns_once_at_the_await(self): + async def test_async_warns_at_the_await(self): client = AsyncASRClient(_asr_wrapper(_async_wrapper)) with warnings.catch_warnings(record=True) as record: warnings.simplefilter("always") with pytest.raises(_Stop): line = _line() + 1 await client.transcribe(audio=b"audio") - with pytest.raises(_Stop): - await client.transcribe(audio=b"audio") emitted = _deprecation_warnings(record) assert [(w.filename, w.lineno) for w in emitted] == [(__file__, line)] assert str(emitted[0].message) == NO_MODEL_MESSAGE - def test_sync_and_async_share_the_one_notice(self): + def test_default_filter_shows_it_once_per_calling_line(self): + client = ASRClient(_asr_wrapper(_sync_wrapper)) with warnings.catch_warnings(record=True) as record: - warnings.simplefilter("always") + warnings.resetwarnings() + warnings.simplefilter("default") + for _ in range(3): # one line, called three times + with pytest.raises(_Stop): + client.transcribe(audio=b"audio") + with pytest.raises(_Stop): + client.transcribe(audio=b"audio") # another line + assert len(_deprecation_warnings(record)) == 2 + + def test_error_filter_raises_on_every_call_and_sends_nothing(self): + wrapper = _asr_wrapper(_sync_wrapper) + client = ASRClient(wrapper) + with warnings.catch_warnings(): + warnings.simplefilter("error", FutureWarning) + for _ in range(2): # a retry does not get past it either + with pytest.raises(FutureWarning, match="No speech-to-text model"): + client.transcribe(audio=b"audio") + wrapper.request.assert_not_called() + + @pytest.mark.asyncio + async def test_async_error_filter_raises_on_every_call_and_sends_nothing(self): + wrapper = _asr_wrapper(_async_wrapper) + client = AsyncASRClient(wrapper) + with warnings.catch_warnings(): + warnings.simplefilter("error", FutureWarning) + for _ in range(2): + with pytest.raises(FutureWarning, match="No speech-to-text model"): + await client.transcribe(audio=b"audio") + wrapper.request.assert_not_called() + + def test_ignored_call_does_not_silence_a_later_one(self): + client = ASRClient(_asr_wrapper(_sync_wrapper)) + with warnings.catch_warnings(): + warnings.simplefilter("ignore") with pytest.raises(_Stop): - ASRClient(_asr_wrapper(_sync_wrapper)).transcribe(audio=b"audio") + client.transcribe(audio=b"audio") + with warnings.catch_warnings(record=True) as record: + warnings.simplefilter("default") with pytest.raises(_Stop): - asyncio.run( - AsyncASRClient(_asr_wrapper(_async_wrapper)).transcribe( - audio=b"audio" - ) - ) - assert len(_deprecation_warnings(record)) == 1 + client.transcribe(audio=b"audio") + assert [str(w.message) for w in _deprecation_warnings(record)] == [ + NO_MODEL_MESSAGE + ] @pytest.mark.parametrize( "how", @@ -467,34 +492,57 @@ def test_any_model_silences_it(self, how, model): with pytest.raises(_Stop): client.transcribe(audio=b"audio", **kwargs) - def test_named_transcribe_1_keeps_its_own_notice_only(self): - client = ASRClient(_asr_wrapper(_sync_wrapper)) + @pytest.mark.parametrize("client_model", [None, "transcribe-2-pro"]) + @pytest.mark.parametrize("how", ["argument", "request_options"]) + def test_empty_model_warns_whatever_the_client_default(self, how, client_model): + # httpx sends the request's empty header in place of the client's, + # so the request carries no model either way. + headers = {"Model": client_model} if client_model else None + client = ASRClient(_asr_wrapper(_sync_wrapper, headers)) + kwargs: dict[str, Any] = ( + {"model": ""} + if how == "argument" + else {"request_options": RequestOptions(additional_headers={"model": ""})} + ) with warnings.catch_warnings(record=True) as record: warnings.simplefilter("always") with pytest.raises(_Stop): - client.transcribe(audio=b"audio", model="transcribe-1") - with pytest.raises(_Stop): - client.transcribe(audio=b"audio") + client.transcribe(audio=b"audio", **kwargs) assert [str(w.message) for w in _deprecation_warnings(record)] == [ - TRANSCRIBE_1_MESSAGE, - NO_MODEL_MESSAGE, + NO_MODEL_MESSAGE ] - def test_concurrent_calls_warn_once(self): + def test_argument_wins_over_an_empty_request_options_header(self): client = ASRClient(_asr_wrapper(_sync_wrapper)) + with warnings.catch_warnings(): + warnings.simplefilter("error") + with pytest.raises(_Stop): + client.transcribe( + audio=b"audio", + model="transcribe-2-pro", + request_options=RequestOptions(additional_headers={"model": ""}), + ) - def call(): + def test_empty_client_header_warns(self): + client = ASRClient(_asr_wrapper(_sync_wrapper, {"Model": ""})) + with warnings.catch_warnings(record=True) as record: + warnings.simplefilter("always") with pytest.raises(_Stop): client.transcribe(audio=b"audio") + assert len(_deprecation_warnings(record)) == 1 + def test_named_transcribe_1_keeps_its_own_notice_only(self): + client = ASRClient(_asr_wrapper(_sync_wrapper)) with warnings.catch_warnings(record=True) as record: warnings.simplefilter("always") - threads = [threading.Thread(target=call) for _ in range(8)] - for thread in threads: - thread.start() - for thread in threads: - thread.join() - assert len(_deprecation_warnings(record)) == 1 + with pytest.raises(_Stop): + client.transcribe(audio=b"audio", model="transcribe-1") + with pytest.raises(_Stop): + client.transcribe(audio=b"audio") + assert [str(w.message) for w in _deprecation_warnings(record)] == [ + TRANSCRIBE_1_MESSAGE, + NO_MODEL_MESSAGE, + ] def _line() -> int: From 1641e9849e17cec2fe402b652b540edf90e581b7 Mon Sep 17 00:00:00 2001 From: Felix Lu <58391009+lumpinif@users.noreply.github.com> Date: Wed, 2 Dec 2026 19:50:56 -0800 Subject: [PATCH 4/4] docs(asr): say to write the model ID exactly, and what a request hook means for the notice --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 41afd8f..6126dda 100644 --- a/README.md +++ b/README.md @@ -191,7 +191,7 @@ 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 `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. A transcription that names no model runs on the API's default model (`transcribe-1` until it is retired, `transcribe-2-pro` after) and emits a `FutureWarning`, shown as the deprecation warnings above are; pass any non-empty model (the `model` argument or a `model` header) to silence it. A model that only an httpx request hook adds is not seen, so such a request still gets it. 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. A transcription that names no model runs on the API's default model (`transcribe-1` until it is retired, `transcribe-2-pro` after) and emits a `FutureWarning`, shown as the deprecation warnings above are; pass a model (the `model` argument or a `model` header) to silence it. Write the model ID exactly, for example `transcribe-2-pro`: the API runs a name it does not know on its default model, and the SDK does not check names. A model that only an httpx request hook or auth flow adds is not seen, so such a request still gets the warning; if you also turn warnings into errors, pass `model` in the call. 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)