This commit is contained in:
yumoqing 2024-01-31 16:50:21 +08:00
parent 3dd1dca6dd
commit 73019d6107

View File

@ -2,14 +2,13 @@ from io import BytesIO
from TTS.utils.manage import ModelManager from TTS.utils.manage import ModelManager
from TTS.utils.synthesizer import Synthesizer from TTS.utils.synthesizer import Synthesizer
import numpy as np import numpy as np
from logmmse import logmmse # from logmmse import logmmse
from scipy.io.wavfile import write from scipy.io.wavfile import write
from ahserver.serverenv import ServerEnv from ahserver.serverenv import ServerEnv
class CoquiTTS: class CoquiTTS:
def __init__(self, model_name): def __init__(self, model_name):
manager = ModelManager() self.manager = ModelManager()
# model_path, config_path, model_item = manager.download_model("tts_models/zh-CN/baker/tacotron2-DDC-GST")
model_path, config_path, model_item = manager.download_model(model_name) model_path, config_path, model_item = manager.download_model(model_name)
print(f'reult={model_path=}, {config_path=}, {model_item=}') print(f'reult={model_path=}, {config_path=}, {model_item=}')
self.synthesizer = Synthesizer( self.synthesizer = Synthesizer(
@ -17,6 +16,7 @@ class CoquiTTS:
) )
def generate(self, text): def generate(self, text):
"""
wavs = self.synthesizer.tts(text) wavs = self.synthesizer.tts(text)
enhanced = logmmse(np.array(wavs, dtype=np.float32), enhanced = logmmse(np.array(wavs, dtype=np.float32),
self.synthesizer.output_sample_rate, self.synthesizer.output_sample_rate,
@ -28,4 +28,11 @@ class CoquiTTS:
write(b, self.synthesizer.output_sample_rate, enhanced) write(b, self.synthesizer.output_sample_rate, enhanced)
b.seek(0,0) b.seek(0,0)
buf = b.read() buf = b.read()
"""
wavs = self.synthesizer.tts(text)
data = np.array(wavs, dtype=np.float32)
b = BytesIO()
write(b, self.synthesizer.output_sample_rate, data)
b.seek(0,0)
buf = b.read()
return buf return buf