import ChatTTS import scipy import torch chat = ChatTTS.Chat() chat.load('custom', custom_path='./chatTTS', compile=False)
随机生成音色,俗称抽奖,抽的我心碎了
rand_spk = chat.sample_random_speaker()
读取保存的音色模型
spk = chat._encode_spk_emb(torch.load('./seed_2155_restored_emb.pt')) params_infer_code = ChatTTS.Chat.InferCodeParams( spk_emb = spk, # add sampled speaker temperature = .3, # using custom temperature top_P = 0.7, # top P decode top_K = 20, # top K decode ) text = '最初的鸟儿是不会飞翔的,飞翔是他们勇敢跃入峡谷的奖励,重要的是勇气,是它让你们成为世上最初的飞鸟。' ################################### text1 = chat.infer(text, refine_text_only=True)
refine_text_only=True:自动添加语气词
[oral_0]:连接词,嗯呐,哦,就是之类的词
[laugh_0]:笑声
[break_0]:停顿
print(text1) wavs = chat.infer(text1, params_infer_code=params_infer_code) scipy.io.wavfile.write(filename = "output.wav", rate = 24_000, data = wavs[0].T)