API 文档AI 模型接口语音Bilibili

音色语音合成

使用内置音色或自定义音色 ID 将文本合成为 WAV 音频。

使用内置音色或已上传的自定义音色,将文本合成为 WAV 音频。成功时直接返回二进制音频流,而不是 JSON URL。

Base URL

  • https://api.autorouter.top — Production

Authentication

BearerAuth: http (bearer) 使用 Bearer Token 认证。 格式: Authorization: Bearer sk-xxxxxx

Endpoints

POST /v1/audio/speech

创建音色语音合成请求

传入文本与音色,响应返回 WAV 音频。

Request Body

Content-Type: application/json

Example:

{
  "model": "IndexTeam/IndexTTS-2",
  "input": "你好!欢迎使用语音合成服务。",
  "voice": "jack_cheng"
}

Properties:

NameTypeRequiredDescription
modelstringYes模型名称。固定为 IndexTeam/IndexTTS-2
inputstringYes待合成文本,长度不超过 600 个字符
voicestringYes音色。内置音色、自定义 uspeech:... ID,或空字符串使用默认音色

voicestring(必选)

音色标识,三选一:

内置音色:

  • jack_cheng
  • sales_voice
  • crystla_liu
  • stephen_chow
  • xiaoyueyue
  • mkas
  • entertain
  • novel
  • movie

自定义音色: 通过「上传音色」接口获得的 ID,格式 uspeech:xxxx-xxxx-xxxx-xxxx。

空字符串: 使用文档中的默认音色行为。

Responses

200: 合成成功,返回 WAV 音频流

Content-Type: audio/wav

400: 请求参数错误

Content-Type: application/json

请求示例

curl -X POST "https://api.autorouter.top/v1/audio/speech" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-xxxxxx" \
  --output speech.wav \
  -d '{
  "model": "IndexTeam/IndexTTS-2",
  "input": "你好!欢迎使用语音合成服务。",
  "voice": "jack_cheng"
}'

响应示例

<binary WAV audio stream>

响应字段说明:

NameTypeDescription
(body)binary成功时为 WAV 音频流,Content-Type: audio/wav
error.messagestring错误说明(失败时)
error.typestring错误类型,如 invalid_request_error
error.codestring机器可读错误码
error.paramstring请求 ID 或出错参数名

错误处理

HTTP 400 参数错误

场景响应
未传 input / voice / model{"error":{"message":"...","type":"invalid_request_error","code":"...","param":"..."}}
input 超过 600 字符{"error":{"message":"...","type":"invalid_request_error","code":"...","param":"input"}}
自定义音色不存在或已删除{"error":{"code":"invalid_voice_id",...}}

HTTP 401 / 403 鉴权错误

  • 401 Unauthorized:API Key 无效或已过期
  • 403 Forbidden:API Key 无权访问此模型(检查 token 的模型白名单)

HTTP 402 余额不足

返回 insufficient user quota。请前往 AutoRouter 控制台充值。

目录