> 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-dai-li-xie-tong-gong-xian-yu-lai-yuan-zheng-ming/yong-yu-ai-dai-li-zhi-li-de-mo-kuai-hua-gong-shi-kuang-jia/qu-zhong-xin-hua-ai-dai-li-gong-xian-yu-nft/ai-dai-li-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/yong-virtuals-gou-jian/dai-li-gong-xian/gong-xian-dao-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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://whitepaper.virtuals.io/virtuals-bai-pi-shu/guan-yu-virtuals-1/xie-yi/ai-dai-li-xie-tong-gong-xian-yu-lai-yuan-zheng-ming/yong-yu-ai-dai-li-zhi-li-de-mo-kuai-hua-gong-shi-kuang-jia/qu-zhong-xin-hua-ai-dai-li-gong-xian-yu-nft/ai-dai-li-de-yu-yin-he-xin.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
