Run transcode_audio_to_mp3 in a thread to avoid blocking (#24876)

This incorporates the transcoding implementation in #24145.
This commit is contained in:
Dara Adib
2026-05-20 00:25:34 +04:00
committed by GitHub
parent 2b99945d27
commit 8a104a7ab1
+3 -1
View File
@@ -438,7 +438,9 @@ async def speech(request: Request, user=Depends(get_verified_user)):
audio_data = await r.read()
content_type_header = r.headers.get('Content-Type', 'audio/mpeg')
if not transcode_audio_to_mp3(audio_data, content_type_header, file_path):
if not await asyncio.to_thread(
transcode_audio_to_mp3, audio_data, content_type_header, file_path
):
async with aiofiles.open(file_path, 'wb') as f:
await f.write(audio_data)