# 语音合成PRO API Documentation

> 语音合成PRO：文本转语音。使用声音复刻PRO/声音设计PRO返回的音色ID，将文本合成为音频。单次不超过2000计费字符；中文按2字符、英文/标点/空格按1字符计。

## Overview

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

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

## 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 http://apis.xiaobao.ink/api/audio/audiosavepro`
- **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 | 我像小草一样在发芽。 |
| `voice` | Yes | voice-68e021aa448346fb8cc0575a163229eb |
| `format` | Yes | mp3 |
| `sample_rate` | Yes | 22050 |
| `volume` | Yes | 50 |
| `rate` | Yes | 1.0 |
| `pitch` | Yes | 1.0 |
| `base64` | Yes |  |

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

### Request Example

```
http://apis.xiaobao.ink/api/audio/audiosavepro?key=你的密钥
```

## Details

## 请求HEADER：

| 名称 | 值 |
| --- | --- |
| Content-Type | application/x-www-form-urlencoded;charset=utf-8 或 application/json |

## 接口说明：

文本语音合成接口：将文本转为音频。音色ID通过「声音复刻PRO」或「声音设计PRO」获取。

**关联接口：**声音复刻PRO `/api/audio/audiocopypro`、声音设计PRO `/api/audio/sounddesignpro`

## 计费说明：

按量计费：默认 **200 点/万字**（约 2 元/万字）。字符统计：1个中文=2字符，1个英文字母、1个标点或句中空格=1字符。扣点公式：`ceil(计费字符 × 单价 / 10000)`，至少 1 点。

默认返回转存后的 `audio_url`；若传 `base64=true`，则返回音频 Base64。

## 请求参数说明：

| 名称 | 必填 | 类型 | 示例值 | 说明 |
| --- | --- | --- | --- | --- |
| key | 是 | string | 你的平台密钥 | 接口密钥，在控制台→密钥管理查看 |
| text | 是 | string | 我像小草一样在发芽。 | 文本内容，单次不超过2000计费字符；建议使用中文符号；支持识别中小学常见数学表达式 |
| voice | 是 | string | voice-68e021aa448346fb8cc0575a163229eb | 音色ID，通过声音复刻PRO / 声音设计PRO 返回 |
| format | 否 | string | mp3 | 音频格式，默认mp3，支持 mp3、wav、pcm |
| sample_rate | 否 | string | 22050 | 采样率：8000 / 16000 / 22050 / 24000 / 44100 / 48000 |
| volume | 否 | string | 50 | 音量调整（0～100），默认50 |
| rate | 否 | string | 1.0 | 语速调整（0.5～2），默认1.0 |
| pitch | 否 | string | 1.0 | 音调调整（0.5～2），默认1.0 |
| base64 | 否 | string | true | 不传或空：返回 audio_url；传 true：返回 Base64 编码 |

## 返回参数说明：

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| code | int | 状态码 |
| msg | string | 状态信息 |
| data | object | 结果数据 |
| - audio_url | string | 音频地址（未传 base64 时） |
| - base64 | string | 音频 Base64（base64=true 时） |
| - format | string | 音频格式 |
| - sample_rate | int | 采样率 |
| - billable_chars | int | 本次计费字符数 |
| - power_cost | number | 本次扣点 |
| exec_time | float | 执行耗时 |
| ip | string | 客户端IP |

## 错误码：

| 错误码 | 类型 | 说明 |
| --- | --- | --- |
| 403 | int | 没有权限（密钥无效等） |
| 400 | int | 参数传递不正确 / 业务失败 |
| 500 | int | 服务器内部错误 |

## Response Example

```json
{
    "code": 200,
    "msg": "语音合成成功",
    "data": {
        "audio_url": "https://apis.xiaobao.ink/upload/audio/2026/07/15/ttspro_xxx.mp3",
        "format": "mp3",
        "sample_rate": 22050,
        "billable_chars": 20,
        "power_cost": 1
    },
    "exec_time": 1.2,
    "ip": "1.2.3.4"
}
```

## Error Codes

| 错误码 | 类型 | 说明 |
| --- | --- | --- |
| 403 | int | 没有权限（密钥无效等） |
| 400 | int | 参数传递不正确 / 业务失败 |
| 500 | int | 服务器内部错误 |

## 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}`)._
