Merge pull request #2375 from fabrice404/gladia-region-selection
Gladia region selection
This commit is contained in:
@@ -14,7 +14,8 @@ import asyncio
|
||||
import base64
|
||||
import json
|
||||
import warnings
|
||||
from typing import Any, AsyncGenerator, Dict, Optional
|
||||
from typing import Any, AsyncGenerator, Dict, Literal, Optional
|
||||
from urllib.parse import urlencode
|
||||
|
||||
import aiohttp
|
||||
from loguru import logger
|
||||
@@ -203,6 +204,7 @@ class GladiaSTTService(STTService):
|
||||
self,
|
||||
*,
|
||||
api_key: str,
|
||||
region: Optional[Literal["us-west", "eu-west"]] = "eu-west",
|
||||
url: str = "https://api.gladia.io/v2/live",
|
||||
confidence: float = 0.5,
|
||||
sample_rate: Optional[int] = None,
|
||||
@@ -217,6 +219,7 @@ class GladiaSTTService(STTService):
|
||||
|
||||
Args:
|
||||
api_key: Gladia API key for authentication.
|
||||
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".
|
||||
confidence: Minimum confidence threshold for transcriptions (0.0-1.0).
|
||||
sample_rate: Audio sample rate in Hz. If None, uses service default.
|
||||
@@ -241,6 +244,7 @@ class GladiaSTTService(STTService):
|
||||
)
|
||||
|
||||
self._api_key = api_key
|
||||
self._region = region
|
||||
self._url = url
|
||||
self.set_model_name(model)
|
||||
self._confidence = confidence
|
||||
@@ -337,6 +341,13 @@ class GladiaSTTService(STTService):
|
||||
|
||||
return settings
|
||||
|
||||
def _get_endpoint_url(self) -> str:
|
||||
query_params = dict()
|
||||
query_params["region"] = self._region or "eu-west"
|
||||
query = urlencode(query_params)
|
||||
|
||||
return f"{self._url}?{query}"
|
||||
|
||||
async def start(self, frame: StartFrame):
|
||||
"""Start the Gladia STT websocket connection.
|
||||
|
||||
@@ -485,11 +496,13 @@ class GladiaSTTService(STTService):
|
||||
async def _setup_gladia(self, settings: Dict[str, Any]):
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.post(
|
||||
self._url,
|
||||
self._get_endpoint_url(),
|
||||
headers={"X-Gladia-Key": self._api_key, "Content-Type": "application/json"},
|
||||
json=settings,
|
||||
) as response:
|
||||
if response.ok:
|
||||
response_text = await response.json()
|
||||
logger.error(f"Gladia response: {response_text}")
|
||||
return await response.json()
|
||||
else:
|
||||
error_text = await response.text()
|
||||
|
||||
Reference in New Issue
Block a user