游雁
2023-04-27 a917d7557dd2b1e5263eeba7e5e4d5a5fc02f69f
websocket
2个文件已修改
28 ■■■■ 已修改文件
funasr/runtime/python/websocket/ASR_client.py 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
funasr/runtime/python/websocket/ASR_server_streaming_asr.py 22 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
funasr/runtime/python/websocket/ASR_client.py
@@ -59,7 +59,7 @@
        voices.put(message)
        #print(voices.qsize())
        await asyncio.sleep(0.01)
        await asyncio.sleep(0.005)
# 其他函数可以通过调用send(data)来发送数据,例如:
async def record_from_scp():
@@ -116,8 +116,8 @@
                await websocket.send(data) # 通过ws对象发送数据
            except Exception as e:
                print('Exception occurred:', e)
            await asyncio.sleep(0.01)
        await asyncio.sleep(0.01)
            await asyncio.sleep(0.005)
        await asyncio.sleep(0.005)
funasr/runtime/python/websocket/ASR_server_streaming_asr.py
@@ -89,6 +89,8 @@
    websocket.speek_online = Queue()
    ss_online = threading.Thread(target=asr_online, args=(websocket,))
    ss_online.start()
    ss_ws_send = threading.Thread(target=ws_send, args=(websocket,))
    ss_ws_send.start()
    try:
        async for message in websocket:
            message = json.loads(message)
@@ -104,9 +106,9 @@
                websocket.speek_online.put(audio_in)
                frames_online = []
            if not websocket.send_msg.empty():
                await websocket.send(websocket.send_msg.get())
                websocket.send_msg.task_done()
            # if not websocket.send_msg.empty():
            #     await websocket.send(websocket.send_msg.get())
            #     websocket.send_msg.task_done()
     
    except websockets.ConnectionClosed:
@@ -119,11 +121,20 @@
 
def asr_online(websocket):  # ASR推理
def ws_send(websocket):  # ASR推理
    global inference_pipeline_asr_online
    global websocket_users
    while websocket in websocket_users:
        if not websocket.speek_online.empty():
            await websocket.send(websocket.send_msg.get())
            websocket.send_msg.task_done()
        time.sleep(0.005)
def asr_online(websocket):  # ASR推理
    global websocket_users
    while websocket in websocket_users:
        if not websocket.send_msg.empty():
            audio_in = websocket.speek_online.get()
            websocket.speek_online.task_done()
            if len(audio_in) > 0:
@@ -131,7 +142,8 @@
                audio_in = load_bytes(audio_in)
                # print(audio_in.shape)
                print(websocket.param_dict_asr_online["is_final"])
                rec_result = inference_pipeline_asr_online(audio_in=audio_in, param_dict=websocket.param_dict_asr_online)
                rec_result = inference_pipeline_asr_online(audio_in=audio_in,
                                                           param_dict=websocket.param_dict_asr_online)
                if websocket.param_dict_asr_online["is_final"]:
                    websocket.param_dict_asr_online["cache"] = dict()