fix(voice): correct yandex asr endpoints

This commit is contained in:
Yera All
2026-04-17 13:39:26 +05:00
parent feb0ce01e2
commit ac2269b6a4
3 changed files with 29 additions and 14 deletions
@@ -39,13 +39,20 @@ def _openai_asr_model() -> str:
def _yandex_asr_api_base() -> str:
explicit = os.getenv("AI_VOICE_ASR_YANDEX_API_BASE", "").strip()
if explicit:
return explicit.rstrip("/")
tts_base = os.getenv("AI_VOICE_TTS_YANDEX_API_BASE", "https://tts.api.ml.yandexcloud.kz").strip().lower()
if "yandexcloud.kz" in tts_base:
return "https://stt.api.ml.yandexcloud.kz"
normalized = explicit.rstrip("/")
if "stt.api.ml.yandexcloud.kz" in normalized.lower():
return "https://stt.api.cloud.yandex.net"
return normalized
return "https://stt.api.cloud.yandex.net"
def _yandex_asr_operations_base() -> str:
explicit = os.getenv("AI_VOICE_ASR_YANDEX_OPERATIONS_BASE", "").strip()
if explicit:
return explicit.rstrip("/")
return "https://operation.api.cloud.yandex.net"
def _yandex_asr_api_key() -> str:
return (
os.getenv("AI_VOICE_ASR_YANDEX_API_KEY", "").strip()
@@ -99,7 +106,8 @@ def _yandex_asr_api_version(api_base: str) -> str:
return "v1"
if raw in {"v3", "v3_async", "async"}:
return "v3"
if "yandexcloud.kz" in str(api_base or "").lower():
normalized_base = str(api_base or "").lower()
if "stt.api.cloud.yandex.net" in normalized_base or "stt.api.ml.yandexcloud.kz" in normalized_base:
return "v3"
return "v1"
@@ -116,9 +124,9 @@ def _yandex_asr_poll_interval_seconds() -> float:
def _yandex_asr_grpc_target(api_base: str) -> str:
explicit = os.getenv("AI_VOICE_ASR_YANDEX_GRPC_TARGET", "").strip()
if explicit:
if "stt.api.ml.yandexcloud.kz" in explicit.lower():
return "stt.api.cloud.yandex.net:443"
return explicit
if "yandexcloud.kz" in str(api_base or "").lower():
return "stt.api.ml.yandexcloud.kz:443"
return "stt.api.cloud.yandex.net:443"
@@ -296,6 +304,7 @@ class YandexSpeechKitASRProvider(ASRProvider):
self._api_key = str(api_key if api_key is not None else _yandex_asr_api_key()).strip()
self._iam_token = str(iam_token if iam_token is not None else _yandex_asr_iam_token()).strip()
self._folder_id = str(folder_id if folder_id is not None else _yandex_asr_folder_id()).strip()
self._operations_base = _yandex_asr_operations_base()
self._timeout_seconds = max(
float(timeout_seconds if timeout_seconds is not None else _yandex_asr_timeout_seconds()),
3.0,
@@ -417,7 +426,7 @@ class YandexSpeechKitASRProvider(ASRProvider):
raise TimeoutError("Yandex ASR v3 recognition timed out")
time.sleep(self._poll_interval_seconds)
operation_response = client.get(
f"{self._api_base}/operations/{operation_id}",
f"{self._operations_base}/operations/{operation_id}",
headers=headers,
)
operation_response.raise_for_status()