Correctly return file extension in Google Cloud TTS (#120849)

pull/120864/head
tronikos 2024-06-30 06:02:06 -07:00 committed by GitHub
parent 255cc9ed74
commit 5deb69d492
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 3 deletions

View File

@ -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