结构如图
代码如下:
import ChatTTS
import torch
import torchaudio
chat = ChatTTS.Chat()
chat.load(compile=False) # Set to True for better performance
texts = ["PUT YOUR 1st TEXT HERE", "PUT YOUR 2nd TEXT HERE"]
wavs = chat.infer(texts)
for i in range(len(wavs)):
"""
In some versions of torchaudio, the first line works but in other versions, so does the second line.
"""
try:
torchaudio.save(f"basic_output{i}.wav", torch.from_numpy(wavs[i]).unsqueeze(0), 24000)
except:
torchaudio.save(f"basic_output{i}.wav", torch.from_numpy(wavs[i]), 24000)
运行如下:
(chattts) duyicheng@duyicheng-computer:~/gitee/ChatTTS$ python base.py
found invalid characters: {'1'}
found invalid characters: {'2'}
text: 0%|▍ | 1/384(max) [00:00, 2.24it/s]We detected that you are passing `past_key_values` as a tuple of tuples. This is deprecated and will be removed in v4.47. Please convert your cache or use an appropriate `Cache` class (https://huggingface.co/docs/transformers/kv_cache#legacy-cache-format)
text: 3%|████▋ | 10/384(max) [00:00, 13.17it/s]
code: 4%|██████▊ | 77/2048(max) [00:02, 31.63it/s]
(chattts) duyicheng@duyicheng-computer:~/gitee/ChatTTS$
音质还行。