import eventlet import socketio import sys, os, struct, argparse, logging from distutils.util import strtobool from datetime import datetime from OpenSSL import SSL, crypto import torch import numpy as np from scipy.io.wavfile import write sys.path.append("mod") sys.path.append("mod/text") import utils from data_utils import TextAudioSpeakerLoader, TextAudioSpeakerCollate from models import SynthesizerTrn from text.symbols import symbols class MyCustomNamespace(socketio.Namespace): def __init__(self, namespace, config, model): super().__init__(namespace) self.hps =utils.get_hparams_from_file(config) self.net_g = SynthesizerTrn( len(symbols), self.hps.data.filter_length // 2 + 1, self.hps.train.segment_size // self.hps.data.hop_length, n_speakers=self.hps.data.n_speakers, **self.hps.model) self.net_g.eval() self.gpu_num = torch.cuda.device_count() print("GPU_NUM:",self.gpu_num) utils.load_checkpoint( model, self.net_g, None) def on_connect(self, sid, environ): print('[{}] connet sid : {}'.format(datetime.now().strftime('%Y-%m-%d %H:%M:%S') , sid)) # print('[{}] connet env : {}'.format(datetime.now().strftime('%Y-%m-%d %H:%M:%S') , environ)) def on_request_message(self, sid, msg): # print("MESSGaa", msg) 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', CONFIG, MODEL)) 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)