Skip to content

Commit 4e6eecf

Browse files
authored
Retry Google Cloud exceptions (#141266)
1 parent 0f60fd8 commit 4e6eecf

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

homeassistant/components/google_cloud/stt.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import logging
77

88
from google.api_core.exceptions import GoogleAPIError, Unauthenticated
9+
from google.api_core.retry import AsyncRetry
910
from google.cloud import speech_v1
1011

1112
from homeassistant.components.stt import (
@@ -127,6 +128,7 @@ async def request_generator() -> AsyncGenerator[
127128
responses = await self._client.streaming_recognize(
128129
requests=request_generator(),
129130
timeout=10,
131+
retry=AsyncRetry(initial=0.1, maximum=2.0, multiplier=2.0),
130132
)
131133

132134
transcript = ""

homeassistant/components/google_cloud/tts.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import Any, cast
88

99
from google.api_core.exceptions import GoogleAPIError, Unauthenticated
10+
from google.api_core.retry import AsyncRetry
1011
from google.cloud import texttospeech
1112
import voluptuous as vol
1213

@@ -215,7 +216,11 @@ async def _async_get_tts_audio(
215216
),
216217
)
217218

218-
response = await self._client.synthesize_speech(request, timeout=10)
219+
response = await self._client.synthesize_speech(
220+
request,
221+
timeout=10,
222+
retry=AsyncRetry(initial=0.1, maximum=2.0, multiplier=2.0),
223+
)
219224

220225
if encoding == texttospeech.AudioEncoding.MP3:
221226
extension = "mp3"

0 commit comments

Comments
 (0)