Retry Google Cloud exceptions (#141266)

This commit is contained in:
tronikos 2025-03-24 03:27:59 -07:00 committed by GitHub
parent 0f60fd8c40
commit 4e6eecf11b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View File

@ -6,6 +6,7 @@ from collections.abc import AsyncGenerator, AsyncIterable
import logging
from google.api_core.exceptions import GoogleAPIError, Unauthenticated
from google.api_core.retry import AsyncRetry
from google.cloud import speech_v1
from homeassistant.components.stt import (
@ -127,6 +128,7 @@ class GoogleCloudSpeechToTextEntity(SpeechToTextEntity):
responses = await self._client.streaming_recognize(
requests=request_generator(),
timeout=10,
retry=AsyncRetry(initial=0.1, maximum=2.0, multiplier=2.0),
)
transcript = ""

View File

@ -7,6 +7,7 @@ from pathlib import Path
from typing import Any, cast
from google.api_core.exceptions import GoogleAPIError, Unauthenticated
from google.api_core.retry import AsyncRetry
from google.cloud import texttospeech
import voluptuous as vol
@ -215,7 +216,11 @@ class BaseGoogleCloudProvider:
),
)
response = await self._client.synthesize_speech(request, timeout=10)
response = await self._client.synthesize_speech(
request,
timeout=10,
retry=AsyncRetry(initial=0.1, maximum=2.0, multiplier=2.0),
)
if encoding == texttospeech.AudioEncoding.MP3:
extension = "mp3"