from flask import Flask, request, Markup, abort, jsonify from flask_cors import CORS import logging from logging.config import dictConfig import sys import base64 import torch import numpy as np from scipy.io.wavfile import write, read from datetime import datetime import traceback import struct 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 dictConfig({ 'version': 1, 'formatters': {'default': { 'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s', }}, 'handlers': {'wsgi': { 'class': 'logging.StreamHandler', 'stream': 'ext://flask.logging.wsgi_errors_stream', 'formatter': 'default' }}, 'root': { 'level': 'INFO', 'handlers': ['wsgi'] } }) app = Flask(__name__, static_folder="/voice-changer-internal/frontend/dist", static_url_path='/') CORS(app, resources={r"/*": {"origins": "*"}}) class VoiceChanger(): def __init__(self, config, model): 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_request(self, gpu, srcId, dstId, timestamp, wav): if wav==0: samplerate, data=read("dummy.wav") unpackedData = data else: unpackedData = np.array(struct.unpack('<%sh'%(len(wav) // struct.calcsize('