Repository: livekit/agents
File: livekit-plugins/livekit-plugins-speechmatics/livekit/plugins/speechmatics/stt.py (Python)

Code before:
            operating_point = operating_point or config.operating_point
            enable_diarization = enable_diarization or config.diarization == "speaker"
            enable_partials = enable_partials or config.enable_partials
            max_delay = max_delay or config.max_delay
            additional_vocab = (
                additional_vocab if is_given(additional_vocab) else config.additional_vocab
            )
            punctuation_overrides = (
                punctuation_overrides
                if is_given(punctuation_overrides)
                else config.punctuation_overrides
            )

        if is_given(audio_settings):
            logger.warning(
                "`audio_settings` is deprecated. Use individual arguments instead (which override this argument)."
            )

            audio: AudioSettings = audio_settings
            sample_rate = sample_rate or audio.sample_rate
            audio_encoding = audio_encoding or audio.encoding

        self._stt_options = STTOptions(
            operating_point=operating_point,
            domain=domain if is_given(domain) else None,
            language=language if is_given(language) else "en",
            output_locale=output_locale if is_given(output_locale) else None,
            enable_partials=enable_partials,
            enable_diarization=enable_diarization,
            max_delay=max_delay,
            end_of_utterance_silence_trigger=end_of_utterance_silence_trigger,
            end_of_utterance_mode=end_of_utterance_mode,
            additional_vocab=additional_vocab if is_given(additional_vocab) else [],
            punctuation_overrides=punctuation_overrides if is_given(punctuation_overrides) else {},
            diarization_sensitivity=diarization_sensitivity,
            speaker_active_format=speaker_active_format,
            speaker_passive_format=speaker_passive_format,
            prefer_current_speaker=prefer_current_speaker,
            focus_speakers=focus_speakers if is_given(focus_speakers) else [],
            ignore_speakers=ignore_speakers if is_given(ignore_speakers) else [],
            focus_mode=focus_mode,
            known_speakers=known_speakers if is_given(known_speakers) else [],
        )

        self._api_key: str = api_key if is_given(api_key) else os.getenv("SPEECHMATICS_API_KEY", "")
        self._base_url: str = (
            base_url
            if is_given(base_url)
            else os.getenv("SPEECHMATICS_RT_URL", "wss://eu2.rt.speechmatics.com/v2")
        )


Review comment (suggestion):
`speaker_diarization_config` is a dataclass? if it requires a specific version of `speechmatics`, we can specify it in pyproject.toml.

```suggestion
            if (
                not is_given(max_speakers)
                and (dz_cfg := config.speaker_diarization_config)
                and dz_cfg.max_speakers is not None
            ):
                max_speakers = dz_cfg.max_speakers
```

Code after:
                "`transcription_config` is deprecated. Use individual arguments instead (which override this argument)."
            )

            config: TranscriptionConfig = transcription_config
            language = language if is_given(language) else config.language
            if not is_given(output_locale) and config.output_locale is not None:
                output_locale = config.output_locale
            if not is_given(domain) and config.domain is not None:
                domain = config.domain
            enable_diarization = enable_diarization or config.diarization == "speaker"
            if not is_given(additional_vocab) and config.additional_vocab is not None:
                additional_vocab = [
                    AdditionalVocabEntry(content=k, sounds_like=v)
                    for k, v in config.additional_vocab.items()
                ]
            if not is_given(punctuation_overrides) and config.punctuation_overrides is not None:
                punctuation_overrides = config.punctuation_overrides
            # Extract max_speakers from speaker_diarization_config if present
            if (
                not is_given(max_speakers)
                and (dz_cfg := config.speaker_diarization_config)
                and hasattr(dz_cfg, "max_speakers")
                and dz_cfg.max_speakers is not None
            ):
                max_speakers = dz_cfg.max_speakers

        if is_given(audio_settings):
            logger.warning(
                "`audio_settings` is deprecated. Use individual arguments instead (which override this argument)."
            )

            audio: AudioSettings = audio_settings
            sample_rate = sample_rate or audio.sample_rate
            audio_encoding = audio_encoding or AudioEncoding(audio.encoding)

        self._stt_options = STTOptions(
            operating_point=operating_point,
            domain=domain if is_given(domain) else None,
            language=language if is_given(language) else "en",
            output_locale=output_locale if is_given(output_locale) else None,
            enable_partials=enable_partials,
            enable_diarization=enable_diarization,
            max_delay=max_delay,
            end_of_utterance_silence_trigger=end_of_utterance_silence_trigger,
            end_of_utterance_mode=end_of_utterance_mode,
            additional_vocab=additional_vocab if is_given(additional_vocab) else [],
            punctuation_overrides=punctuation_overrides if is_given(punctuation_overrides) else {},
            diarization_sensitivity=diarization_sensitivity,
            max_speakers=max_speakers if is_given(max_speakers) else None,
            speaker_active_format=speaker_active_format,
            speaker_passive_format=speaker_passive_format,