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