From b8dd1e310b631cba7f8124ff30783ea60026b724 Mon Sep 17 00:00:00 2001
From: zhaomingwork <61895407+zhaomingwork@users.noreply.github.com>
Date: 星期三, 24 五月 2023 15:43:48 +0800
Subject: [PATCH] add ssl for ws_clinet and 2pass offline srv (#546)
---
funasr/runtime/python/websocket/ws_client.py | 19 ++++++++++++++++---
1 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/funasr/runtime/python/websocket/ws_client.py b/funasr/runtime/python/websocket/ws_client.py
index de5a1d8..f7dfcaf 100644
--- a/funasr/runtime/python/websocket/ws_client.py
+++ b/funasr/runtime/python/websocket/ws_client.py
@@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
import os
import time
-import websockets
+import websockets,ssl
import asyncio
# import threading
import argparse
@@ -53,6 +53,11 @@
type=str,
default=None,
help="output_dir")
+
+parser.add_argument("--ssl",
+ type=int,
+ default=1,
+ help="1 for ssl connect, 0 for no ssl")
args = parser.parse_args()
args.chunk_size = [int(x) for x in args.chunk_size.split(",")]
@@ -221,8 +226,16 @@
async def ws_client(id,chunk_begin,chunk_size):
global websocket
- uri = "ws://{}:{}".format(args.host, args.port)
- async for websocket in websockets.connect(uri, subprotocols=["binary"], ping_interval=None):
+ if args.ssl==1:
+ ssl_context = ssl.SSLContext()
+ ssl_context.check_hostname = False
+ ssl_context.verify_mode = ssl.CERT_NONE
+ uri = "wss://{}:{}".format(args.host, args.port)
+ else:
+ uri = "ws://{}:{}".format(args.host, args.port)
+ ssl_context=None
+ print("connect to",uri)
+ async for websocket in websockets.connect(uri, subprotocols=["binary"], ping_interval=None,ssl=ssl_context):
if args.audio_in is not None:
task = asyncio.create_task(record_from_scp(chunk_begin,chunk_size))
else:
--
Gitblit v1.9.1