# 语音合成 API Documentation

> 文本合成语言

## Overview

This document describes how to call the **语音合成** API.

- **Model / path slug**: `aihuman/tts`
- **Task type**: `sync` (`sync` = synchronous, `async` = create task then poll / callback)
- **HTML docs**: `/doc/10`

## Authentication

All API requests require your platform API key as the query parameter `key`:

```
?key=YOUR_API_KEY
```

Get API Key:
1. Sign in to the console
2. Open [API Key Management](/user/key) and create or copy your key
3. Append `key=YOUR_API_KEY` to the request URL (or pass it in form/JSON when the endpoint accepts it)

---

## API Information

- **URL**: `POST https://apis.xiaobao.ink/api/aihuman/tts`
- **Content-Type**: `application/json` (request body commonly `application/json` or `application/x-www-form-urlencoded` for POST)
- **HTTP Method**: `POST`

### Request Parameters

| Parameter | Required | Description |
|-----------|----------|-------------|
| `text` | Yes | 文本内容，不超过2000字 |
| `voice_type` | Yes | 音色类型：克隆的音色custom、系统音色public |
| `voice_id` | Yes | 克隆或系统的音色ID |
| `lang` | Yes | 文本的语言，仅限克隆的音色，目前仅支持 zh-cn、en |
| `volume` | Yes | 音量，取值 0～2，默认 1 |
| `speed` | Yes | 语速，取值 0～2，默认 1 |
| `notify` | Yes | 回调地址，用于接收任务结果，任务结果数据会通过 POST 请求发送到该地址 |

> **Note**: `key` (API key) is required for authenticated calls even if omitted from the parameter list above.

### Request Example

```
https://apis.xiaobao.ink/api/aihuman/tts?key=你的密钥
```

## Details

## 请求HEADER：

| 名称 | 值 |
| --- | --- |
| Content-Type | application/json |

## 请求参数说明：

| 名称 | 必填 | 类型 | 示例值 | 说明 |
| --- | --- | --- | --- | --- |
| text | 是 | string | 要克隆的文本内容 | 文本内容，不超过2000字 |
| voice_type | 否 | string | custom | 音色类型：克隆的音色custom、系统音色public |
| voice_id | 是 | string | 21221 | 克隆或系统的音色I |
| lang | 否 | string |  zh-cn | 文本的语言，仅限克隆的音色。 zh-cn：中文 en：英文 fr：法语 de：德语 ja：日语 ko：韩语 ru：俄语 pt：葡萄牙语 th：泰语 id：印尼语 vi：越南语 默认值: zh-cn |
| volume | 否 | int | 1 | 音量，取值 0～2，默认 1 |
| speed | 否 | int | 1 | 语速，取值 0～2，默认 1 |
| notify | 是 | string |  | 回调地址，用于接收任务结果，任务结果数据会通过 POST 请求发送到该地址 |

## 返回参数说明：

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| code | int | 状态码 |
| msg | string | 状态信息 |
| data | string | 请求结果数据集 |
| - task_id | string | 任务id |
| debug | string/array | 调试数据 |
| exec_time | float | 执行耗时 |
| user_ip | string | 客户端IP |

回调的参数说明：

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| task_id | string | 任务id |
| code | int | 200 成功 |
| audio_url | string | 结果音频url（文件仅短暂留存，请转存） |
| msg | string | 失败原因，仅失败时有值 |
|  |  |  |

## Response Example

```json
{
    "code": 200,
    "data": {
        "task_id": "string"
    },
    "msg": "string"
}
```

## Error Codes

| Status / code | Description |
|---------------|-------------|
| 200 / success | Request successful |
| 400 | Invalid request parameters |
| 401 | Authentication failed, please check API Key |
| 402 | Insufficient account balance / points |
| 429 | Request rate limit exceeded |
| 500 | Internal server error |

## Usage Flow

1. Obtain your API Key from the console
2. Call the endpoint with `key` and required parameters
3. Parse the JSON (or binary) response according to the examples above

---

_Generated for AI / LLM consumption. Source of truth: `api_list` (same as HTML `/doc/{id}`)._
