From eb6c31aeddfa1840b9de2aebec652c5ea8795948 Mon Sep 17 00:00:00 2001
From: zhaomingwork <zhaomingwork@qq.com>
Date: 星期六, 06 五月 2023 21:53:28 +0800
Subject: [PATCH] fix problem about chunk_interval

---
 funasr/runtime/python/websocket/ws_client.py        |    3 +--
 funasr/runtime/python/websocket/ws_server_online.py |    9 +++++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/funasr/runtime/python/websocket/ws_client.py b/funasr/runtime/python/websocket/ws_client.py
index 55507a7..c62dd87 100644
--- a/funasr/runtime/python/websocket/ws_client.py
+++ b/funasr/runtime/python/websocket/ws_client.py
@@ -151,8 +151,7 @@
             meg = json.loads(meg)
             # print(meg, end = '')
             # print("\r")
-            text = meg["text"]
-            text_print += text
+            text_print += " {}".format(meg["text"][0]) 
             text_print = text_print[-55:]
             #os.system('clear')
             print("\r"+str(id)+":"+text_print)
diff --git a/funasr/runtime/python/websocket/ws_server_online.py b/funasr/runtime/python/websocket/ws_server_online.py
index ea9ba6d..a395d73 100644
--- a/funasr/runtime/python/websocket/ws_server_online.py
+++ b/funasr/runtime/python/websocket/ws_server_online.py
@@ -54,7 +54,11 @@
 
                 websocket.param_dict_asr_online["chunk_size"] = message["chunk_size"]
                 
-                await async_asr_online(websocket,audio)
+                frames_online.append(audio)
+                if len(frames_online) % message["chunk_interval"] == 0 or not is_speaking:
+                    audio_in = b"".join(frames_online)
+                    await async_asr_online(websocket,audio_in)
+                    frames_online = []
 
 
      
@@ -75,7 +79,8 @@
                     websocket.param_dict_asr_online["cache"] = dict()
                 if "text" in rec_result:
                     if rec_result["text"] != "sil" and rec_result["text"] != "waiting_for_more_voice":
-                        print(rec_result["text"])
+                        if len(rec_result["text"])>0:
+                            rec_result["text"][0]=rec_result["text"][0].replace(" ","")
                         message = json.dumps({"mode": "online", "text": rec_result["text"]})
                         await websocket.send(message)
 

--
Gitblit v1.9.1