From 7e63de52f02c51b2c221de21a951fffa6d2130af Mon Sep 17 00:00:00 2001 From: zhifu gao <zhifu.gzf@alibaba-inc.com> Date: 星期三, 17 五月 2023 00:05:31 +0800 Subject: [PATCH] Merge pull request #519 from alibaba-damo-academy/main --- funasr/runtime/python/websocket/ws_server_online.py | 18 +++++++++++++++--- 1 files changed, 15 insertions(+), 3 deletions(-) diff --git a/funasr/runtime/python/websocket/ws_server_online.py b/funasr/runtime/python/websocket/ws_server_online.py index a35b127..16a3abe 100644 --- a/funasr/runtime/python/websocket/ws_server_online.py +++ b/funasr/runtime/python/websocket/ws_server_online.py @@ -7,7 +7,7 @@ import logging import tracemalloc import numpy as np - +import ssl from parse_args import args from modelscope.pipelines import pipeline from modelscope.utils.constant import Tasks @@ -53,6 +53,9 @@ if "is_speaking" in messagejson: websocket.is_speaking = messagejson["is_speaking"] websocket.param_dict_asr_online["is_final"] = not websocket.is_speaking + # need to fire engine manually if no data received any more + if not websocket.is_speaking: + await async_asr_online(websocket,b"") if "chunk_interval" in messagejson: websocket.chunk_interval=messagejson["chunk_interval"] if "wav_name" in messagejson: @@ -82,7 +85,7 @@ async def async_asr_online(websocket,audio_in): - if len(audio_in) > 0: + if len(audio_in) >=0: audio_in = load_bytes(audio_in) rec_result = inference_pipeline_asr_online(audio_in=audio_in, param_dict=websocket.param_dict_asr_online) @@ -94,7 +97,16 @@ await websocket.send(message) +if len(args.certfile)>0: + ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) -start_server = websockets.serve(ws_serve, args.host, args.port, subprotocols=["binary"], ping_interval=None) + # Generate with Lets Encrypt, copied to this location, chown to current user and 400 permissions + ssl_cert = args.certfile + ssl_key = args.keyfile + + ssl_context.load_cert_chain(ssl_cert, keyfile=ssl_key) + start_server = websockets.serve(ws_serve, args.host, args.port, subprotocols=["binary"], ping_interval=None,ssl=ssl_context) +else: + start_server = websockets.serve(ws_serve, args.host, args.port, subprotocols=["binary"], ping_interval=None) asyncio.get_event_loop().run_until_complete(start_server) asyncio.get_event_loop().run_forever() \ No newline at end of file -- Gitblit v1.9.1