> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-zh/yin-pin-yu-yu-yin/zonos-tts.md).

# Zonos TTS 声音克隆

在 Clore.ai GPU 上运行 Zyphra 的 Zonos TTS，用于带情感和音高控制的声音克隆。

由 Zonos 提供 [Zyphra](https://www.zyphra.com/) 是一个 0.4B 参数的开权重文本转语音模型，在 20 万小时以上的多语种语音上训练而成。它只需 2–30 秒的参考音频即可进行零样本声音克隆，并提供对情感、语速、音高变化和音频质量的细粒度控制。输出为高保真 44 kHz 音频。提供两种模型变体：Transformer（最佳质量）和 Hybrid/Mamba（更快推理）。

**GitHub：** [Zyphra/Zonos](https://github.com/Zyphra/Zonos) **HuggingFace：** [Zyphra/Zonos-v0.1-transformer](https://huggingface.co/Zyphra/Zonos-v0.1-transformer) **许可证：** Apache 2.0

## 主要特性

* **从 2–30 秒进行声音克隆** — 无需微调
* **44 kHz 高保真输出** — 工作室级音频质量
* **情感控制** — 通过 8D 向量控制快乐、悲伤、愤怒、恐惧、惊讶、厌恶
* **语速与音高** — 独立的细粒度控制
* **音频前缀输入** — 支持耳语及其他难以克隆的行为
* **多语言** — 英语、日语、中文、法语、德语
* **两种架构** — Transformer（质量）和 Hybrid/Mamba（速度，在 RTX 4090 上约 2× 实时）
* **Apache 2.0** — 可免费用于个人和商业用途

## 需求

| 组件     | 最低                | 推荐             |
| ------ | ----------------- | -------------- |
| GPU    | RTX 3080 10 GB    | RTX 4090 24 GB |
| 显存     | 6 GB（Transformer） | 10 GB+         |
| 内存     | 16 GB             | 32 GB          |
| 磁盘     | 10 GB             | 20 GB          |
| Python | 3.10+             | 3.11           |
| CUDA   | 12.8+             | 12.8+          |
| 系统     | espeak-ng         | —              |

**Clore.ai 推荐：** RTX 3090（$0.07–0.21/小时），具有舒适余量。RTX 4090（$0.14–0.42/小时）适用于 Hybrid 模型和最快推理。

## 安装

```bash
# 安装系统依赖
apt-get install -y espeak-ng

# 克隆并安装
git clone https://github.com/Zyphra/Zonos.git
cd Zonos
pip install -e .

# 对于 Hybrid 模型（需要 Ampere+ GPU，即 RTX 3000 系列或更新）
pip install -e ".[compile]"

# 验证
python -c "from zonos.model import Zonos; print('Zonos 已就绪')"
```

## 快速开始

```python
import torch
import torchaudio
from zonos.model import Zonos
from zonos.conditioning import make_cond_dict

# 加载模型（首次运行时会下载权重）
model = Zonos.from_pretrained("Zyphra/Zonos-v0.1-transformer", device="cuda")

# 加载用于声音克隆的参考音频
wav, sr = torchaudio.load("reference_speaker.wav")
speaker = model.make_speaker_embedding(wav, sr)

# 构建条件信息
cond_dict = make_cond_dict(
    text="来自 Clore.ai 的问候！这是一个声音克隆演示。",
    speaker=speaker,
    language="en-us",
)
conditioning = model.prepare_conditioning(cond_dict)

# 生成
torch.manual_seed(42)
codes = model.generate(conditioning)
wavs = model.autoencoder.decode(codes).cpu()

torchaudio.save("output.wav", wavs[0], model.autoencoder.sampling_rate)
print(f"已将 output.wav 保存为 {model.autoencoder.sampling_rate} Hz")
```

## 使用示例

### 情感控制

Zonos 接受一个 8 维情感向量： `[快乐、悲伤、厌恶、恐惧、惊讶、愤怒、其他、中性]`.

```python
import torch
import torchaudio
from zonos.model import Zonos
from zonos.conditioning import make_cond_dict

model = Zonos.from_pretrained("Zyphra/Zonos-v0.1-transformer", device="cuda")

wav, sr = torchaudio.load("speaker_ref.wav")
speaker = model.make_speaker_embedding(wav, sr)

text = "我简直不敢相信今天刚刚发生的事！"

emotions = {
    "happy":   [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
    "sad":     [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
    "angry":   [0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0],
    "fearful": [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0],
    "neutral": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0],
}

for name, emo_vec in emotions.items():
    cond_dict = make_cond_dict(
        text=text,
        speaker=speaker,
        language="en-us",
        emotion=torch.tensor(emo_vec).unsqueeze(0),
    )
    conditioning = model.prepare_conditioning(cond_dict)
    codes = model.generate(conditioning)
    audio = model.autoencoder.decode(codes).cpu()
    torchaudio.save(f"emotion_{name}.wav", audio[0], model.autoencoder.sampling_rate)
    print(f"已生成：{name}")
```

### 语速和音高控制

```python
import torch
import torchaudio
from zonos.model import Zonos
from zonos.conditioning import make_cond_dict

model = Zonos.from_pretrained("Zyphra/Zonos-v0.1-transformer", device="cuda")

wav, sr = torchaudio.load("speaker_ref.wav")
speaker = model.make_speaker_embedding(wav, sr)

# 缓慢而平静
cond_slow = make_cond_dict(
    text="慢慢来，完全不用着急。",
    speaker=speaker,
    language="en-us",
    speaking_rate=torch.tensor([8.0]),   # 更低 = 更慢
    pitch_std=torch.tensor([20.0]),      # 更低 = 更单调
)
codes = model.generate(model.prepare_conditioning(cond_slow))
audio = model.autoencoder.decode(codes).cpu()
torchaudio.save("slow_calm.wav", audio[0], model.autoencoder.sampling_rate)

# 快速且充满活力
cond_fast = make_cond_dict(
    text="快点！我们现在就得走！",
    speaker=speaker,
    language="en-us",
    speaking_rate=torch.tensor([22.0]),  # 更高 = 更快
    pitch_std=torch.tensor([80.0]),      # 更高 = 更有表现力
)
codes = model.generate(model.prepare_conditioning(cond_fast))
audio = model.autoencoder.decode(codes).cpu()
torchaudio.save("fast_energetic.wav", audio[0], model.autoencoder.sampling_rate)
```

### Gradio Web 界面

```bash
cd Zonos
python gradio_interface.py
# 或使用 uv：
# uv run gradio_interface.py
```

开放端口 `7860/http` 在你的 Clore.ai 订单中，并打开 `http_pub` URL 以访问 UI。

## 给 Clore.ai 用户的建议

* **模型选择** — Transformer 以获得最佳质量，Hybrid 以获得约 2× 更快的推理（需要 RTX 3000+ GPU）
* **参考音频** — 10–30 秒清晰语音效果最佳；较短的片段（2–5 秒）也可用，但保真度较低
* **Docker 设置** — 使用 `pytorch/pytorch:2.11.0-cuda12.8-cudnn9-runtime`，添加 `apt-get install -y espeak-ng` 到启动项
* **端口映射** — 公开 `7860/http` 用于 Gradio UI， `8000/http` 用于 API 服务器
* **随机种子控制** ——将 `torch.manual_seed()` 在生成前设置，以获得可复现的输出
* **音频质量参数** — 试试 `audio_quality` 条件字段，以获得更干净的输出

## 故障排查

| 问题                           | 解决方案                                                           |
| ---------------------------- | -------------------------------------------------------------- |
| `未找到 espeak-ng`              | 运行 `apt-get install -y espeak-ng` （音素化所需）                      |
| `CUDA 内存不足`                  | 使用 Transformer 模型（比 Hybrid 更小）；减少每次调用的文本长度                     |
| Hybrid 模型失败                  | 需要 Ampere+ GPU（RTX 3000 系列或更新）以及 `pip install -e ".[compile]"` |
| 克隆的声音听起来不对                   | 使用更长的参考片段（15–30 秒），确保语音清晰并尽量减少背景噪音                             |
| 生成缓慢                         | Transformer 属于正常现象（约 0.5× 实时）；Hybrid 在 RTX 4090 上可达到约 2× 实时    |
| `ModuleNotFoundError: zonos` | 请确保你是从源代码安装的： `cd Zonos && pip install -e .`                   |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-zh/yin-pin-yu-yu-yin/zonos-tts.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
