""" Speechmatics STT factory for voice-agent. Creates a livekit-plugins-speechmatics STT instance configured for Mandarin-English bilingual recognition with speaker diarization support. The SPEECHMATICS_API_KEY environment variable is read automatically by the livekit-plugins-speechmatics package. """ import logging from livekit.plugins import speechmatics logger = logging.getLogger(__name__) # Map Whisper language codes to Speechmatics language codes _LANG_MAP = { "zh": "cmn", "en": "en", "ja": "ja", "ko": "ko", "de": "de", "fr": "fr", } def create_speechmatics_stt(language: str = "cmn") -> speechmatics.STT: """Create a Speechmatics STT instance for the voice pipeline. Args: language: Language code (Whisper or Speechmatics). Whisper codes like 'zh' are automatically mapped to Speechmatics equivalents. Returns: Configured speechmatics.STT instance. """ sm_lang = _LANG_MAP.get(language, language) stt = speechmatics.STT( language=sm_lang, include_partials=True, ) logger.info("Speechmatics STT created: language=%s (input=%s)", sm_lang, language) return stt