> ## Documentation Index
> Fetch the complete documentation index at: https://docs.veadk.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# 语音合成

## 功能说明

对应工具标识 `text_to_speech`。

`text_to_speech` 将文本合成为语音，并把音频保存到本地。

导入路径：`from veadk.tools.builtin_tools.tts import text_to_speech`

## 环境变量与前提

<Warning>
  附加要求：

  1. 配置用于智能体推理模型的 API Key；
  2. 配置 VeSpeech 服务的 App ID 与 API Key。
</Warning>

环境变量：

* `MODEL_AGENT_API_KEY`：智能体推理模型的 API Key
* `TOOL_VESPEECH_APP_ID`：VeSpeech 服务的 App ID
* `TOOL_VESPEECH_API_KEY`：VeSpeech 服务的 API Key
* `TOOL_VESPEECH_SPEAKER`：音色，默认为 `zh_female_vv_uranus_bigtts`
* `TOOL_VESPEECH_AUDIO_OUTPUT_PATH`：音频输出目录，默认为系统临时目录

## 使用方法

```python title="examples/tools/tts/agent.py" lines theme={null}
import asyncio

from veadk import Agent, Runner
from veadk.memory.short_term_memory import ShortTermMemory
from veadk.tools.builtin_tools.tts import text_to_speech

agent = Agent(
    name="tts_agent",
    model_name="doubao-seed-1-8-251228",
    description="An agent that speaks text aloud.",
    instruction="Use the text_to_speech tool to synthesize the user's text into speech.",
    tools=[text_to_speech],
)

runner = Runner(agent=agent, short_term_memory=ShortTermMemory())


async def main():
    response = await runner.run("把这句话读出来：你好，欢迎使用 VeADK")
    print(response)


if __name__ == "__main__":
    asyncio.run(main())
```
