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