MCPcopy Create free account
hub / github.com/modelscope/FunASR / async_asr_online

Function async_asr_online

runtime/python/websocket/funasr_wss_server.py:683–712  ·  view source on GitHub ↗
(websocket, audio_in: bytes)

Source from the content-addressed store, hash-verified

681
682
683async def async_asr_online(websocket, audio_in: bytes):
684 if len(audio_in) <= 0:
685 return
686
687 # streaming generate 也是阻塞:线程池执行
688 rec_out = await run_blocking(
689 _generate_sync,
690 model_asr_streaming,
691 audio_in,
692 websocket.status_dict_asr_online,
693 sem=SEM_ASR_ONLINE,
694 )
695 rec_result = rec_out[0]
696 print("online, ", rec_result)
697
698 # 2pass:online 只要 partial,不发 final(final 交给 offline)
699 if websocket.mode == "2pass" and websocket.status_dict_asr_online.get("is_final", False):
700 return
701
702 if rec_result.get("text"):
703 mode = "2pass-online" if "2pass" in (websocket.mode or "") else websocket.mode
704 message = {
705 "mode": mode,
706 "text": rec_result["text"],
707 "wav_name": websocket.wav_name,
708 "is_final": bool(
709 websocket.status_dict_asr_online.get("is_final", False) or (not websocket.is_speaking)
710 ),
711 }
712 await websocket.send(json.dumps(message, ensure_ascii=False))
713
714
715# ===================== 启动服务 =====================

Callers 1

ws_serveFunction · 0.85

Calls 1

run_blockingFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…