Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Google Cloud STT/TTS timeout configurable #136575

Open
wants to merge 10 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions homeassistant/components/google_cloud/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
CONF_GAIN = "gain"
CONF_PROFILES = "profiles"
CONF_TEXT_TYPE = "text_type"
CONF_TIMEOUT= "tts_timeout"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space before =

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove tts_ prefix and use it in stt.py too.


DEFAULT_TIMEOUT = 10
DEFAULT_SPEED = 1.0
DEFAULT_PITCH = 0
DEFAULT_GAIN = 0
Expand Down
6 changes: 6 additions & 0 deletions homeassistant/components/google_cloud/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
CONF_PROFILES,
CONF_SPEED,
CONF_TEXT_TYPE,
CONF_TIMEOUT,
CONF_VOICE,
DEFAULT_GAIN,
DEFAULT_LANG,
DEFAULT_PITCH,
DEFAULT_SPEED,
DEFAULT_TIMEOUT,
)

DEFAULT_VOICE = ""
Expand Down Expand Up @@ -150,6 +152,10 @@ def tts_options_schema(
)
),
),
vol.Optional(
CONF_TIMEOUT,
default=defaults.get(CONF_TIMEOUT, DEFAULT_TIMEOUT),
): NumberSelector(NumberSelectorConfig(min=1, max=60, step=1)),
}
)

Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/google_cloud/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"gain": "Default volume gain (in dB) of the voice",
"profiles": "Default audio profiles",
"text_type": "Default text type",
"stt_model": "STT model"
"stt_model": "STT model",
"tts_timeout": "TTS timeout, seconds",

Check failure on line 29 in homeassistant/components/google_cloud/strings.json

View workflow job for this annotation

GitHub Actions / Check other linters

Failed to json decode (Illegal trailing comma before end of object: line 29 column 48 (char 975))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove tts_ and TTS prefixes and use it in stt.py too.

Copy link
Member

@tronikos tronikos Feb 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with other options, e.g. gain above, change to Timeout (in seconds)

}
}
}
Expand Down
9 changes: 7 additions & 2 deletions homeassistant/components/google_cloud/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
CONF_SERVICE_ACCOUNT_INFO,
CONF_SPEED,
CONF_TEXT_TYPE,
CONF_TIMEOUT,
CONF_VOICE,
DEFAULT_GAIN,
DEFAULT_LANG,
DEFAULT_PITCH,
DEFAULT_SPEED,
DEFAULT_TIMEOUT,
DOMAIN,
)
from .helpers import async_tts_voices, tts_options_schema, tts_platform_schema
Expand Down Expand Up @@ -215,8 +217,11 @@ async def _async_get_tts_audio(
),
)

response = await self._client.synthesize_speech(request, timeout=10)

tts_timeout = options[CONF_TIMEOUT]
if not tts_timeout:
tts_timeout = DEFAULT_TIMEOUT
response = await self._client.synthesize_speech(request, timeout=tts_timeout)

if encoding == texttospeech.AudioEncoding.MP3:
extension = "mp3"
elif encoding == texttospeech.AudioEncoding.OGG_OPUS:
Expand Down
2 changes: 2 additions & 0 deletions tests/components/google_cloud/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ async def test_options_flow(
"profiles",
"text_type",
"stt_model",
"tts_timeout",
}
assert mock_api_tts_from_service_account_info.list_voices.call_count == 2

Expand All @@ -181,5 +182,6 @@ async def test_options_flow(
"profiles": [],
"text_type": "text",
"stt_model": "latest_short",
"tts_timeout": 10,
}
assert mock_api_tts_from_service_account_info.list_voices.call_count == 3
Loading