API DocsAI Model APIsAudioBilibili

Upload Voice

Upload custom voice material and receive a voice ID for later speech synthesis.

Upload custom voice material for later voice TTS. Speaker audio can be provided as a file, Base64, or a public URL.

On success, the response returns a voice ID with the uspeech: prefix. Use it in the voice field of the Voice TTS endpoint.

Base URL

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

Authentication

BearerAuth: http (bearer) Authenticate using a Bearer Token. Format: Authorization: Bearer sk-xxxxxx

Endpoints

POST /v1/audio/voice/upload

Upload Custom Voice

The request includes a voice name, model, and speaker audio. The response returns a voice ID. Audio format is WAV / MP3, the file must not exceed 20MB, and duration must not exceed 30 seconds. Speaker audio must be provided as one of speaker_file, speaker_file_base64, or speaker_url.

Request Body

Content-Type: multipart/form-data or application/x-www-form-urlencoded

Example:

{
  "name": "温柔女声",
  "model": "IndexTeam/IndexTTS-2",
  "speaker_url": "https://example.com/audio/speaker.wav",
  "emotion_url": "https://example.com/audio/emotion.wav"
}

Properties:

NameTypeRequiredDescription
namestringYesCustom voice name. Examples: 温柔女声, 客服音色A
modelstringYesModel name. Example: IndexTeam/IndexTTS-2
speaker_filefileConditionalSpeaker audio file (multipart only). WAV / MP3, max 20MB, max 30 seconds
speaker_file_base64stringConditionalSpeaker audio Base64
speaker_urlstringConditionalPublic URL of the speaker audio
emotion_filefileNoEmotion reference audio file (multipart only). WAV / MP3, max 20MB
emotion_file_base64stringNoEmotion reference audio Base64
emotion_urlstringNoPublic URL of the emotion reference audio

application/x-www-form-urlencoded does not support file fields; use speaker_file_base64 or speaker_url.

speaker_filefile(Conditional)

Speaker audio used to extract voice features. Provide exactly one of speaker_file, speaker_file_base64, or speaker_url.

Limits:

  • Format: wav, mp3
  • File size: Max 20MB
  • Duration: Max 30 seconds. Upstream computes duration from the WAV header data chunk size. A streaming WAV that never rewrites the real length may be rejected as too long.

Responses

200: Upload succeeded

Content-Type: application/json

400: Bad request / audio constraints not met

Content-Type: application/json

401: Bearer Token invalid or missing

Content-Type: application/json

Request Example

curl -X POST "https://api.autorouter.top/v1/audio/voice/upload" \
  -H "Authorization: Bearer sk-xxxxxx" \
  -F "name=温柔女声" \
  -F "model=IndexTeam/IndexTTS-2" \
  -F "speaker_file=@/path/to/speaker.wav" \
  -F "emotion_file=@/path/to/emotion.wav"

Response Example

{
  "id": "uspeech:xxxx-xxxx-xxxx-xxxx"
}

Response fields:

NameTypeDescription
idstringCustom voice ID in the format uspeech:.... Pass it as voice in later synthesis

Error Handling

HTTP 400 Parameter Errors

Scenarioerror.code
Missing namemissing_name
No speaker audio providedmissing_speaker
Invalid Base64invalid_speaker_base64
Unsupported audio formatunsupported_audio_format
File too largefile_too_large
Duration longer than 30 secondsduration_out_of_range
Sample rate too lowsample_rate_too_low

duration_out_of_range is returned by the upstream provider with HTTP 400 and error.type invalid_request_error. The gateway forwards speaker_file as multipart as-is and only checks file size and extension locally; it does not compute audio duration.

Example:

{
  "error": {
    "message": "Upstream provider error: audio duration must be <= 30 seconds",
    "type": "invalid_request_error",
    "code": "duration_out_of_range"
  }
}

Streaming WAV misread as too long: Some recorders and exporters write streaming WAV files: they first set RIFF chunk size and data chunk size to about 0x7FFFFFFF (~2.1 GB) and never rewrite the real lengths. Python wave and many server-side parsers trust the header data size, compute tens of thousands of seconds, and reject the file. macOS afinfo estimates duration from the actual file size, so the same file may still appear to be only a few seconds long.

Fix: re-export as a standard WAV so the writer backfills the real chunk sizes, or upload MP3 instead.

HTTP 401 / 403 Auth Errors

  • 401 Unauthorized: API Key invalid or expired. Example: {"error":{"message":"Validate Certification failed.","type":"invalid_request_error","code":"auth_error","param":null}}
  • 403 Forbidden: API Key has no access to this model

HTTP 402 Insufficient Balance

Returns insufficient user quota. Top up at the AutoRouter console.

On this page