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

Function async_asr

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

Source from the content-addressed store, hash-verified

581
582
583async def async_asr(websocket, audio_in: bytes):
584 mode = "2pass-offline" if "2pass" in (websocket.mode or "") else websocket.mode
585
586 if len(audio_in) <= 0:
587 message = {
588 "mode": mode,
589 "text": "",
590 "wav_name": websocket.wav_name,
591 "is_final": True,
592 }
593 await websocket.send(json.dumps(message, ensure_ascii=False))
594 return
595
596 # 1) ASR(阻塞,线程池执行)
597 rec_result_list = await run_blocking(
598 _generate_sync,
599 model_asr,
600 audio_in,
601 websocket.status_dict_asr,
602 sem=SEM_ASR_OFFLINE,
603 )
604 rec_result = rec_result_list[0]
605
606 print("offline_asr, raw:", rec_result)
607 print("offline_asr, keys:", rec_result.keys())
608
609 text = rec_result.get("text", "")
610 timestamp = rec_result.get("timestamp", None)
611 sentence_info = rec_result.get("sentence_info", None)
612
613 # 2) 声纹识别(阻塞,线程池执行)
614 spk_name = "unknown"
615 best_score = 0.0
616 try:
617 spk_name, best_score = await run_blocking(
618 _sv_and_match_sync,
619 audio_in,
620 int(args.speaker_db_reload_sec),
621 sem=SEM_SV,
622 )
623 except Exception as e:
624 print(f"声纹识别失败: {e}")
625
626 # 3) 标点(阻塞,线程池执行)
627 punc_array = None
628 if model_punc is not None and len(text) > 0:
629 try:
630 # punc 只对文本处理
631 punc_out = await run_blocking(
632 _generate_sync,
633 model_punc,
634 text,
635 websocket.status_dict_punc,
636 sem=SEM_PUNC,
637 )
638 punc_result = punc_out[0]
639 print("offline, after punc", punc_result)
640

Callers 1

ws_serveFunction · 0.85

Calls 3

run_blockingFunction · 0.85
to_pythonFunction · 0.85
keysMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…