From 65c18785016c099f40ff626c2c6a7dac91c3426f Mon Sep 17 00:00:00 2001
From: zhaomingwork <61895407+zhaomingwork@users.noreply.github.com>
Date: 星期二, 01 八月 2023 08:54:20 +0800
Subject: [PATCH] add is_final for python_ws_srv (#794)

---
 funasr/runtime/python/websocket/funasr_wss_client.py |    6 +++++-
 funasr/runtime/python/websocket/funasr_wss_server.py |    4 ++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/funasr/runtime/python/websocket/funasr_wss_client.py b/funasr/runtime/python/websocket/funasr_wss_client.py
index 264014f..5830db4 100644
--- a/funasr/runtime/python/websocket/funasr_wss_client.py
+++ b/funasr/runtime/python/websocket/funasr_wss_client.py
@@ -222,7 +222,11 @@
                 # text_print = text_print[-args.words_max_print:]
                 # os.system('clear')
                 print("\rpid" + str(id) + ": " + wav_name + ": " + text_print)
-                offline_msg_done = True
+                if ("is_final" in meg and meg["is_final"]==False):
+                    offline_msg_done = True
+                
+                if not "is_final" in meg:
+                    offline_msg_done = True
             else:
                 if meg["mode"] == "2pass-online":
                     text_print_2pass_online += "{}".format(text)
diff --git a/funasr/runtime/python/websocket/funasr_wss_server.py b/funasr/runtime/python/websocket/funasr_wss_server.py
index 2aff9ba..57f7584 100644
--- a/funasr/runtime/python/websocket/funasr_wss_server.py
+++ b/funasr/runtime/python/websocket/funasr_wss_server.py
@@ -241,7 +241,7 @@
                     # print("offline", rec_result)
                 if 'text' in rec_result:
                     mode = "2pass-offline" if "2pass" in websocket.mode else websocket.mode
-                    message = json.dumps({"mode": mode, "text": rec_result["text"], "wav_name": websocket.wav_name})
+                    message = json.dumps({"mode": mode, "text": rec_result["text"], "wav_name": websocket.wav_name,"is_final":websocket.is_speaking})
                     await websocket.send(message)
 
 
@@ -258,7 +258,7 @@
             if rec_result["text"] != "sil" and rec_result["text"] != "waiting_for_more_voice":
                 # print("online", rec_result)
                 mode = "2pass-online" if "2pass" in websocket.mode else websocket.mode
-                message = json.dumps({"mode": mode, "text": rec_result["text"], "wav_name": websocket.wav_name})
+                message = json.dumps({"mode": mode, "text": rec_result["text"], "wav_name": websocket.wav_name,"is_final":websocket.is_speaking})
                 await websocket.send(message)
 
 if len(args.certfile)>0:

--
Gitblit v1.9.1