ChatTTS部署与测试

前言

ChatTTS 是专门为对话场景(如 LLM 助手)设计的文本到语音模型。

官网

https://chattts.com/zh

安装部署

代码克隆

1
2
git clone https://gitcode.com/gh_mirrors/ch/ChatTTS.git
cd ChatTTS

使用 conda 安装

1
2
3
conda create -n chattts python=3.11
conda activate chattts
pip install -r requirements.txt

测试

1
python examples/cmd/run.py "你好" "我是小爱同学"

代码调用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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)

一键安装包

Windows版

网盘分享的文件:ChatTTS-UI-0.85.7z
链接: https://pan.baidu.com/s/1lt9VG2JQSzcsJeNyq0r58A?pwd=fb98 提取码: fb98