from TTS.utils.manage import ModelManager
from TTS.utils.synthesizer import Synthesizer

manager = ModelManager()
model_path, config_path, model_item = manager.download_model("tts_models/zh-CN/baker/tacotron2-DDC-GST")
synthesizer = Synthesizer(
    model_path, config_path, None, None, None,
)

def tts(text):
    wavs = synthesizer.tts(text)
    txt_without_mark = text.replace("？", "").replace("。", "").replace("，", "").replace("！", "").replace("：", "").replace("；", "")
    print(txt_without_mark)
    fn = "s"+ txt_without_mark + ".wav"
    synthesizer.save_wav(wavs, fn)
    
    
    #synthesizer.save_wav(wavs, "tts.wav")
    return wavs

tts("你好吗？我很好。")
tts("十四五期间改造投资将超万亿。")
tts("拜登特朗普锁定各自党派提名, 美大选将上演二次对决。")


#example_text = '你好吗？我很好。'
#wavs = synthesizer.tts(example_text)
#synthesizer.save_wav(wavs, "tts.wav")



#display(Audio(wavs, rate=synthesizer.output_sample_rate))

