Repository: livekit/agents
File: livekit-plugins/livekit-plugins-google/livekit/plugins/google/tts.py (Python)

Code before:
                raise ValueError("SSML support is not available for streaming synthesis")
            if use_markup:
                raise ValueError("SSML support is not available for markup input")

        self._client: texttospeech.TextToSpeechAsyncClient | None = None
        self._credentials_info = credentials_info
        self._credentials_file = credentials_file
        self._location = location

        lang = language if is_given(language) else DEFAULT_LANGUAGE
        ssml_gender = _gender_from_str(DEFAULT_GENDER if not is_given(gender) else gender)

        voice_params = texttospeech.VoiceSelectionParams(
            language_code=lang,
            ssml_gender=ssml_gender,
        )
        if is_given(model_name):
            voice_params.model_name = model_name
        if is_given(voice_cloning_key):
            voice_params.voice_clone = texttospeech.VoiceCloneParams(
                voice_cloning_key=voice_cloning_key,
            )
        else:
            voice_params.name = (
                voice_name
                if is_given(voice_name)
                else "Charon"
                if voice_params.model_name
                else "en-US-Chirp3-HD-Charon"
            )

        if not is_given(tokenizer):
            tokenizer = tokenize.blingfire.SentenceTokenizer()

        pronunciations = None if not is_given(custom_pronunciations) else custom_pronunciations

        self._opts = _TTSOptions(
            voice=voice_params,
            encoding=audio_encoding,
            sample_rate=sample_rate,
            pitch=pitch,
            effects_profile_id=effects_profile_id,
            speaking_rate=speaking_rate,
            tokenizer=tokenizer,
            volume_gain_db=volume_gain_db,
            custom_pronunciations=pronunciations,
            enable_ssml=enable_ssml,
            use_markup=use_markup,
            model_name=model_name if is_given(model_name) else None,
            prompt=prompt if is_given(prompt) else None,
        )

Review comment (suggestion):
this is a bit hard to parse, could we break this out into more reasonable params? 

do they support different voice names between the models? then we need a explicit `model_name` check as well? (or comment indicating how the default is chosen)

Code after:
                raise ValueError("SSML support is not available for streaming synthesis")
            if use_markup:
                raise ValueError("SSML support is not available for markup input")

        self._client: texttospeech.TextToSpeechAsyncClient | None = None
        self._credentials_info = credentials_info
        self._credentials_file = credentials_file
        self._location = location

        lang = language if is_given(language) else DEFAULT_LANGUAGE
        ssml_gender = _gender_from_str(DEFAULT_GENDER if not is_given(gender) else gender)

        voice_params = texttospeech.VoiceSelectionParams(
            language_code=lang,
            ssml_gender=ssml_gender,
        )
        if model_name != "chirp_3":  #  voice_params.model_name must not be set for Chirp 3
            voice_params.model_name = model_name

        if is_given(voice_cloning_key):
            voice_params.voice_clone = texttospeech.VoiceCloneParams(
                voice_cloning_key=voice_cloning_key,
            )
        else:
            if is_given(voice_name):
                voice_params.name = voice_name
            elif model_name == "chirp_3":
                voice_params.name = "en-US-Chirp3-HD-Charon"
            else:
                voice_params.name = "Charon"

        if not is_given(tokenizer):
            tokenizer = tokenize.blingfire.SentenceTokenizer()

        pronunciations = None if not is_given(custom_pronunciations) else custom_pronunciations

        self._opts = _TTSOptions(
            voice=voice_params,
            encoding=audio_encoding,
            sample_rate=sample_rate,
            pitch=pitch,
            effects_profile_id=effects_profile_id,
            speaking_rate=speaking_rate,
            tokenizer=tokenizer,
            volume_gain_db=volume_gain_db,
            custom_pronunciations=pronunciations,
            enable_ssml=enable_ssml,
            use_markup=use_markup,
            model_name=model_name,
            prompt=prompt if is_given(prompt) else None,
        )