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

# Bark TTS

在 Clore.ai 上使用 Bark AI 生成逼真的语音和音频

使用 Bark AI 生成逼真的语音和音频。

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

## 服务器要求

| 参数   | 最低      | 推荐       |
| ---- | ------- | -------- |
| 内存   | 8GB     | 16GB+    |
| 显存   | 4GB（小）  | 8GB+（普通） |
| 网络   | 200Mbps | 500Mbps+ |
| 启动时间 | 3-5 分钟  | -        |

{% hint style="warning" %}
**启动时间：** 首次启动会下载 Bark 模型（取决于网络速度，需 3-5 分钟）。在此期间出现 HTTP 502 属于正常现象。
{% 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>`

## 什么是 Bark？

Suno AI 的 Bark 可以生成：

* 多种语言的逼真语音
* 各种说话人声音
* 非语言声音（笑声、叹息）
* 音乐和音效
* 多语言语音

## 需求

| 质量 | 显存   | 推荐       |
| -- | ---- | -------- |
| 小  | 4GB  | RTX 3060 |
| 普通 | 8GB  | RTX 3070 |
| 高  | 12GB | RTX 3090 |

## 快速部署

**Docker 镜像：**

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

**端口：**

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

**命令：**

```bash
pip install git+https://github.com/suno-ai/bark.git gradio scipy && \\
python -c "
import gradio as gr
from bark import SAMPLE_RATE, generate_audio, preload_models
import scipy.io.wavfile as wav
import numpy as np
import tempfile

preload_models()

def generate(text, voice):
    audio = generate_audio(text, history_prompt=voice)
    with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as f:
        wav.write(f.name, SAMPLE_RATE, (audio * 32767).astype(np.int16))
        return f.name

voices = ['v2/en_speaker_0', 'v2/en_speaker_1', 'v2/en_speaker_2', 'v2/en_speaker_3',
          'v2/en_speaker_4', 'v2/en_speaker_5', 'v2/en_speaker_6', 'v2/en_speaker_7',
          'v2/en_speaker_8', 'v2/en_speaker_9']

demo = gr.Interface(fn=generate, inputs=[gr.Textbox(lines=5), gr.Dropdown(voices)],
                   outputs=gr.Audio(), title='Bark 文本转语音')
demo.launch(server_name='0.0.0.0', server_port=7860)
"
```

## 访问你的服务

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

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

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

### 验证是否正常工作

```bash
# 检查 Gradio 界面是否可访问
curl https://your-http-pub.clorecloud.net/
```

{% hint style="warning" %}
如果出现 HTTP 502，请等待 3-5 分钟——服务正在下载模型。
{% endhint %}

## 安装

```bash
pip install git+https://github.com/suno-ai/bark.git
pip install scipy
```

## 基础用法

```python
from bark import SAMPLE_RATE, generate_audio, preload_models
import scipy.io.wavfile as wav
import numpy as np

# 预加载模型（首次运行时会下载）
preload_models()

# 生成音频
text = "你好，这是对 Bark 文本转语音的测试。"
audio = generate_audio(text)

# 保存为 WAV
wav.write("output.wav", SAMPLE_RATE, (audio * 32767).astype(np.int16))
```

## 声音选择

### 内置声音

```python

# 英语说话人（0-9）
audio = generate_audio("你好！", history_prompt="v2/en_speaker_0")
audio = generate_audio("你好！", history_prompt="v2/en_speaker_3")
audio = generate_audio("你好！", history_prompt="v2/en_speaker_9")

# 其他语言
audio = generate_audio("Bonjour!", history_prompt="v2/fr_speaker_0")  # 法语
audio = generate_audio("Hallo!", history_prompt="v2/de_speaker_0")    # 德语
audio = generate_audio("Hola!", history_prompt="v2/es_speaker_0")     # 西班牙语
audio = generate_audio("Ciao!", history_prompt="v2/it_speaker_0")     # 意大利语
audio = generate_audio("Olá!", history_prompt="v2/pt_speaker_0")      # 葡萄牙语
audio = generate_audio("Привет!", history_prompt="v2/ru_speaker_0")   # 俄语
audio = generate_audio("こんにちは!", history_prompt="v2/ja_speaker_0") # 日语
audio = generate_audio("你好!", history_prompt="v2/zh_speaker_0")      # 中文
```

### 可用语言

| 语言   | 代码 | 说话人 |
| ---- | -- | --- |
| 英语   | en | 0-9 |
| 德语   | de | 0-9 |
| 西班牙语 | es | 0-9 |
| 法语   | fr | 0-9 |
| 印地语  | hi | 0-9 |
| 意大利语 | it | 0-9 |
| 日语   | ja | 0-9 |
| 韩语   | ko | 0-9 |
| 波兰语  | pl | 0-9 |
| 葡萄牙语 | pt | 0-9 |
| 俄语   | ru | 0-9 |
| 土耳其语 | tr | 0-9 |
| 中文   | zh | 0-9 |

## 非语言声音

Bark 可以生成非语言音频：

```python

# 笑声
audio = generate_audio("你好！[laughs] 这太好笑了！")

# 叹息
audio = generate_audio("[sighs] 我今天太累了。")

# 倒吸一口气
audio = generate_audio("[gasps] 我的天啊！")

# 清嗓子
audio = generate_audio("[clears throat] 咳咳，请注意。")

# 音符
audio = generate_audio("♪ La la la ♪")
```

## 长篇音频

对于超过 13 秒的文本：

```python
from bark import generate_audio
from bark.generation import SAMPLE_RATE
import numpy as np

def generate_long_audio(text, voice="v2/en_speaker_6")】【：】【“】【t_3ae97a4e】【：】【“】【# 按句子拆分
    # 按句子拆分
    sentences = text.replace(".", ".|").replace("?", "?|").replace("!", "!|").split("|")
    sentences = [s.strip() for s in sentences if s.strip()]

    audio_segments = []
    for sentence in sentences:
        audio = generate_audio(sentence, history_prompt=voice)
        audio_segments.append(audio)
        # 句子之间添加短暂停顿
        audio_segments.append(np.zeros(int(0.25 * SAMPLE_RATE)))

    return np.concatenate(audio_segments)

long_text = """
这是一段较长的文本，会被拆分成多个片段。
每个片段将分别生成，然后再连接起来。
这样就可以生成任意长度的音频。
"""

audio = generate_long_audio(long_text)
```

## 声音克隆

创建自定义声音提示：

```python
from bark.generation import preload_models, generate_text_semantic
from bark.api import semantic_to_waveform
from bark import generate_audio, SAMPLE_RATE
import numpy as np

# 使用特定特征生成

# 提示词可以包含说话人描述

# 首先生成一个参考
voice_prompt = "v2/en_speaker_6"
text = "这就是我正常说话时的声音。"
audio = generate_audio(text, history_prompt=voice_prompt)

# 保存为自定义声音（简化示例）
np.savez("custom_voice.npz", audio=audio)
```

## 批量处理

```python
import os
from bark import generate_audio, SAMPLE_RATE
import scipy.io.wavfile as wav
import numpy as np

texts = [
    "欢迎来到我们的播客。",
    "今天我们将讨论人工智能。",
    "让我们从介绍开始。",
]

output_dir = "./audio_clips"
os.makedirs(output_dir, exist_ok=True)

voice = "v2/en_speaker_6"

for i, text in enumerate(texts):
    print(f"正在生成 {i+1}/{len(texts)}")
    audio = generate_audio(text, history_prompt=voice)
    wav.write(
        os.path.join(output_dir, f"clip_{i:03d}.wav"),
        SAMPLE_RATE,
        (audio * 32767).astype(np.int16)
    )
```

## API 服务器

```python
from fastapi import FastAPI
from fastapi.responses import FileResponse
from bark import generate_audio, preload_models, SAMPLE_RATE
import scipy.io.wavfile as wav
import numpy as np
import tempfile
import os

app = FastAPI()
preload_models()

@app.post("/generate")
async def generate_speech(text: str, voice: str = "v2/en_speaker_6"):
    audio = generate_audio(text, history_prompt=voice)

    with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as f:
        wav.write(f.name, SAMPLE_RATE, (audio * 32767).astype(np.int16))
        return FileResponse(f.name, media_type="audio/wav")

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

### 用法

```bash
curl -X POST "http://localhost:8000/generate?text=Hello%20world&voice=v2/en_speaker_6" \\
    --output speech.wav
```

## 内存优化

### 适用于有限 VRAM

```python
import os

# 使用更小的模型
os.environ["SUNO_USE_SMALL_MODELS"] = "1"

# 卸载到 CPU
os.environ["SUNO_OFFLOAD_CPU"] = "1"

from bark import generate_audio
audio = generate_audio("你好，世界")
```

### 启用 FP16

```python
os.environ["SUNO_ENABLE_MPS"] = "0"

from bark import generate_audio
audio = generate_audio("你好！", history_prompt="v2/en_speaker_6")
```

## 与其他音频混合

```python
from pydub import AudioSegment
import numpy as np
from bark import generate_audio, SAMPLE_RATE
import scipy.io.wavfile as wav
import tempfile

def bark_to_pydub(audio_array):
    with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as f:
        wav.write(f.name, SAMPLE_RATE, (audio_array * 32767).astype(np.int16))
        return AudioSegment.from_wav(f.name)

# 生成语音
speech = generate_audio("欢迎来到节目！")
speech_audio = bark_to_pydub(speech)

# 加载背景音乐
music = AudioSegment.from_mp3("background.mp3")

# 混合在一起
music = music - 20  # 降低音乐音量
combined = speech_audio.overlay(music)
combined.export("output.mp3", format="mp3")
```

## 性能

| 模式  | GPU      | 时间（10 个词） |
| --- | -------- | --------- |
| 普通  | RTX 3090 | 约 5 秒     |
| 普通  | RTX 4090 | \~3s      |
| 小   | RTX 3060 | \~8s      |
| CPU | -        | \~60秒     |

## 与其他 TTS 的对比

| 功能  | Bark | Coqui | Piper |
| --- | ---- | ----- | ----- |
| 质量  | 最佳   | 很高    | 好     |
| 速度  | 慢    | 中等    | 快     |
| 语言  | 13+  | 20+   | 30+   |
| 非语言 | 是    | 否     | 否     |
| 显存  | 8GB+ | 4GB   | 1GB   |

## 故障排查

### 内存不足

```python

# 使用小模型
os.environ["SUNO_USE_SMALL_MODELS"] = "1"
os.environ["SUNO_OFFLOAD_CPU"] = "1"
```

### 生成缓慢

* 使用 GPU（而非 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** 代币支付
* 比较不同提供商的价格

## 下一步

* [RVC 语音克隆](/guides/guides_v2-zh/yin-pin-yu-yu-yin/rvc-voice-clone.md)
* [Whisper Transcription](/guides/guides_v2-zh/yin-pin-yu-yu-yin/whisper-transcription.md)
* [AudioCraft 音乐](/guides/guides_v2-zh/yin-pin-yu-yu-yin/audiocraft-music.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/bark-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.
