> For the complete documentation index, see [llms.txt](https://whitepaper.virtuals.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://whitepaper.virtuals.io/virtuals-bai-pi-shu/guan-yu-virtuals-1/xie-yi/ai-zhi-neng-ti-gong-tong-gong-xian-yu-su-yuan/mian-xiang-ai-zhi-neng-ti-zhi-li-de-mo-kuai-hua-gong-shi-kuang-jia/qu-zhong-xin-hua-ai-zhi-neng-ti-gong-xian-yu-nft/ai-zhi-neng-ti-de-yu-yin-he-xin.md).

# AI 智能体的语音核心

探索 Virtuals Protocol 的语音核心，涵盖 AI 智能体语音、语音转文本、文本转语音、VITS 语音合成以及音频数据预处理。

Voice Core 为每个虚拟智能体提供独特且与其个性相匹配的声音。AI 语音模型训练会为每个智能体和角色生成真实、一致的语音。

### AI 智能体语音模块

**语音转文本（STT）：** STT 模块基于多样化的语音数据进行训练。它能够准确转写不同用户场景中的口音、方言和说话模式。

**文本转语音（TTS）：** TTS 模块使用用于文本转语音的变分推断（VITS）进行训练。VITS 能生成高质量、自然的语音，并支持针对每个 AI 智能体个性定制的语音合成。

语音模型训练之前会进行音频数据预处理。

### 语音模型的音频数据预处理

1. **音频格式一致性：** 采用 22050 Hz 的单声道 WAV 文件可创建一致的训练输入。一致的输入数据有助于机器学习语音模型稳定可靠地运行。
2. **采样率归一化：** 22050 Hz 的采样率既能捕获人类语音频率，又能保持文件大小可控。根据奈奎斯特定理，它可捕获最高 11025 Hz 的频率。
3. **单声道音频通道：** 将立体声或多声道音频转换为单声道，可为语音模型提供单一训练通道，并简化学习过程。

<details>

<summary>示例代码</summary>

```python
import os
from pydub import AudioSegment

upload_dir = 'upload_dir'
output_dir = 'out'

# 确保输出目录存在
os.makedirs(output_dir, exist_ok=True)

extensions = ['wav', 'mp3', 'ogg']

# 处理上传目录中的所有文件
for filename in os.listdir(upload_dir):
    if any(filename.lower().endswith(ext) for ext in extensions):
        # 构建文件路径
        file_path = os.path.join(upload_dir, filename)
        output_path = os.path.join(output_dir, os.path.splitext(filename)[0] + '.wav')

        # 加载音频文件
        audio = AudioSegment.from_file(file_path)

        # 转换为 WAV、22050 Hz、单声道
        audio = audio.set_frame_rate(22050).set_channels(1)

        # 导出处理后的音频
        audio.export(output_path, format='wav')

```

</details>

[<mark style="color:红色;">进一步了解如何为 Voice Core 贡献内容。</mark>](/virtuals-bai-pi-shu/gou-jian-zhe-zhong-xin/shi-yong-virtuals-gou-jian/zhi-neng-ti-gong-xian/gong-xian-gei-yu-yin-he-xin.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://whitepaper.virtuals.io/virtuals-bai-pi-shu/guan-yu-virtuals-1/xie-yi/ai-zhi-neng-ti-gong-tong-gong-xian-yu-su-yuan/mian-xiang-ai-zhi-neng-ti-zhi-li-de-mo-kuai-hua-gong-shi-kuang-jia/qu-zhong-xin-hua-ai-zhi-neng-ti-gong-xian-yu-nft/ai-zhi-neng-ti-de-yu-yin-he-xin.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.
