import eventlet import socketio import sys from datetime import datetime import struct 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('