fix(speech): call Gemini once per TTS request

aspeech re-ran speech whenever the first result was not a coroutine, so the
speech-to-completion bridge sent every async Gemini and Vertex AI TTS request
upstream twice. It now returns the sync result

Prerequisite for the backport of #50803 to lts/1.108.x, whose tests count one
upstream request per speech call.
Hand-ported from f4347d4f50 (#44551, main), the aspeech hunk only.
This commit is contained in:
mateo-berri 2026-11-09 20:31:54 -08:00
parent 6e7600bbff
commit ef66d75951

View file

@ -8430,14 +8430,8 @@ async def aspeech(*args, **kwargs) -> HttpxBinaryResponseContent:
api_base=api_base_hint,
)
# Await normally
init_response: Final = await loop.run_in_executor(None, func_with_context)
if asyncio.iscoroutine(init_response):
response = await init_response
else:
# Call the synchronous function using run_in_executor
response = await loop.run_in_executor(None, func_with_context)
return response
return await init_response if asyncio.iscoroutine(init_response) else init_response
except Exception as e:
custom_llm_provider = custom_llm_provider or "openai"
raise exception_type(