From 5deb69d492fe28b0731a579e6b5c8d0b2b33fb96 Mon Sep 17 00:00:00 2001 From: tronikos Date: Sun, 30 Jun 2024 06:02:06 -0700 Subject: [PATCH] Correctly return file extension in Google Cloud TTS (#120849) --- homeassistant/components/google_cloud/tts.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/google_cloud/tts.py b/homeassistant/components/google_cloud/tts.py index e5374a2151c..f9b01c9b870 100644 --- a/homeassistant/components/google_cloud/tts.py +++ b/homeassistant/components/google_cloud/tts.py @@ -265,7 +265,7 @@ class GoogleCloudTTSProvider(Provider): _LOGGER.error("Error: %s when validating options: %s", err, options) return None, None - encoding = options[CONF_ENCODING] + encoding = texttospeech.AudioEncoding[options[CONF_ENCODING]] gender = texttospeech.SsmlVoiceGender[options[CONF_GENDER]] voice = options[CONF_VOICE] if voice: @@ -281,7 +281,7 @@ class GoogleCloudTTSProvider(Provider): name=voice, ), audio_config=texttospeech.AudioConfig( - audio_encoding=texttospeech.AudioEncoding[encoding], + audio_encoding=encoding, speaking_rate=options[CONF_SPEED], pitch=options[CONF_PITCH], volume_gain_db=options[CONF_GAIN], @@ -295,4 +295,11 @@ class GoogleCloudTTSProvider(Provider): _LOGGER.error("Error occurred during Google Cloud TTS call: %s", err) return None, None - return encoding, response.audio_content + if encoding == texttospeech.AudioEncoding.MP3: + extension = "mp3" + elif encoding == texttospeech.AudioEncoding.OGG_OPUS: + extension = "ogg" + else: + extension = "wav" + + return extension, response.audio_content