# Kani-TTS-2 声音克隆

nineninesix.ai 的 Kani-TTS-2（发布于 2026 年 2 月 15 日）是一个 4 亿参数的开源文本转语音模型，仅使用 **3GB 显存**就能实现高保真语音合成。基于 LiquidAI 的 LFM2 架构并采用 NVIDIA NanoCodec，它将音频视为一种语言——通过短时参考音频片段进行零样本语音克隆以生成自然听感的语音。其规模不到竞争模型的一半、计算量也仅为其一小部分，非常适合在预算有限的硬件上用于实时对话式 AI、有声书生成和语音克隆。

**HuggingFace：** [nineninesix/kani-tts-2-en](https://huggingface.co/nineninesix/kani-tts-2-en) **GitHub：** [nineninesix-ai/kani-tts-2](https://github.com/nineninesix-ai/kani-tts-2) **PyPI：** [kani-tts-2](https://pypi.org/project/kani-tts-2/) **许可：** Apache 2.0

## 主要特性

* **4 亿参数，3GB 显存** — 几乎可在任何现代 GPU 上运行，包括 RTX 3060
* **零样本语音克隆** — 从 3–30 秒的参考音频样本中克隆任意声音
* **说话人嵌入** — 基于 WavLM 的 128 维说话人表示，用于精确的声音控制
* **最长可生成 40 秒连续音频** — 适用于较长段落和对话
* **实时或更快** — 在 RTX 5080 上 RTF 约为 0.2，即使在入门级 GPU 上也能实时运行
* **Apache 2.0** — 个人和商业用途均完全开源可用
* **包含预训练框架** — 可在任何语言上从头训练自己的 TTS 模型

## 与其他 TTS 模型的比较

| A100           | 参数量    | 最小显存 | 语音克隆   | 语言       | 许可           |
| -------------- | ------ | ---- | ------ | -------- | ------------ |
| **Kani-TTS-2** | 4 亿    | 3GB  | ✅ 零样本  | 英语（可扩展）  | Apache 2.0   |
| Kokoro         | 8200 万 | 2GB  | ❌ 预设声音 | 英语、日语、中文 | Apache 2.0   |
| Zonos          | 4 亿    | 8GB  | ✅      | 多 GPU    | Apache 2.0   |
| ChatTTS        | 3 亿    | 4GB  | ❌ 随机种子 | 中文，英文    | AGPL 3.0     |
| Chatterbox     | 5 亿    | 6GB  | ✅      | 英语       | Apache 2.0   |
| XTTS（Coqui）    | 4.67 亿 | 6GB  | ✅      | 多 GPU    | MPL 2.0      |
| F5-TTS         | 335M   | 4GB  | ✅      | 多 GPU    | CC-BY-NC 4.0 |

## 要求

| 组件     | 最低              | 推荐           |
| ------ | --------------- | ------------ |
| GPU    | 任何有 3GB 显存的 GPU | RTX 3060 或更好 |
| 显存     | 3GB             | 6GB          |
| 内存     | 8GB             | 16GB         |
| 磁盘     | 2GB             | 5GB          |
| Python | 3.9+            | 3.11+        |
| CUDA   | 11.8+           | 12.0+        |

**Clore.ai 建议：** 一块 RTX 3060（\~\~每天 $0.15–0.30）就绰绰有余。即使是 Clore.ai 上最便宜的 GPU 实例也能轻松运行 Kani-TTS-2。对于批量处理（有声书、数据集），一块 RTX 4090（\~\~每天 $0.5–2）能提供极佳的吞吐量。

## 安装

```bash
# 安装该软件包
pip install kani-tts-2

# 重要：安装兼容的 transformers 版本（LFM2 架构所需）
pip install -U "transformers==4.56.0"

# 可选：安装 soundfile 以保存音频
pip install soundfile
```

## 快速开始

生成语音的三行代码：

```python
from kani_tts import KaniTTS

# 使用英文模型初始化
model = KaniTTS('nineninesix/kani-tts-2-en')

# 生成语音
audio, text = model("Hello! Welcome to Kani TTS 2, the next generation of efficient text-to-speech.")

# 保存到文件
model.save_audio(audio, "output.wav")
```

## 使用示例

### 1. 基本文本转语音

```python
from kani_tts import KaniTTS

model = KaniTTS('nineninesix/kani-tts-2-en')

# 使用自定义参数生成
audio, text = model(
    "The quick brown fox jumps over the lazy dog. ",
    "This sentence contains every letter of the English alphabet.",
    temperature=0.7,
    top_p=0.9,
    repetition_penalty=1.1
)

model.save_audio(audio, "pangram.wav")
print(f"生成了 {len(audio) / 22000:.1f} 秒的音频")
```

### 2. 语音克隆

从短的参考音频样本中克隆任意声音：

```python
from kani_tts import KaniTTS, SpeakerEmbedder

# 初始化模型
model = KaniTTS('nineninesix/kani-tts-2-en')
embedder = SpeakerEmbedder()

# 从参考音频中提取说话人嵌入（建议 3–30 秒）
speaker_embedding = embedder.embed_audio_file("reference_voice.wav")

# 使用克隆的声音生成语音
audio, text = model(
    "这是使用 Kani TTS 2 进行语音克隆的演示。 "
    "你听到的声音应与参考音频样本相匹配。",
    speaker_emb=speaker_embedding
)

model.save_audio(audio, "cloned_output.wav")
```

### 3. 用于有声书的批量生成

高效生成多个章节：

```python
from kani_tts import KaniTTS, SpeakerEmbedder
import soundfile as sf

model = KaniTTS('nineninesix/kani-tts-2-en')
embedder = SpeakerEmbedder()

# 使用叙述者声音
narrator_emb = embedder.embed_audio_file("narrator_sample.wav")

chapters = [
    "第一章。那是四月一个明亮而寒冷的日子，钟声敲了十三点。",
    "第二章。走廊里弥漫着煮熟的卷心菜和旧破布垫的气味。",
    "第三章。外面，透过紧闭的窗玻璃，世界看起来很冷。",
]

for i, chapter_text in enumerate(chapters):
    audio, _ = model(chapter_text, speaker_emb=narrator_emb)
    model.save_audio(audio, f"chapter_{i+1}.wav")
    print(f"已生成第 {i+1} 章")
```

### 4. 兼容 OpenAI 的流式 API

对于实时应用，请使用兼容 OpenAI 的服务器：

```bash
# 克隆服务器代码库
git clone https://github.com/nineninesix-ai/kani-tts-2-openai-server.git
cd kani-tts-2-openai-server

# 安装依赖
pip install -r requirements.txt

# 启动服务器
python server.py --model nineninesix/kani-tts-2-en --host 0.0.0.0 --port 8080
```

然后将其与任何 OpenAI TTS 客户端一起使用：

```python
from openai import OpenAI

client = OpenAI(base_url="http://localhost:8080/v1", api_key="not-needed")

response = client.audio.speech.create(
    model="kani-tts-2-en",
    voice="default",
    input="Hello from the OpenAI-compatible Kani TTS server!"
)

response.stream_to_file("streamed_output.wav")
```

## 给 Clore.ai 用户的提示

1. **这是运行成本最低的模型** — 在 3GB 显存下，Kani-TTS-2 实际上可以在 Clore.ai 上的任何 GPU 实例上运行。一块每天 $0.15 的 RTX 3060 就足以满足生产级 TTS 的需求。
2. **与语言模型结合使用** — 租用一台 GPU 实例，同时运行一个小型 LLM（例如 Mistral 3 8B）和 Kani-TTS-2，即可构建一个完整的语音助手。它们可以共享 GPU 并有富余空间。
3. **预先计算说话人嵌入** — 只需提取并保存一次说话人嵌入即可。这样可避免在每次请求时加载 WavLM 嵌入器模型。
4. **使用兼容 OpenAI 的服务器** — 该 `kani-tts-2-openai-server` 提供了 OpenAI TTS API 的即插即用替代方案，使其易于集成到现有应用中。
5. **在自定义语言上训练** — Kani-TTS-2 包含完整的预训练框架（[kani-tts-2-pretrain](https://github.com/nineninesix-ai/kani-tts-2-pretrain)）。在您自己的语言数据集上微调模型——大约需要 8 块 H100 运行 \~6 小时。

## # 使用固定种子以获得一致结果

| 问题                         | 解决方案                                                            |
| -------------------------- | --------------------------------------------------------------- |
| `ImportError：无法导入 LFM2`    | 请安装正确的 transformers 版本： `pip install -U "transformers==4.56.0"` |
| 音频质量差 / 听起来像机器人            | 增加 `temperature` 将（参数）调整到 0.8–0.9；确保用于克隆的参考音频干净（无背景噪音）          |
| 语音克隆听起来与参考不符               | 使用 5–15 秒的清晰单一说话人音频。避免参考中有音乐或背景噪音                               |
| `CUDA 内存不足（out of memory）` | 在 3GB 模型下不应发生 — 检查是否有其他进程正在使用 GPU 内存（`nvidia-smi`)              |
| 音频在句中被截断                   | Kani-TTS-2 支持最长约 40 秒。将更长的文本拆分为句子并连接输出                          |
| 在 CPU 上运行缓慢                | 强烈建议使用 GPU 推理。即使是基础 GPU 的速度也比 CPU 快 10–50 倍                     |

## 延伸阅读

* [GitHub — kani-tts-2](https://github.com/nineninesix-ai/kani-tts-2) — PyPI 包、使用文档、高级示例
* [HuggingFace — kani-tts-2-en](https://huggingface.co/nineninesix/kani-tts-2-en) — 英文模型权重
* [预训练框架](https://github.com/nineninesix-ai/kani-tts-2-pretrain) — 从头训练您自己的 TTS 模型
* [兼容 OpenAI 的服务器](https://github.com/nineninesix-ai/kani-tts-2-openai-server) — 可替代 OpenAI TTS API 的即插即用方案
* [说话人嵌入模型](https://huggingface.co/nineninesix/speaker-emb-tbr) — 基于 WavLM 的语音嵌入器
* [MarkTechPost 概览](https://www.marktechpost.com/2026/02/15/meet-kani-tts-2-a-400m-param-open-source-text-to-speech-model-that-runs-in-3gb-vram-with-voice-cloning-support/) — 社区报道


---

# Agent Instructions: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
