from __future__ import annotations from functools import lru_cache from faster_whisper import WhisperModel from config import CONFIG @lru_cache(maxsize=1) def _model(): """Load the whisper model once and cache it.""" return WhisperModel( CONFIG.whisper_size, device="cpu", compute_type=CONFIG.whisper_compute, ) def transcribe(audio_path: str) -> str: """Transcribe a recording to text in the configured language.""" if not audio_path: return "" segments, _info = _model().transcribe( audio_path, language=CONFIG.language, vad_filter=True, ) return " ".join(seg.text.strip() for seg in segments).strip()