diff --git a/backend/open_webui/routers/audio.py b/backend/open_webui/routers/audio.py index 1599852f3c..17bb32f35c 100644 --- a/backend/open_webui/routers/audio.py +++ b/backend/open_webui/routers/audio.py @@ -1091,19 +1091,17 @@ async def transcribe(request: Request, file_path: str, metadata: Optional[dict] detail=ERROR_MESSAGES.DEFAULT(e, 'Error processing audio file'), ) - results = [] try: tasks = [transcription_handler(request, chunk_path, metadata, user) for chunk_path in chunk_paths] - for coro in asyncio.as_completed(tasks): - try: - results.append(await coro) - except HTTPException: - raise - except Exception as transcribe_exc: - raise HTTPException( - status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, - detail=f'Error transcribing chunk: {transcribe_exc}', - ) + # gather keeps results in chunk order, unlike as_completed + results = await asyncio.gather(*tasks) + except HTTPException: + raise + except Exception as transcribe_exc: + raise HTTPException( + status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, + detail=f'Error transcribing chunk: {transcribe_exc}', + ) finally: # Clean up only the temporary chunks, never the original file for chunk_path in chunk_paths: