This commit is contained in:
superobk
2024-03-27 16:10:46 +08:00
parent 0549a033e1
commit 229501515a
6 changed files with 41 additions and 20 deletions

View File

@ -1,10 +1,8 @@
import io
import sys
import time
sys.path.append('tts/vits')
import numpy as np
import soundfile
import os
os.environ["PYTORCH_JIT"] = "0"
@ -21,20 +19,43 @@ import logging
logging.getLogger().setLevel(logging.INFO)
logging.basicConfig(level=logging.INFO)
dirbaspath = __file__.split("\\")[1:-1]
dirbaspath= "C://" + "/".join(dirbaspath)
config = {
'paimon': {
'cfg': dirbaspath + '/models/paimon6k.json',
'model': dirbaspath + '/models/paimon6k_390k.pth',
'char': 'character_paimon',
'speed': 1
},
'yunfei': {
'cfg': dirbaspath + '/tts/models/yunfeimix2.json',
'model': dirbaspath + '/models/yunfeimix2_53k.pth',
'char': 'character_yunfei',
'speed': 1.1
},
'catmaid': {
'cfg': dirbaspath + '/models/catmix.json',
'model': dirbaspath + '/models/catmix_107k.pth',
'char': 'character_catmaid',
'speed': 1.2
},
}
class TTService():
def __init__(self, cfg, model, char, speed):
logging.info('Initializing TTS Service for %s...' % char)
self.hps = utils.get_hparams_from_file(cfg)
self.speed = speed
def __init__(self, model_name="catmaid"):
cfg = config[model_name]
logging.info('Initializing TTS Service for %s...' % cfg["char"])
self.hps = utils.get_hparams_from_file(cfg["cfg"])
self.speed = cfg["speed"]
self.net_g = SynthesizerTrn(
len(symbols),
self.hps.data.filter_length // 2 + 1,
self.hps.train.segment_size // self.hps.data.hop_length,
**self.hps.model).cpu()
_ = self.net_g.eval()
_ = utils.load_checkpoint(model, self.net_g, None)
_ = utils.load_checkpoint(cfg["model"], self.net_g, None)
def get_text(self, text, hps):
text_norm = text_to_sequence(text, hps.data.text_cleaners)