From bf608691d556e604dbdf81613418979f641b36ae Mon Sep 17 00:00:00 2001 From: tronikos Date: Sun, 30 Jun 2024 02:03:24 -0700 Subject: [PATCH] Do not set gender if voice name is specified in Google Cloud TTS (#120848) * Use TextToSpeechAsyncClient in Google Cloud TTS * Do not set gender if voice name is specified in Google Cloud TTS --- homeassistant/components/google_cloud/tts.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/google_cloud/tts.py b/homeassistant/components/google_cloud/tts.py index 0178da30e69..975567845ae 100644 --- a/homeassistant/components/google_cloud/tts.py +++ b/homeassistant/components/google_cloud/tts.py @@ -262,15 +262,18 @@ class GoogleCloudTTSProvider(Provider): options = options_schema(options) encoding = options[CONF_ENCODING] + gender = texttospeech.SsmlVoiceGender[options[CONF_GENDER]] voice = options[CONF_VOICE] - if voice and not voice.startswith(language): - language = voice[:5] + if voice: + gender = None + if not voice.startswith(language): + language = voice[:5] request = texttospeech.SynthesizeSpeechRequest( input=texttospeech.SynthesisInput(**{options[CONF_TEXT_TYPE]: message}), voice=texttospeech.VoiceSelectionParams( language_code=language, - ssml_gender=texttospeech.SsmlVoiceGender[options[CONF_GENDER]], + ssml_gender=gender, name=voice, ), audio_config=texttospeech.AudioConfig(