From 59f920f17c781be3a9b31d2b82dbda28c9b0c362 Mon Sep 17 00:00:00 2001
From: 游雁 <zhifu.gzf@alibaba-inc.com>
Date: 星期一, 08 五月 2023 16:14:25 +0800
Subject: [PATCH] websocket python offline/online 2pass demo
---
funasr/runtime/python/websocket/ws_client.py | 37 ++++++++++++++++++++++++++++---------
1 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/funasr/runtime/python/websocket/ws_client.py b/funasr/runtime/python/websocket/ws_client.py
index 9de31a4..5ced688 100644
--- a/funasr/runtime/python/websocket/ws_client.py
+++ b/funasr/runtime/python/websocket/ws_client.py
@@ -10,6 +10,10 @@
from multiprocessing import Process
from funasr.fileio.datadir_writer import DatadirWriter
+import logging
+
+logging.basicConfig(level=logging.ERROR)
+
parser = argparse.ArgumentParser()
parser.add_argument("--host",
type=str,
@@ -158,25 +162,40 @@
async def message(id):
global websocket
text_print = ""
+ text_print_2pass_online = ""
+ text_print_2pass_offline = ""
while True:
try:
meg = await websocket.recv()
meg = json.loads(meg)
- # print(meg, end = '')
- # print("\r")
- # print(meg)
wav_name = meg.get("wav_name", "demo")
- print(wav_name)
+ # print(wav_name)
text = meg["text"]
if ibest_writer is not None:
ibest_writer["text"][wav_name] = text
+
if meg["mode"] == "online":
text_print += " {}".format(text)
- else:
+ text_print = text_print[-args.words_max_print:]
+ os.system('clear')
+ print("\rpid"+str(id)+": "+text_print)
+ elif meg["mode"] == "online":
text_print += "{}".format(text)
- text_print = text_print[-args.words_max_print:]
- os.system('clear')
- print("\rpid"+str(id)+": "+text_print)
+ text_print = text_print[-args.words_max_print:]
+ os.system('clear')
+ print("\rpid"+str(id)+": "+text_print)
+ else:
+ if meg["mode"] == "2pass-online":
+ text_print_2pass_online += " {}".format(text)
+ text_print = text_print_2pass_offline + text_print_2pass_online
+ else:
+ text_print_2pass_online = " "
+ text_print = text_print_2pass_offline + "{}".format(text)
+ text_print_2pass_offline += "{}".format(text)
+ text_print = text_print[-args.words_max_print:]
+ os.system('clear')
+ print("\rpid" + str(id) + ": " + text_print)
+
except Exception as e:
print("Exception:", e)
traceback.print_exc()
@@ -207,7 +226,7 @@
await asyncio.gather(task, task2, task3)
def one_thread(id):
- asyncio.get_event_loop().run_until_complete(ws_client(id)) # 鍚姩鍗忕▼
+ asyncio.get_event_loop().run_until_complete(ws_client(id))
asyncio.get_event_loop().run_forever()
--
Gitblit v1.9.1