> 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/f5-tts.md).

# F5-TTS

在 Clore.ai GPU 上使用 F5-TTS 实现快速、流畅的文字转语音

使用 F5-TTS 生成自然语音——一个快速流畅的 TTS 系统。

{% hint style="success" %}
所有示例都可以在通过以下方式租用的 GPU 服务器上运行 [CLORE.AI 市场](https://clore.ai/marketplace).
{% endhint %}

## 在 CLORE.AI 上租用

1. 访问 [CLORE.AI 市场](https://clore.ai/marketplace)
2. 按 GPU 类型、VRAM 和价格筛选
3. 选择 **按需** （固定费率）或 **竞价** （出价）
4. 配置你的订单：
   * 选择 Docker 镜像
   * 设置端口（SSH 用 TCP，Web UI 用 HTTP）
   * 如有需要，添加环境变量
   * 输入启动命令
5. 选择支付方式： **CLORE**, **BTC**，或 **USDT/USDC**
6. 创建订单并等待部署

### 访问你的服务器

* 在以下位置查找连接信息 **我的订单**
* Web 界面：使用 HTTP 端口 URL
* SSH： `ssh -p <port> root@<proxy-address>`

## 什么是 F5-TTS？

F5-TTS 提供：

* 快速推理（快于实时）
* 自然的韵律和语调
* 零样本声音克隆
* 多语言支持

## 资源

* **GitHub：** [SWivid/F5-TTS](https://github.com/SWivid/F5-TTS)
* **HuggingFace：** [SWivid/F5-TTS](https://huggingface.co/SWivid/F5-TTS)
* **论文：** [F5-TTS 论文](https://arxiv.org/abs/2410.06885)
* **演示：** [HuggingFace Space](https://huggingface.co/spaces/mrfakename/E2-F5-TTS)

## 推荐硬件

| 组件  | 最低            | 推荐            | 最佳            |
| --- | ------------- | ------------- | ------------- |
| GPU | RTX 3060 12GB | RTX 4080 16GB | RTX 4090 24GB |
| 显存  | 6GB           | 12GB          | 16GB          |
| CPU | 4 核           | 8 核           | 16 核          |
| 内存  | 16GB          | 32GB          | 64GB          |
| 存储  | 20GB SSD      | 50GB NVMe     | 100GB NVMe    |
| 网络  | 100 Mbps      | 500 Mbps      | 1 Gbps        |

## 在 CLORE.AI 上快速部署

**Docker 镜像：**

```
pytorch/pytorch:2.11.0-cuda12.8-cudnn9-runtime
```

**端口：**

```
22/tcp
7860/http
```

**命令：**

```bash
pip install f5-tts && \\
f5-tts-webui
```

## 访问你的服务

部署后，找到你的 `http_pub` URL 在 **我的订单**:

1. 前往 **我的订单** 页面
2. 点击你的订单
3. 找到 `http_pub` URL（例如， `abc123.clorecloud.net`)

使用 `https://YOUR_HTTP_PUB_URL` 替代 `localhost` 在下面的示例中。

## 安装

```bash
pip install f5-tts

# 或从源码安装
git clone https://github.com/SWivid/F5-TTS.git
cd F5-TTS
pip install -e .
```

## 你可以创建什么

### 语音内容

* 播客制作
* 有声书旁白
* 视频配音

### 无障碍

* 屏幕阅读器
* 文档朗读
* 学习材料

### 交互式应用

* 语音助手
* 游戏 NPC
* 客服机器人

### 创意项目

* 角色配音
* 广播剧
* 音乐人声

## 基础用法

### 简单 TTS

```python
from f5_tts import F5TTS

# 初始化
tts = F5TTS(device="cuda")

# 生成语音
audio = tts.generate(
    text="你好！这是 F5-TTS 正在生成自然语音。",
    output_path="output.wav"
)
```

### 声音克隆

```python
from f5_tts import F5TTS

tts = F5TTS(device="cuda")

# 从参考音频克隆声音
audio = tts.generate(
    text="这是我的克隆声音在说新文本。",
    ref_audio="reference_voice.wav",
    ref_text="这是音频中朗读的参考文本。",
    output_path="cloned_output.wav"
)
```

## 多语言支持

```python
from f5_tts import F5TTS

tts = F5TTS(device="cuda")

# 英语
tts.generate(
    text="你好，今天过得怎么样？",
    ref_audio="english_speaker.wav",
    output_path="english.wav"
)

# 中文
tts.generate(
    text="你好，今天怎么样？",
    ref_audio="chinese_speaker.wav",
    output_path="chinese.wav"
)

# 法语
tts.generate(
    text="Bonjour, comment allez-vous?",
    ref_audio="french_speaker.wav",
    output_path="french.wav"
)
```

## 批量处理

```python
from f5_tts import F5TTS
import os

tts = F5TTS(device="cuda")

texts = [
    "欢迎观看我们的产品演示。",
    "今天我们将向您展示主要功能。",
    "让我们从主仪表板开始。",
    "如您所见，界面很直观。",
    "感谢观看！"
]

ref_audio = "narrator_voice.wav"
ref_text = "参考音频中的示例文本。"
output_dir = "./narration"
os.makedirs(output_dir, exist_ok=True)

for i, text in enumerate(texts):
    print(f"正在生成 {i+1}/{len(texts)}: {text[:50]}...")

    tts.generate(
        text=text,
        ref_audio=ref_audio,
        ref_text=ref_text,
        output_path=f"{output_dir}/segment_{i:03d}.wav"
    )
```

## 长篇音频

```python
from f5_tts import F5TTS

tts = F5TTS(device="cuda")

long_text = """
欢迎阅读这份机器学习综合指南。
在本章中，我们将探讨神经网络的基础。
神经网络是受生物神经网络启发的计算系统。
它们由相互连接的节点组成，用于处理信息。
让我们从基本概念开始。
"""

# F5-TTS 通过按句子拆分来处理长文本
audio = tts.generate(
    text=long_text,
    ref_audio="narrator.wav",
    output_path="long_narration.wav",
    chunk_size=200  # 每个分块的字符数
)
```

## Gradio 界面

```python
import gradio as gr
from f5_tts import F5TTS
import tempfile

tts = F5TTS(device="cuda")

def generate_speech(text, ref_audio, ref_text):
    with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as f:
        tts.generate(
            text=text,
            ref_audio=ref_audio,
            ref_text=ref_text,
            output_path=f.name
        )
        return f.name

demo = gr.Interface(
    fn=generate_speech,
    inputs=[
        gr.Textbox(label="要朗读的文本", lines=5),
        gr.Audio(type="filepath", label="参考声音"),
        gr.Textbox(label="参考文本", lines=2)
    ],
    outputs=gr.Audio(label="生成的语音"),
    title="F5-TTS 声音克隆",
    description="在 CLORE.AI 服务器上使用 F5-TTS 克隆任何声音"
)

demo.launch(server_name="0.0.0.0", server_port=7860)
```

## API 服务器

```python
from fastapi import FastAPI, UploadFile, File, Form
from fastapi.responses import FileResponse
from f5_tts import F5TTS
import tempfile

app = FastAPI()
tts = F5TTS(device="cuda")

@app.post("/synthesize")
async def synthesize(
    text: str = Form(...),
    ref_audio: UploadFile = File(...),
    ref_text: str = Form(...)
):
    with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as ref_file:
        ref_file.write(await ref_audio.read())
        ref_path = ref_file.name

    with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as out_file:
        tts.generate(
            text=text,
            ref_audio=ref_path,
            ref_text=ref_text,
            output_path=out_file.name
        )
        return FileResponse(out_file.name, media_type="audio/wav")

# 运行：uvicorn server:app --host 0.0.0.0 --port 8000
```

## 性能

| 文本长度     | GPU      | 生成时间  | 实时因子 |
| -------- | -------- | ----- | ---- |
| 100 个字符  | RTX 3090 | 0.5秒  | 5 倍  |
| 100 个字符  | RTX 4090 | 0.3秒  | 8 倍  |
| 500 个字符  | RTX 4090 | 1.2秒  | 10 倍 |
| 1000 个字符 | A100     | 2.0 秒 | 12 倍 |

## 常见问题与解决方案

### 声音匹配不佳

**问题：** 生成的声音与参考不匹配

**解决方案：**

* 使用 5-15 秒清晰的参考音频
* 提供准确的参考文本转录
* 避免参考音频中的背景噪音
* 使文本与参考音频语言一致

### 发音问题

**问题：** 单词或姓名发音错误

**解决方案：**

```python

# 对难读单词使用音标提示
text = "欢迎来到 CLORE（发音为 KLOR）AI 平台。"

# 或使用类似 SSML 的格式
text = "CEO 约翰·史密斯（SMIHTH）将发言。"
```

### 音频质量问题

**问题：** 输出听起来机械或失真

**解决方案：**

* 使用高质量参考音频（24kHz 以上）
* 清理参考音频中的噪音
* 尝试不同的参考样本
* 提高生成质量设置

### 内存问题

**问题：** 长文本时内存不足

**解决方案：**

```python

# 分成更小的块处理
tts.generate(
    text=long_text,
    chunk_size=100,  # 更小的块
    overlap=20  # 平滑过渡
)
```

### 生成缓慢

**问题：** 生成耗时过长

**解决方案：**

* 使用 GPU 推理（CUDA）
* 减小 chunk\_size 以加快处理
* 使用 RTX 4090 或更高配置
* 启用半精度（fp16）

## 故障排查

### 声音与参考不匹配

* 使用 5-15 秒清晰的参考音频
* 准确转录参考文本
* 避免参考音频中的背景噪音

### 音频质量问题

* 使用高采样率参考音频（24kHz 以上）
* 清理参考音频中的噪音
* 尝试不同的参考样本

### 生成缓慢

* 使用 CUDA（而不是 CPU）
* 缩短文本长度或将其分块
* 使用更小的批量大小

### 语言不匹配

* 使文本语言与参考音频语言一致
* 某些语言需要特定模型

## 成本估算

CLORE.AI 市场常见费率（截至 2024 年）：

| GPU       | 小时费率    | 日费率     | 4 小时会话  |
| --------- | ------- | ------- | ------- |
| RTX 3060  | \~$0.03 | \~$0.70 | \~$0.12 |
| RTX 3090  | \~$0.06 | \~$1.50 | \~$0.25 |
| RTX 4090  | \~$0.10 | \~$2.30 | \~$0.40 |
| A100 40GB | \~$0.17 | \~$4.00 | \~$0.70 |
| A100 80GB | \~$0.25 | \~$6.00 | \~$1.00 |

*价格因提供商和需求而异。请查看* [*CLORE.AI 市场*](https://clore.ai/marketplace) *以获取当前费率。*

**节省费用：**

* 使用 **竞价** 可中断工作市场——约三分之一的服务器将现货价格定得低于按需价格（中位数约优惠 13%），其余则与按需价格持平
* 使用 **CLORE** 代币支付
* 比较不同提供商的价格

## 下一步

* [XTTS](/guides/guides_v2-zh/yin-pin-yu-yu-yin/xtts-coqui.md) - 替代 TTS
* [Bark TTS](/guides/guides_v2-zh/yin-pin-yu-yu-yin/bark-tts.md) - 表现力 TTS
* [SadTalker](/guides/guides_v2-zh/talking-heads/sadtalker.md) - 口型说话头像


---

# 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/f5-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.
