| | |
| | | # -*- encoding: utf-8 -*- |
| | | import os |
| | | import time |
| | | import websockets |
| | | import websockets,ssl |
| | | import asyncio |
| | | # import threading |
| | | import argparse |
| | |
| | | help="test_thread_num") |
| | | parser.add_argument("--words_max_print", |
| | | type=int, |
| | | default=100, |
| | | default=10000, |
| | | help="chunk") |
| | | parser.add_argument("--output_dir", |
| | | 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(",")] |
| | |
| | | ibest_writer["text"][wav_name] = text |
| | | |
| | | if meg["mode"] == "online": |
| | | text_print += " {}".format(text) |
| | | text_print += "{}".format(text) |
| | | text_print = text_print[-args.words_max_print:] |
| | | os.system('clear') |
| | | print("\rpid"+str(id)+": "+text_print) |
| | |
| | | print("\rpid"+str(id)+": "+text_print) |
| | | else: |
| | | if meg["mode"] == "2pass-online": |
| | | text_print_2pass_online += " {}".format(text) |
| | | text_print_2pass_online += "{}".format(text) |
| | | text_print = text_print_2pass_offline + text_print_2pass_online |
| | | else: |
| | | text_print_2pass_online = "" |
| | |
| | | |
| | | 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: |
| | |
| | | |
| | | |
| | | if __name__ == '__main__': |
| | | process_list = [] |
| | | for i in range(args.test_thread_num): |
| | | p = Process(target=one_thread,args=(i, 0, 0)) |
| | | p.start() |
| | | process_list.append(p) |
| | | # for microphone |
| | | if args.audio_in is None: |
| | | p = Process(target=one_thread,args=(0, 0, 0)) |
| | | p.start() |
| | | p.join() |
| | | print('end') |
| | | else: |
| | | # calculate the number of wavs for each preocess |
| | | if args.audio_in.endswith(".scp"): |
| | | f_scp = open(args.audio_in) |
| | | wavs = f_scp.readlines() |
| | | else: |
| | | wavs = [args.audio_in] |
| | | total_len=len(wavs) |
| | | if total_len>=args.test_thread_num: |
| | | chunk_size=int((total_len)/args.test_thread_num) |
| | | remain_wavs=total_len-chunk_size*args.test_thread_num |
| | | else: |
| | | chunk_size=1 |
| | | remain_wavs=0 |
| | | |
| | | for i in process_list: |
| | | p.join() |
| | | process_list = [] |
| | | chunk_begin=0 |
| | | for i in range(args.test_thread_num): |
| | | now_chunk_size= chunk_size |
| | | if remain_wavs>0: |
| | | now_chunk_size=chunk_size+1 |
| | | remain_wavs=remain_wavs-1 |
| | | # process i handle wavs at chunk_begin and size of now_chunk_size |
| | | p = Process(target=one_thread,args=(i,chunk_begin,now_chunk_size)) |
| | | chunk_begin=chunk_begin+now_chunk_size |
| | | p.start() |
| | | process_list.append(p) |
| | | |
| | | print('end') |
| | | for i in process_list: |
| | | p.join() |
| | | |
| | | # |
| | | # if __name__ == '__main__': |
| | | # # calculate the number of wavs for each preocess |
| | | # if args.audio_in.endswith(".scp"): |
| | | # f_scp = open(args.audio_in) |
| | | # wavs = f_scp.readlines() |
| | | # else: |
| | | # wavs = [args.audio_in] |
| | | # total_len=len(wavs) |
| | | # if total_len>=args.test_thread_num: |
| | | # chunk_size=int((total_len)/args.test_thread_num) |
| | | # remain_wavs=total_len-chunk_size*args.test_thread_num |
| | | # else: |
| | | # chunk_size=0 |
| | | # |
| | | # process_list = [] |
| | | # chunk_begin=0 |
| | | # for i in range(args.test_thread_num): |
| | | # now_chunk_size= chunk_size |
| | | # if remain_wavs>0: |
| | | # now_chunk_size=chunk_size+1 |
| | | # remain_wavs=remain_wavs-1 |
| | | # # process i handle wavs at chunk_begin and size of now_chunk_size |
| | | # p = Process(target=one_thread,args=(i,chunk_begin,now_chunk_size)) |
| | | # chunk_begin=chunk_begin+now_chunk_size |
| | | # p.start() |
| | | # process_list.append(p) |
| | | # |
| | | # for i in process_list: |
| | | # p.join() |
| | | # |
| | | # print('end') |
| | | # |
| | | print('end') |
| | | |
| | | |