GladiaSTTService: deprecate confidence arg

This commit is contained in:
Mark Backman
2025-09-18 09:17:40 -04:00
parent ca96eef1f3
commit e8a676eb36
2 changed files with 45 additions and 32 deletions

View File

@@ -41,6 +41,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Deprecated ### Deprecated
- `GladiaSTTService`'s `confidence` arg is deprecated. `confidence` is no
longer needed to determine which transcription or translation frames to
emit.
- `PipelineTask` events `on_pipeline_stopped`, `on_pipeline_ended` and - `PipelineTask` events `on_pipeline_stopped`, `on_pipeline_ended` and
`on_pipeline_cancelled` are now deprecated. Use `on_pipeline_finished` `on_pipeline_cancelled` are now deprecated. Use `on_pipeline_finished`
instead. instead.

View File

@@ -13,6 +13,7 @@ supporting multiple languages, custom vocabulary, and various audio processing o
import asyncio import asyncio
import base64 import base64
import json import json
import warnings
from typing import Any, AsyncGenerator, Dict, Literal, Optional from typing import Any, AsyncGenerator, Dict, Literal, Optional
import aiohttp import aiohttp
@@ -173,8 +174,6 @@ class _InputParamsDescriptor:
"""Descriptor for backward compatibility with deprecation warning.""" """Descriptor for backward compatibility with deprecation warning."""
def __get__(self, obj, objtype=None): def __get__(self, obj, objtype=None):
import warnings
with warnings.catch_warnings(): with warnings.catch_warnings():
warnings.simplefilter("always") warnings.simplefilter("always")
warnings.warn( warnings.warn(
@@ -208,7 +207,7 @@ class GladiaSTTService(STTService):
api_key: str, api_key: str,
region: Literal["us-west", "eu-west"] | None = None, region: Literal["us-west", "eu-west"] | None = None,
url: str = "https://api.gladia.io/v2/live", url: str = "https://api.gladia.io/v2/live",
confidence: float = 0.5, confidence: Optional[float] = None,
sample_rate: Optional[int] = None, sample_rate: Optional[int] = None,
model: str = "solaria-1", model: str = "solaria-1",
params: Optional[GladiaInputParams] = None, params: Optional[GladiaInputParams] = None,
@@ -224,6 +223,11 @@ class GladiaSTTService(STTService):
region: Region used to process audio. eu-west or us-west. Defaults to eu-west. region: Region used to process audio. eu-west or us-west. Defaults to eu-west.
url: Gladia API URL. Defaults to "https://api.gladia.io/v2/live". url: Gladia API URL. Defaults to "https://api.gladia.io/v2/live".
confidence: Minimum confidence threshold for transcriptions (0.0-1.0). confidence: Minimum confidence threshold for transcriptions (0.0-1.0).
.. deprecated:: 0.0.86
The 'confidence' parameter is deprecated and will be removed in a future version.
No confidence threshold is applied.
sample_rate: Audio sample rate in Hz. If None, uses service default. sample_rate: Audio sample rate in Hz. If None, uses service default.
model: Model to use for transcription. Defaults to "solaria-1". model: Model to use for transcription. Defaults to "solaria-1".
params: Additional configuration parameters for Gladia service. params: Additional configuration parameters for Gladia service.
@@ -236,7 +240,6 @@ class GladiaSTTService(STTService):
params = params or GladiaInputParams() params = params or GladiaInputParams()
# Warn about deprecated language parameter if it's used
if params.language is not None: if params.language is not None:
with warnings.catch_warnings(): with warnings.catch_warnings():
warnings.simplefilter("always") warnings.simplefilter("always")
@@ -247,11 +250,20 @@ class GladiaSTTService(STTService):
stacklevel=2, stacklevel=2,
) )
if confidence:
with warnings.catch_warnings():
warnings.simplefilter("always")
warnings.warn(
"The 'confidence' parameter is deprecated and will be removed in a future version. "
"No confidence threshold is applied.",
DeprecationWarning,
stacklevel=2,
)
self._api_key = api_key self._api_key = api_key
self._region = region self._region = region
self._url = url self._url = url
self.set_model_name(model) self.set_model_name(model)
self._confidence = confidence
self._params = params self._params = params
self._websocket = None self._websocket = None
self._receive_task = None self._receive_task = None
@@ -575,43 +587,40 @@ class GladiaSTTService(STTService):
elif content["type"] == "transcript": elif content["type"] == "transcript":
utterance = content["data"]["utterance"] utterance = content["data"]["utterance"]
confidence = utterance.get("confidence", 0)
language = utterance["language"] language = utterance["language"]
transcript = utterance["text"] transcript = utterance["text"]
is_final = content["data"]["is_final"] is_final = content["data"]["is_final"]
if confidence >= self._confidence: if is_final:
if is_final: await self.push_frame(
await self.push_frame( TranscriptionFrame(
TranscriptionFrame( transcript,
transcript, self._user_id,
self._user_id, time_now_iso8601(),
time_now_iso8601(), language,
language, result=content,
result=content,
)
) )
await self._handle_transcription( )
transcript=transcript, await self._handle_transcription(
is_final=is_final, transcript=transcript,
language=language, is_final=is_final,
) language=language,
else: )
await self.push_frame( else:
InterimTranscriptionFrame( await self.push_frame(
transcript, InterimTranscriptionFrame(
self._user_id, transcript,
time_now_iso8601(), self._user_id,
language, time_now_iso8601(),
result=content, language,
) result=content,
) )
)
elif content["type"] == "translation": elif content["type"] == "translation":
translated_utterance = content["data"]["translated_utterance"] translated_utterance = content["data"]["translated_utterance"]
original_language = content["data"]["original_language"] original_language = content["data"]["original_language"]
translated_language = translated_utterance["language"] translated_language = translated_utterance["language"]
confidence = translated_utterance.get("confidence", 0)
translation = translated_utterance["text"] translation = translated_utterance["text"]
if translated_language != original_language and confidence >= self._confidence: if translated_language != original_language:
await self.push_frame( await self.push_frame(
TranslationFrame( TranslationFrame(
translation, "", time_now_iso8601(), translated_language translation, "", time_now_iso8601(), translated_language