> 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/fish-speech.md).

# Fish Speech

在 Clore.ai GPU 上运行 Fish Speech 多语言 TTS 和零样本声音克隆

Fish Speech 是一套最先进的多语言文本转语音（TTS）系统，具备零样本声音克隆能力。GitHub 星标超过 15,000，它支持英语、中文、日语、韩语、法语、德语、阿拉伯语、西班牙语等多种语言——全部由单一模型完成。仅需 10–15 秒的参考音频，Fish Speech 就能以惊人的保真度克隆任意声音，非常适合有声书制作、配音、虚拟助手以及大规模内容创作。

Fish Speech 采用基于 Transformer 的架构，并配备 VQGAN vocoder，在标准 TTS 基准上实现接近人类的自然度评分。WebUI（Gradio）让你无需编写一行代码即可使用，而 REST API 则可无缝集成到生产流程中。

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

***

## 服务器要求

| 参数   | 最低                     | 推荐                     |
| ---- | ---------------------- | ---------------------- |
| GPU  | NVIDIA RTX 3080（10 GB） | NVIDIA RTX 4090（24 GB） |
| 显存   | 8 GB                   | 16–24 GB               |
| 内存   | 16 GB                  | 32 GB                  |
| CPU  | 4 核                    | 8+ 核                   |
| 磁盘   | 20 GB                  | 40 GB                  |
| 操作系统 | Ubuntu 20.04+          | Ubuntu 22.04           |
| CUDA | 11.8+                  | 12.1+                  |
| 端口   | 22, 7860               | 22, 7860               |

{% hint style="info" %}
Fish Speech 在中端 GPU（RTX 3080/3090）上运行高效。对于批量推理或为多个并发用户提供服务，建议使用 RTX 4090 或 A100。
{% endhint %}

***

## 在 CLORE.AI 上快速部署

让 Fish Speech 运行起来的最快方式，是通过 Docker Hub 上的官方 Docker 镜像直接部署。

### 1. 找到合适的服务器

