https://chattts.com/

ChatTTS - 适用于对话场景的文本转语音
针对自然、对话式的文本转语音进行了优化

什么是 ChatTTS?

ChatTTS 是专为对话场景设计的语音生成模型,专门用于大型语言模型 (LLM) 助手的对话任务,以及对话式音频和视频介绍等应用。它支持中英文,通过使用约 10 万小时的中英文数据进行训练,ChatTTS 在语音合成方面表现出很高的质量和自然度。

ChatTTS 功能

  • 多语言支持

ChatTTS 的主要功能之一是支持多种语言,包括英语和中文。这使得它能够服务广泛的用户并克服语言障碍

  • 大数据培训

ChatTTS 使用大量数据进行训练,约 1000 万小时的中文和英文数据。经过大量训练,语音合成质量高、发音自然

  • 对话任务兼容性

ChatTTS 非常适合处理通常分配给大型语言模型 LLM 的对话任务。它可以生成对话响应,并在集成到各种应用程序和服务中时提供更自然、更流畅的交互体验

  • 开源计划

项目团队计划开源已训练的基础模型。这将使社区的学术研究人员和开发人员能够进一步研究和开发该技术

  • 控制和安全

团队致力于提高模型的可控性、添加水印、与LLM集成等,这些努力保证了模型的安全性和可靠性

  • 使用方便

ChatTTS 为用户提供了易于使用的体验。它只需要输入文本信息,即可生成相应的语音文件。这种简单性为有语音合成需求的用户提供了便利

如何使用 ChatTTS?

让我们通过几个简单的步骤开始使用 ChatTTS。

1、从 GitHub 下载

从 GitHub 下载代码。

git clone https://github.com/2noise/ChatTTS

下载 ChatTTS

2、安装依赖项

开始之前,请确保已安装必要的软件包。您将需要 torch 和 ChatTTS。如果尚未安装它们,可以使用 pip 安装:

pip install torch ChatTTS
3、导入所需库

导入脚本所需的库。你需要 torch、ChatTTS 和 IPython.display 中的 Audio

import torch
import ChatTTS
from IPython.display import Audio
4、初始化 ChatTTS

创建ChatTTS类的实例并加载预先训练的模型。

chat = ChatTTS.Chat()
chat.load_models()
5、准备文本

定义要转换为语音的文本。将 <YOUR TEXT HERE> 替换为您想要的文本。

texts = ["Hello, welcome to ChatTTS!",]
6、生成语音

使用 infer 方法从文本生成语音。设置 use_decoder=True 以启用解码器。

wavs = chat.infer(texts, use_decoder=True)
7、播放音频

使用 IPython.display 中的 Audio 类播放生成的音频。将采样率设置为 24,000 Hz 并启用自动播放。

Audio(wavs[0], rate=24_000, autoplay=True)
8、完整脚本

以下是完整的脚本,供参考:

import torch
import ChatTTS
from IPython.display import Audio

# Initialize ChatTTS
chat = ChatTTS.Chat()
chat.load_models()

# Define the text to be converted to speech
texts = ["Hello, welcome to ChatTTS!",]

# Generate speech
wavs = chat.infer(texts, use_decoder=True)

# Play the generated audio
Audio(wavs[0], rate=24_000, autoplay=True)

模型调用:

# Import necessary libraries and configure settings
import torch
import torchaudio
torch._dynamo.config.cache_size_limit = 64
torch._dynamo.config.suppress_errors = True
torch.set_float32_matmul_precision('high')

import ChatTTS
from IPython.display import Audio

# Initialize and load the model: 
chat = ChatTTS.Chat()
chat.load_models(compile=False) # Set to True for better performance

# Define the text input for inference (Support Batching)
texts = [
    "So we found being competitive and collaborative was a huge way of staying motivated towards our goals, so one person to call when you fall off, one person who gets you back on then one person to actually do the activity with.",
    ]

# Perform inference and play the generated audio
wavs = chat.infer(texts)
Audio(wavs[0], rate=24_000, autoplay=True)

# Save the generated audio 
torchaudio.save("output.wav", torch.from_numpy(wavs[0]), 24000)
作者:Jeebiz  创建时间:2024-06-05 22:34
最后编辑:Jeebiz  更新时间:2025-05-12 09:20