Watch
1
0
Fork
You've already forked Seyyed_arc
0
forked from hesabix/arc
Seyyed_arc/hesabixAPI/app/services/voice/whisper_pool.py
2026-08-18 17:20:26 +00:00

31 lines
681 B
Python

"""Process-wide Whisper STT so each WS connection does not reload the model."""
from __future__ import annotations
import threading
from app.services.voice.stt import STTConfig, WhisperSTT
_lock = threading.Lock()
_instances: dict[tuple[str, str, str, str], WhisperSTT] = {}
def get_shared_whisper(cfg: STTConfig) -> WhisperSTT:
key = (
str(cfg.model_size_or_path),
str(cfg.device),
str(cfg.compute_type),
str(cfg.language),
)
with _lock:
existing = _instances.get(key)
if existing is not None:
return existing
inst = WhisperSTT(cfg)
_instances[key] = inst
return inst
def reset_shared_whisper_for_tests() -> None:
with _lock:
_instances.clear()