Create speech
Convert text into a binary audio stream, with optional voice cloning from reference audio in the same request.
POST /api/v1/audio/speech
Generate audio with Qwen Audio 3.0 TTS Flash. When input_references is supplied, GlobalRouter first creates a one-time voice from the reference audio, then synthesizes speech. The response is a file stream, not a JSON object.
Back to Audio endpoint listRequest parameters
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Always qwen-audio-3.0-tts-flash. |
input | string | Yes | Text to synthesize into speech. |
voice | string | No | Preset voice when input_references is omitted; otherwise a one-time voice is generated from the reference audio. |
input_references | array | No | Reference input array; input_audio enables voice cloning within the same request. |
input_references[].type | string | Yes (when input_references is supplied) | Always input_audio. |
input_references[].input_audio.data | string | Yes (when input_references is supplied) | Reference audio as a Base64 Data URI: data:audio/wav;base64,<BASE64>, data:audio/mpeg;base64,<BASE64>, or data:audio/mp4;base64,<BASE64>. |
response_format | string | No | Output format: mp3, pcm, wav, or opus; defaults to pcm. |
speed | number | No | Speech speed, from 0.5 to 2; defaults to 1. |
provider.provider_id | string | Yes when input_references is supplied | Provider selection; currently only ali is supported. |
provider.options.ali.sample_rate | integer | No | Sample rate: 8000, 16000, 22050, 24000, 44100, or 48000. |
provider.options.ali.volume | integer | No | Volume, from 0 to 100. |
provider.options.ali.pitch | number | No | Pitch, from 0.5 to 2. |
provider.options.ali.seed | integer | No | Random seed, from 0 to 65535. |
provider.options.ali.language_hints | string[] | No | Single language hint, such as ["zh"]. |
provider.options.ali.instruction | string | No | Voice style or delivery instructions. |
Request examples
curl -X POST "https://api.globalrouter.com/api/v1/audio/speech" \
-H "Authorization: Bearer $GR_API_KEY" \
-H "Content-Type: application/json" \
-o response.mp3 \
-d '{
"model": "qwen-audio-3.0-tts-flash",
"input": "你好,欢迎使用 GlobalRouter。",
"input_references": [
{
"type": "input_audio",
"input_audio": {
"data": "data:audio/wav;base64,<BASE64_AUDIO>"
}
}
],
"response_format": "mp3",
"speed": 1,
"provider": {
"provider_id": "ali"
}
}'Response fields
| Field | Type | Required | Description |
|---|---|---|---|
Content-Type | header | Yes | Audio MIME type: audio/mpeg, audio/pcm, audio/wav, or audio/ogg. |
Content-Disposition | header | Yes | Download filename with an extension matching response_format. |
X-Generation-Id | header | Yes | GlobalRouter generation record ID for troubleshooting. |
body | binary | Yes | Binary audio file stream. |
Response example
HTTP/1.1 200 OK Content-Type: audio/mpeg Content-Disposition: attachment; filename="speech.mp3" X-Generation-Id: gen_123 <binary audio stream>
Errors
| HTTP | Code | Description |
|---|---|---|
| 400 | ROUTER_AUDIO_MODEL_UNSUPPORTED | model is not a currently supported TTS model. |
| 400 | ROUTER_AUDIO_PROVIDER_UNSUPPORTED | provider_id is not ali. |
| 422 | validation_error | Invalid request format, such as an unsupported response_format or an out-of-range speed. |
Notes
- The endpoint requires an API key with tasks scope and permission to use the requested model.
- Save the response file according to response_format; this endpoint does not return an audio URL in JSON.
- input_references[].input_audio.data must be a complete Base64 Data URI, not bare Base64, a file path, or a remote URL. Supported formats are WAV, MP3, and M4A (audio/wav, audio/mpeg, audio/mp4), up to 10 MiB after decoding.
- Voice cloning and synthesis complete in one request without returning a reusable voice_id. Use clear, continuous speech: at least 5 seconds is required, 10 to 20 seconds is recommended, and the maximum is 60 seconds.