前往 [CLORE.AI 市场](https://clore.ai/marketplace) 并按以下条件筛选：

* **显存**：≥ 8 GB
* **GPU**：RTX 3080、3090、4080、4090、A100、H100
* **磁盘**：≥ 20 GB

### 2. 配置你的部署

在 CLORE.AI 订单表单中，设置以下内容：

**Docker 镜像：**

```
fishaudio/fish-speech:latest
```

**端口映射：**

```
22 → SSH 访问
7860 → Gradio Web UI
```

**环境变量：**

```
NVIDIA_VISIBLE_DEVICES=all
CUDA_VISIBLE_DEVICES=0
```

**启动命令（可选——自动启动 WebUI）：**

```bash
python -m tools.webui --listen 0.0.0.0 --port 7860
```

### 3. 访问界面

部署完成后，打开浏览器并访问：

```
http://<your-clore-server-ip>:7860
```

Gradio WebUI 将加载完整的 Fish Speech 界面，可直接使用。

***

## 逐步设置

### 步骤 1：通过 SSH 登录你的服务器

```bash
ssh root@<your-clore-server-ip> -p <ssh-port>
```

### 步骤 2：拉取并运行 Docker 容器

```bash
docker pull fishaudio/fish-speech:latest

docker run -d \\
  --name fish-speech \\
  --gpus all \\
  -p 7860:7860 \
  -p 22:22 \\
  -v /workspace/fish-speech:/workspace \\
  -e NVIDIA_VISIBLE_DEVICES=all \\
  fishaudio/fish-speech:latest \\
  python -m tools.webui --listen 0.0.0.0 --port 7860
```

### 步骤 3：验证 GPU 访问

```bash
docker exec fish-speech nvidia-smi
```

你应该能看到列出的 GPU 以及可用的 VRAM。

### 步骤 4：检查模型下载

Fish Speech 会在首次运行时自动下载模型权重（约 3–5 GB）。监控进度：

```bash
docker logs -f fish-speech
```

等待直到你看到：

```
正在本地 URL 上运行：  http://0.0.0.0:7860
```

### 步骤 5：访问 WebUI

访问 `http://<server-ip>:7860` 在浏览器中。

### 步骤 6：（可选）启用 API 服务器

```bash
docker exec -d fish-speech \\
  python -m tools.api_server --listen 0.0.0.0 --port 8080
```

***

## 使用示例

### 示例 1：通过 WebUI 进行基础文本转语音

1. 打开 WebUI： `http://<server-ip>:7860`
2. 在以下位置输入文本 **“文本”** 字段：

   ```
   欢迎来到 Clore.ai，这是面向 AI 任务的 GPU 云市场。
   ```
3. 选择语言： **英语**
4. 点击 **“生成”**
5. 下载生成的 `.wav` 文件

***

### 示例 2：零样本声音克隆

仅使用 10–15 秒的参考音频即可克隆任意声音：

1. 在 WebUI 中，前往 **“声音克隆”** 标签页
2. 上传你的参考音频文件（`.wav` 或 `.mp3`，10–30 秒）
3. 输入参考音频的转录文本（可选，但可提升质量）
4. 输入要合成的目标文本
5. 点击 **“克隆并生成”**

模型将分析声音特征，并用该声音合成语音。

***

### 示例 3：基于 API 的 TTS（Python）

```python
import requests
import base64

# Fish Speech API 端点
API_URL = "http://<your-clore-server-ip>:8080/v1/tts"

payload = {
    "text": "你好，这是在 Clore.ai GPU 基础设施上运行的 Fish Speech 测试。",
    "reference_id": None,  # 使用默认声音
    "format": "wav",
    "streaming": False
}

response = requests.post(API_URL, json=payload)

if response.status_code == 200:
    with open("output.wav", "wb") as f:
        f.write(response.content)
    print("音频已保存到 output.wav")
else:
    print(f"错误：{response.status_code} - {response.text}")
```

***

### 示例 4：多语言 TTS

```python
import requests

API_URL = "http://<your-clore-server-ip>:8080/v1/tts"

texts = {
    "en": "Clore.ai 为 AI 研究人员提供经济实惠的 GPU 云计算。",
    "zh": "Clore.ai 为 AI 研究人员提供经济实惠的 GPU 云计算服务。",
    "ja": "Clore.ai 为 AI 研究人员提供经济实惠的 GPU 云计算服务。",
    "ko": "Clore.ai 为 AI 研究人员提供经济实惠的 GPU 云计算服务。",
    "fr": "Clore.ai 为 AI 研究人员提供经济实惠的 GPU 云计算服务。",
}

for lang, text in texts.items():
    payload = {"text": text, "format": "wav"}
    response = requests.post(API_URL, json=payload)
    if response.status_code == 200:
        filename = f"output_{lang}.wav"
        with open(filename, "wb") as f:
            f.write(response.content)
        print(f"已保存 {filename}")
```

***

### 示例 5：批量处理音频文件

```python
import requests
import os
from pathlib import Path

API_URL = "http://<your-clore-server-ip>:8080/v1/tts"
OUTPUT_DIR = Path("./tts_outputs")
OUTPUT_DIR.mkdir(exist_ok=True)

# 要转换的一批文本
texts = [
    "第一章：人工智能新时代的开端。",
    "第二章：GPU 计算如何改变机器学习。",
    "第三章：语音合成技术的兴起。",
    "第四章：借助 Clore.ai 基础设施构建未来。",
    "第五章：结论与下一步。",
]

for i, text in enumerate(texts):
    payload = {
        "text": text,
        "format": "wav",
        "streaming": False
    }
    response = requests.post(API_URL, json=payload, timeout=60)
    if response.status_code == 200:
        output_path = OUTPUT_DIR / f"chapter_{i+1:02d}.wav"
        with open(output_path, "wb") as f:
            f.write(response.content)
        print(f"✓ 已生成：{output_path}")
    else:
        print(f"✗ 章节 {i+1} 失败：{response.status_code}")

print(f"\n所有文件已保存到 {OUTPUT_DIR}")
```

***

## 配置

### Docker Compose（生产环境配置）

```yaml
version: '3.8'

services:
  fish-speech:
    image: fishaudio/fish-speech:latest
    container_name: fish-speech
    runtime: nvidia
    environment:
      - NVIDIA_VISIBLE_DEVICES=all
      - CUDA_VISIBLE_DEVICES=0
    ports:
      - "7860:7860"
      - "8080:8080"
    volumes:
      - ./models:/workspace/models
      - ./outputs:/workspace/outputs
      - ./references:/workspace/references
    command: >
      bash -c "python -m tools.webui --listen 0.0.0.0 --port 7860 &
               python -m tools.api_server --listen 0.0.0.0 --port 8080 &
               wait"
    restart: unless-stopped
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              数量：1
              capabilities: [gpu]
```

### 关键配置选项

| 选项                 | 默认值       | 描述                           |
| ------------------ | --------- | ---------------------------- |
| `--listen`         | `0.0.0.0` | 绑定服务器的接口                     |
| `--port`           | `7860`    | Gradio WebUI 的端口             |
| `--compile`        | `false`   | 启用 torch.compile 以加快推理       |
| `--device`         | `cuda`    | 要使用的设备（`cuda`, `cpu`, `mps`) |
| `--half`           | `true`    | 使用 FP16 半精度（节省显存）            |
| `--num_samples`    | `1`       | 要生成的音频样本数量                   |
| `--max_new_tokens` | `1024`    | 生成时的最大新 token 数              |

### 模型变体

