浏览代码

fix(asr): concatenate streaming ASR chunks instead of keeping only last

Streaming Mimo ASR returns text in fragments (e.g. '嗯' then '。').
Previous code overwrote with each chunk, keeping only final punctuation.
Now correctly concatenates all chunks.
wenhongquan 1 月之前
父节点
当前提交
ca38fff29c
共有 1 个文件被更改,包括 2 次插入2 次删除
  1. 2 2
      asr_agent/conversation_worker.py

+ 2 - 2
asr_agent/conversation_worker.py

@@ -181,7 +181,7 @@ async def _asr_transcribe(audio_data: np.ndarray, asr_engine=None) -> str:
         text = ""
         async for chunk, is_done in _asr_mimo_stream(audio_data):
             if chunk:
-                text = chunk  # last partial becomes final
+                text += chunk
         return text.strip()
     loop = asyncio.get_running_loop()
     result = await loop.run_in_executor(None, asr_engine.transcribe_array, audio_data)
@@ -213,7 +213,7 @@ async def _asr_mimo_stream(audio_data: np.ndarray):
                         "data": f"data:audio/wav;base64,{audio_b64}"}}
                 ]}],
                 "stream": True,
-                "extra_body": {"asr_options": {"language": "auto"}},
+                "asr_options": {"language": "auto"},
             },
             headers=h, timeout=aiohttp.ClientTimeout(total=20),
         ) as r: