From d14855ef20b691130a49228f2afc0889fe0b5905 Mon Sep 17 00:00:00 2001
From: 游雁 <zhifu.gzf@alibaba-inc.com>
Date: 星期五, 24 三月 2023 18:35:14 +0800
Subject: [PATCH] websocket
---
funasr/runtime/python/websocket/ASR_server.py | 17 ++++++++++-------
1 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/funasr/runtime/python/websocket/ASR_server.py b/funasr/runtime/python/websocket/ASR_server.py
index b7c42d1..9344f38 100644
--- a/funasr/runtime/python/websocket/ASR_server.py
+++ b/funasr/runtime/python/websocket/ASR_server.py
@@ -62,7 +62,7 @@
mode='online',
ngpu=args.ngpu,
)
-param_dict_vad = {'in_cache': dict(), "is_final": False}
+# param_dict_vad = {'in_cache': dict(), "is_final": False}
# asr
param_dict_asr = {}
@@ -74,7 +74,7 @@
ngpu=args.ngpu,
)
if args.punc_model != "":
- param_dict_punc = {'cache': list()}
+ # param_dict_punc = {'cache': list()}
inference_pipeline_punc = pipeline(
task=Tasks.punctuation,
model=args.punc_model,
@@ -96,6 +96,8 @@
global websocket_users
speech_start, speech_end = False, False
# 璋冪敤asr鍑芥暟
+ websocket.param_dict_vad = {'in_cache': dict(), "is_final": False}
+ websocket.param_dict_punc = {'cache': list()}
websocket.speek = Queue() #websocket 娣诲姞杩涢槦鍒楀璞� 璁゛sr璇诲彇璇煶鏁版嵁鍖�
websocket.send_msg = Queue() #websocket 娣诲姞涓槦鍒楀璞� 璁﹚s鍙戦�佹秷鎭埌瀹㈡埛绔�
websocket_users.add(websocket)
@@ -114,7 +116,7 @@
if speech_start:
frames.append(message)
RECORD_NUM += 1
- speech_start_i, speech_end_i = vad(message)
+ speech_start_i, speech_end_i = vad(message, websocket)
#print(speech_start_i, speech_end_i)
if speech_start_i:
speech_start = speech_start_i
@@ -143,7 +145,7 @@
def asr(websocket): # ASR鎺ㄧ悊
global inference_pipeline2
- global param_dict_punc
+ # global param_dict_punc
global websocket_users
while websocket in websocket_users:
if not websocket.speek.empty():
@@ -152,17 +154,18 @@
if len(audio_in) > 0:
rec_result = inference_pipeline_asr(audio_in=audio_in)
if inference_pipeline_punc is not None and 'text' in rec_result:
- rec_result = inference_pipeline_punc(text_in=rec_result['text'], param_dict=param_dict_punc)
+ rec_result = inference_pipeline_punc(text_in=rec_result['text'], param_dict=websocket.param_dict_punc)
+ # print(rec_result)
if "text" in rec_result:
websocket.send_msg.put(rec_result["text"]) # 瀛樺叆鍙戦�侀槦鍒� 鐩存帴璋冪敤send鍙戦�佷笉浜�
time.sleep(0.1)
-def vad(data): # VAD鎺ㄧ悊
+def vad(data, websocket): # VAD鎺ㄧ悊
global vad_pipline, param_dict_vad
#print(type(data))
# print(param_dict_vad)
- segments_result = inference_pipeline_vad(audio_in=data, param_dict=param_dict_vad)
+ segments_result = inference_pipeline_vad(audio_in=data, param_dict=websocket.param_dict_vad)
# print(segments_result)
# print(param_dict_vad)
speech_start = False
--
Gitblit v1.9.1