The HTTP API for CosyVoice non-real-time speech synthesis, including non-streaming and SSE requests, request parameters, and response fields.
Endpoints
Replace YOUR_WORKSPACE_ID with the workspace ID for the region and use an API key for the same region.
China (Beijing)
POST https://YOUR_WORKSPACE_ID.cn-beijing.maas.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer
Request headers
| Parameter | Type | Required | Description |
|---|---|---|---|
|
| Required | The authentication token in the format |
|
| Required | Set to |
|
| Optional | Set to |
Examples
Non-streaming
curl -X POST "https://YOUR_WORKSPACE_ID.cn-beijing.maas.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "cosyvoice-v3-flash",
"input": {
"text": "我家的后面有一个很大的花园。",
"voice": "longanyang",
"format": "wav",
"sample_rate": 24000
}
}'
Streaming
curl --no-buffer -X POST "https://YOUR_WORKSPACE_ID.cn-beijing.maas.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-DashScope-SSE: enable" \
-d '{
"model": "cosyvoice-v3-flash",
"input": {
"text": "我家的后面有一个很大的花园。",
"voice": "longanyang",
"format": "wav",
"sample_rate": 24000
}
}'
NoteAn SSE event may contain multiple data: lines. Combine all data: lines in the event before parsing JSON. Base64-decode and concatenate audio chunks in event order. The final frame has output.finish_reason=stop and returns the complete audio URL.
Request body
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
|
| Required | — | The speech synthesis model ID. See Non-real-time speech synthesis for models and regions. |
|
| Required | — | The input parameters. |
|
| Required | — | Text to synthesize. Set |
|
| Required | — | The voice ID. For system voices, see the voice list. Create a custom voice with voice cloning or voice design, then synthesize with its bound target model. |
|
| Optional |
| Audio encoding. Valid values: |
|
| Optional | 22050 | Audio sample rate in Hz. Valid values: 8000, 12000, 16000, 22050, 24000, 44100, and 48000. With |
|
| Optional | 50 | Volume. Range: [0, 100]. |
|
| Optional | 1.0 | Speaking rate. Range: [0.5, 2.0]. |
|
| Optional | 32 | Audio bitrate in kbps. Range: [6, 510]. Applies only when |
|
| Optional | 1.0 | Pitch. Range: [0.5, 2.0]. |
|
| Optional | — | Whether to enable SSML. See Usage limits for model, voice, and interface restrictions. |
|
| Optional |
| Whether to return word-level timestamps. Streaming output only. Supports cloned voices of cosyvoice-v3.5-plus, cosyvoice-v3.5-flash, cosyvoice-v3-flash, cosyvoice-v3-plus, and cosyvoice-v2, and system voices marked as supported in the voice list. Cloned voices of other models are not supported. |
|
| Optional | 0 | Random seed. Range: [0, 65535]. With the same model version, text, voice, and other parameters, the same seed reproduces the same synthesis result. |
|
| Optional | — | The target synthesis language. Only the first array element is processed. This is independent of the source language of a cloning sample. Set it for unexpected pronunciation of numbers, abbreviations, symbols, or less common languages. Language codes are listed below. For the cloning source language, see the voice cloning API. |
|
| Optional | — | An instruction controlling dialect, emotion, or role. See Instruction control for model and voice support and usage. |
|
| Optional |
| Whether to embed an invisible AIGC identifier in WAV, MP3, or Opus audio. Supported only by cosyvoice-v3-flash, cosyvoice-v3-plus, and cosyvoice-v2. |
|
| Optional | Alibaba Cloud UID | The Supported only by cosyvoice-v3-flash, cosyvoice-v3-plus, and cosyvoice-v2. |
|
| Optional | Request ID of this request | The Supported only by cosyvoice-v3-flash, cosyvoice-v3-plus, and cosyvoice-v2. |
|
| Optional | — | Text hotfix configuration. Not supported by cosyvoice-v2. |
|
| Optional |
| Whether to filter Markdown markers before synthesis. Supported only for cloned voices of cosyvoice-v3-flash. |
Language codes
zh: Chineseen: Englishfr: Frenchde: Germanja: Japaneseko: Koreanru: Russianpt: Portugueseth: Thaiid: Indonesianvi: Vietnamesees: Spanishit: Italianms: Malayfil: Filipinoar: Arabic
Example text hotfix configuration:
{
"hot_fix": {
"pronunciation": [
{
"天气": "tian1 qi4"
}
],
"replace": [
{
"今天": "金天"
}
]
}
}
Response body
| Parameter | Type | Description |
|---|---|---|
|
| The unique request identifier. |
|
| The model output. |
|
| The stop reason. |
|
| Returned only for streaming output. |
|
| A sentence segmented from the input text. May be absent for the final sentence. |
|
| Sentence information. |
|
| The sentence index, starting at 0. |
|
| Words in the sentence and their timestamps. |
|
| A word or character. |
|
| The start position in the sentence, starting at 0. |
|
| The end position in the sentence, starting at 1. |
|
| The audio start timestamp of the word, in milliseconds. |
|
| The audio end timestamp of the word, in milliseconds. |
|
| The synthesized audio. |
|
| A Base64 audio chunk for streaming output. Empty for non-streaming output. |
|
| The complete audio file URL, valid for 24 hours. |
|
| The synthesized audio identifier. |
|
| The expiry timestamp of |
|
| Usage information. |
|
| Cumulative billable characters. |
Non-streaming
{
"output": {
"audio": {
"data": "",
"id": "audio_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"expires_at": 1792079570,
"url": "https://example.com/output.wav"
},
"finish_reason": "stop"
},
"usage": {
"characters": 27
},
"request_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
Streaming
Intermediate result:
{
"request_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"output": {
"finish_reason": null,
"type": "sentence-begin",
"original_text": "我家的后面有一个很大的花园。",
"sentence": {
"index": 0,
"words": []
},
"audio": {
"data": "",
"id": "audio_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"expires_at": 1792079570
}
}
}
Final result:
{
"output": {
"audio": {
"data": "",
"id": "audio_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"expires_at": 1792079570,
"url": "https://example.com/output.wav"
},
"finish_reason": "stop"
},
"usage": {
"characters": 27
},
"request_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}