import eventlet import socketio import sys,os , math, struct, argparse, logging from distutils.util import strtobool from datetime import datetime from OpenSSL import SSL, crypto import torch, torchaudio import numpy as np from scipy.io.wavfile import write, read sys.path.append("/hubert") from hubert import hubert_discrete, hubert_soft, kmeans100 sys.path.append("/acoustic-model") from acoustic import hubert_discrete, hubert_soft sys.path.append("/hifigan") from hifigan import hifigan hubert_model = torch.load("/models/bshall_hubert_main.pt").cuda() acoustic_model = torch.load("/models/bshall_acoustic-model_main.pt").cuda() hifigan_model = torch.load("/models/bshall_hifigan_main.pt").cuda() def applyVol(i, chunk, vols): curVol = vols[i] / 2 if curVol < 0.0001: line = torch.zeros(chunk.size()) else: line = torch.ones(chunk.size()) volApplied = torch.mul(line, chunk) volApplied = volApplied.unsqueeze(0) return volApplied class MyCustomNamespace(socketio.Namespace): def __init__(self, namespace): super().__init__(namespace) def on_connect(self, sid, environ): print('[{}] connet sid : {}'.format(datetime.now().strftime('%Y-%m-%d %H:%M:%S') , sid)) def on_request_message(self, sid, msg): # print("Processing Request...") gpu = int(msg[0]) srcId = int(msg[1]) dstId = int(msg[2]) timestamp = int(msg[3]) data = msg[4] # print(srcId, dstId, timestamp) unpackedData = np.array(struct.unpack('<%sh'%(len(data) // struct.calcsize(':/ with your browser.", level=0) else: printMessage(f"open http://:/ with your browser.", level=0) if EX_PORT and EX_IP and args.https == 1: printMessage(f"In many cases it is one of the following", level=1) printMessage(f"https://localhost:{EX_PORT}/", level=1) for ip in EX_IP.strip().split(" "): printMessage(f"https://{ip}:{EX_PORT}/", level=1) elif EX_PORT and EX_IP and args.https == 0: printMessage(f"In many cases it is one of the following", level=1) printMessage(f"http://localhost:{EX_PORT}/", level=1) # for ip in EX_IP.strip().split(" "): # print(f" http://{ip}:{EX_PORT}/") # SocketIOセットアップ sio = socketio.Server(cors_allowed_origins='*') sio.register_namespace(MyCustomNamespace('/test')) app = socketio.WSGIApp(sio,static_files={ '': '../frontend/dist', '/': '../frontend/dist/index.html', }) ### log を設定すると通常出力されないログが取得できるようだ。(ログ出力抑制には役立たない?) # logger = logging.getLogger("logger") # logger.propagate=False # handler = logging.FileHandler(filename="logger.log") # logger.addHandler(handler) if args.https: # HTTPS サーバ起動 sslWrapper = eventlet.wrap_ssl( eventlet.listen(('0.0.0.0',int(PORT))), certfile=cert_path, keyfile=key_path, # server_side=True ) ### log を設定すると通常出力されないログが取得できるようだ。(ログ出力抑制には役立たない?) # eventlet.wsgi.server(sslWrapper, app, log=logger) eventlet.wsgi.server(sslWrapper, app) else: # HTTP サーバ起動 ### log を設定すると通常出力されないログが取得できるようだ。(ログ出力抑制には役立たない?) # eventlet.wsgi.server(eventlet.listen(('0.0.0.0',int(PORT))), app, log=logger) eventlet.wsgi.server(eventlet.listen(('0.0.0.0',int(PORT))), app)