| 模型                    | 大小       | 语言    | 备注    |
| --------------------- | -------- | ----- | ----- |
| `fish-speech-1.4`     | \~3 GB   | 8 种语言 | 最新稳定版 |
| `fish-speech-1.2-sft` | \~2.5 GB | 8 种语言 | 微调版本  |
| `fish-speech-1.2`     | \~2.5 GB | 8 种语言 | 基础模型  |

***

## 性能提示

### 1. 启用 torch.compile 以加快推理

```bash
# 启动时添加 --compile 参数
python -m tools.webui --listen 0.0.0.0 --port 7860 --compile
```

首次运行会更慢（编译需要 2–5 分钟），但后续推理将快 20–40%。

### 2. 使用半精度（FP16）

FP16 可将显存占用减少约 50%，且几乎不损失质量：

```bash
python -m tools.webui --listen 0.0.0.0 --port 7860 --half
```

### 3. 预加载参考音色

将常用的参考音色存储在容器的 reference 目录中，以避免重复处理：

```bash
# 将参考音频复制到容器中
docker cp my_voice.wav fish-speech:/workspace/references/my_voice.wav
```

### 4. GPU 内存优化

```bash
# 设置最佳 CUDA 内存分配比例
export PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:512

# 在大批次之间清理 GPU 缓存
docker exec fish-speech python -c "import torch; torch.cuda.empty_cache()"
```

### 5. 批大小调优

对于批量 API 请求，最佳批大小为：

* **RTX 3080（10 GB）**：batch\_size = 1–2
* **RTX 3090/4090（24 GB）**：batch\_size = 4–8
* **A100（40/80 GB）**：batch\_size = 16–32

***

## 故障排查

### 问题：容器无法启动——未找到 CUDA

```bash
# 检查容器内的 NVIDIA 驱动
docker exec fish-speech nvidia-smi

# 如果失败，请检查宿主机驱动
nvidia-smi

# 使用显式 GPU 标志重新运行
docker run --gpus all --rm fishaudio/fish-speech:latest nvidia-smi
```

### 问题：内存不足（OOM）错误

```bash
# 检查显存占用
docker exec fish-speech nvidia-smi

# 使用 FP16 将显存占用减半
# 使用 --half 参数重启容器
docker stop fish-speech
docker run -d --name fish-speech --gpus all -p 7860:7860 \\
  fishaudio/fish-speech:latest \\
  python -m tools.webui --listen 0.0.0.0 --port 7860 --half
```

### 问题：7860 端口无法访问

```bash
# 检查容器是否在运行
docker ps | grep fish-speech

# 检查端口绑定
docker port fish-speech

# 检查防火墙（在 Clore 服务器上）
# 确保在你的 CLORE.AI 订单配置中映射了 7860 端口
```

### 问题：模型下载失败 / 下载缓慢

```bash
# 检查容器的网络连接
docker exec fish-speech curl -I https://huggingface.co

# 手动预下载模型
docker exec fish-speech python -c "
from huggingface_hub import snapshot_download
snapshot_download('fishaudio/fish-speech-1.4')
"
```

### 问题：音频质量较差

* 确保参考音频干净（无背景噪音，采样率 16kHz 以上）
* 将参考音频控制在 10–30 秒之间
* 提供参考音频的转录文本以获得更好的对齐
* 尝试提高 `--num_samples` 以生成多个候选并选择最佳结果

### 问题：WebUI 已加载，但生成卡住

```bash
# 在生成过程中检查 GPU 利用率
docker exec fish-speech watch -n1 nvidia-smi

# 检查日志中的错误
docker logs fish-speech --tail 50
```

***

## 链接

* **GitHub**: <https://github.com/fishaudio/fish-speech>
* **Docker Hub**: <https://hub.docker.com/r/fishaudio/fish-speech>
* **官方文档**: <https://speech.fish.audio>
* **Hugging Face 模型**: <https://huggingface.co/fishaudio/fish-speech-1.4>
* **CLORE.AI 市场**: <https://clore.ai/marketplace>
* **Discord 社区**: <https://discord.gg/Es5qTB9BcN>

***

## Clore.ai GPU 推荐

| 使用场景    | 推荐 GPU         | Clore.ai 预计成本                     |
| ------- | -------------- | --------------------------------- |
| 开发/测试   | RTX 3090（24GB） | $0.07–0.21/gpu/hr                 |
| 生产级 TTS | RTX 4090（24GB） | $0.14–0.42/gpu/hr                 |
| 高吞吐量推理  | A100 80GB      | [裸机](https://clore.ai/bare-metal) |

> 💡 本指南中的所有示例都可以部署在 [Clore.ai](https://clore.ai/marketplace) GPU 服务器上。浏览可用 GPU 并按小时租用——无需承诺，拥有完整 root 访问权限。


---

# 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/fish-speech.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.
