From 72d561531ffedfbefa1456f6b0c6c88466154c55 Mon Sep 17 00:00:00 2001
From: nichongjia-2007 <nichongjia@gmail.com>
Date: 星期四, 23 三月 2023 18:44:36 +0800
Subject: [PATCH] Merge branch 'main' of github.com:alibaba-damo-academy/FunASR

---
 funasr/runtime/python/websocket/ASR_client.py |   32 +++++++++++++++++++++++++++-----
 1 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/funasr/runtime/python/websocket/ASR_client.py b/funasr/runtime/python/websocket/ASR_client.py
index 081e6d5..8010b18 100644
--- a/funasr/runtime/python/websocket/ASR_client.py
+++ b/funasr/runtime/python/websocket/ASR_client.py
@@ -5,13 +5,35 @@
 import asyncio
 from queue import Queue
 # import threading
+import argparse
+
+parser = argparse.ArgumentParser()
+parser.add_argument("--host",
+                    type=str,
+                    default="localhost",
+                    required=False,
+                    help="host ip, localhost, 0.0.0.0")
+parser.add_argument("--port",
+                    type=int,
+                    default=10095,
+                    required=False,
+                    help="grpc server port")
+parser.add_argument("--chunk_size",
+                    type=int,
+                    default=300,
+                    help="ms")
+
+args = parser.parse_args()
+
 voices = Queue()
-async def hello():
+async def ws_client():
     global ws # 瀹氫箟涓�涓叏灞�鍙橀噺ws锛岀敤浜庝繚瀛榳ebsocket杩炴帴瀵硅薄
-    uri = "ws://localhost:8899"
+    # uri = "ws://11.167.134.197:8899"
+    uri = "ws://{}:{}".format(args.host, args.port)
     ws = await websockets.connect(uri, subprotocols=["binary"]) # 鍒涘缓涓�涓暱杩炴帴
     ws.max_size = 1024 * 1024 * 20
     print("connected ws server")
+    
 async def send(data):
     global ws # 寮曠敤鍏ㄥ眬鍙橀噺ws
     try:
@@ -21,7 +43,7 @@
     
 
 
-asyncio.get_event_loop().run_until_complete(hello()) # 鍚姩鍗忕▼  
+asyncio.get_event_loop().run_until_complete(ws_client()) # 鍚姩鍗忕▼
 
 
 # 鍏朵粬鍑芥暟鍙互閫氳繃璋冪敤send(data)鏉ュ彂閫佹暟鎹紝渚嬪锛�
@@ -31,7 +53,7 @@
     FORMAT = pyaudio.paInt16
     CHANNELS = 1
     RATE = 16000
-    CHUNK = int(RATE / 1000 * 300)
+    CHUNK = int(RATE / 1000 * args.chunk_size)
 
     p = pyaudio.PyAudio()
 
@@ -70,4 +92,4 @@
      
     await asyncio.gather(task, task2)
 
-asyncio.run(main())
\ No newline at end of file
+asyncio.run(main())

--
Gitblit v1.9.1