Skip to content

Commit

Permalink
Fix 400 This voice does not support speaking rate or pitch parameters…
Browse files Browse the repository at this point in the history
… at this time for Google Cloud Journey voices (#134255)
  • Loading branch information
tronikos authored and bramkragten committed Dec 30, 2024
1 parent a627fa7 commit 7456ce1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
4 changes: 4 additions & 0 deletions homeassistant/components/google_cloud/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
CONF_PROFILES = "profiles"
CONF_TEXT_TYPE = "text_type"

DEFAULT_SPEED = 1.0
DEFAULT_PITCH = 0
DEFAULT_GAIN = 0

# STT constants
CONF_STT_MODEL = "stt_model"

Expand Down
9 changes: 6 additions & 3 deletions homeassistant/components/google_cloud/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
CONF_SPEED,
CONF_TEXT_TYPE,
CONF_VOICE,
DEFAULT_GAIN,
DEFAULT_LANG,
DEFAULT_PITCH,
DEFAULT_SPEED,
)

DEFAULT_VOICE = ""
Expand Down Expand Up @@ -104,15 +107,15 @@ def tts_options_schema(
),
vol.Optional(
CONF_SPEED,
default=defaults.get(CONF_SPEED, 1.0),
default=defaults.get(CONF_SPEED, DEFAULT_SPEED),
): NumberSelector(NumberSelectorConfig(min=0.25, max=4.0, step=0.01)),
vol.Optional(
CONF_PITCH,
default=defaults.get(CONF_PITCH, 0),
default=defaults.get(CONF_PITCH, DEFAULT_PITCH),
): NumberSelector(NumberSelectorConfig(min=-20.0, max=20.0, step=0.1)),
vol.Optional(
CONF_GAIN,
default=defaults.get(CONF_GAIN, 0),
default=defaults.get(CONF_GAIN, DEFAULT_GAIN),
): NumberSelector(NumberSelectorConfig(min=-96.0, max=16.0, step=0.1)),
vol.Optional(
CONF_PROFILES,
Expand Down
21 changes: 18 additions & 3 deletions homeassistant/components/google_cloud/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@
CONF_SPEED,
CONF_TEXT_TYPE,
CONF_VOICE,
DEFAULT_GAIN,
DEFAULT_LANG,
DEFAULT_PITCH,
DEFAULT_SPEED,
DOMAIN,
)
from .helpers import async_tts_voices, tts_options_schema, tts_platform_schema
Expand Down Expand Up @@ -191,11 +194,23 @@ async def _async_get_tts_audio(
ssml_gender=gender,
name=voice,
),
# Avoid: "This voice does not support speaking rate or pitch parameters at this time."
# by not specifying the fields unless they differ from the defaults
audio_config=texttospeech.AudioConfig(
audio_encoding=encoding,
speaking_rate=options[CONF_SPEED],
pitch=options[CONF_PITCH],
volume_gain_db=options[CONF_GAIN],
speaking_rate=(
options[CONF_SPEED]
if options[CONF_SPEED] != DEFAULT_SPEED
else None
),
pitch=(
options[CONF_PITCH]
if options[CONF_PITCH] != DEFAULT_PITCH
else None
),
volume_gain_db=(
options[CONF_GAIN] if options[CONF_GAIN] != DEFAULT_GAIN else None
),
effects_profile_id=options[CONF_PROFILES],
),
)
Expand Down

0 comments on commit 7456ce1

Please sign in to comment.