From 72a95366cff09829e6a5fc578cd7ee8deb610341 Mon Sep 17 00:00:00 2001 From: awanawona Date: Wed, 18 Mar 2026 17:51:34 +0800 Subject: [PATCH] fix: Use run_in_executor to avoid blocking async event loop in on_audio_end The on_audio_end callback was calling funasr.transcribe() synchronously, which blocks the entire async event loop during audio transcription. This fix wraps the blocking call in run_in_executor to execute it in a thread pool, preventing UI freezes during long transcriptions. This is consistent with how transcribe_file() in on_chat_start already handles the same issue correctly. --- main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index b970efd..f5049b7 100644 --- a/main.py +++ b/main.py @@ -92,7 +92,10 @@ async def on_audio_end(elements: list[ElementBased]): with open(file_path, "wb") as f: f.write(audio_buffer.read()) - result = funasr.transcribe(file_path) + # Use run_in_executor to avoid blocking the async event loop + loop = asyncio.get_event_loop() + result = await loop.run_in_executor(None, funasr.transcribe, file_path) + await cl.Message( content=result, type="user_message",