Qwen-Audio-TTS HTTP API
Synthesize text into speech and receive a complete audio file URL or audio chunks over SSE.
NoteThe examples use China (Beijing). Replace {WorkspaceId} with your workspace ID and set DASHSCOPE_API_KEY to an API key for that region.
https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizerRequest headers
AuthorizationstringRequiredUse the API key for the endpoint region, in the format Bearer <API Key>.
Content-TypestringRequiredThe media type of the request body. Fixed to application/json.
X-DashScope-SSEstringOptionalSelect how to receive the synthesized audio.
- Omit the header to receive one JSON response when synthesis finishes.
- Set the header to
enableto stream synthesis results over SSE.
Request body
modelstringRequiredSpeech synthesis model ID.
inputobjectRequiredThe input parameters.
textstringRequiredText to synthesize. Pass plain text directly. For SSML input, set enable_ssml to true.
To read a mathematical expression in Chinese, enclose the LaTeX formula in $ delimiters within the text. No additional parameter is required. For example, $\frac{2}{7}$ is read as two sevenths in Chinese. In a JSON string, escape each backslash as \\. For fraction and radical notation, see LaTeX tags and symbols.
voicestringRequiredThe ID of the voice that model uses for synthesis.
- System voice: Select a voice listed for your model in the voice list.
- Custom voice: Use the ID returned by voice cloning or voice design. Set
modelto the target model you specified when creating the voice.
formatstringOptionalAudio encoding. Valid values: mp3, pcm, wav, and opus.
Default: mp3
sample_rateintegerOptionalAudio sample rate in Hz. Valid values: 8000, 12000, 16000, 22050, 24000, 44100, and 48000.
Default: 22050
NoteWhen format is opus, the supported sample rates are 8000, 12000, 16000, 24000, and 48000 Hz.
bit_rateintegerOptionalNoteApplies only when format is set to opus.
Audio bitrate in kbps. Range: [6, 510].
Default: 32
volumeintegerOptionalVolume. Range: [0, 100].
Default: 50
ratefloatOptionalSpeaking rate. Range: [0.5, 2.0].
Default: 1.0
pitchfloatOptionalPitch. Range: [0.5, 2.0].
Default: 1.0
enable_ssmlbooleanOptionalFor SSML, set enable_ssml to true. For supported models, voices, and tags, see SSML.
word_timestamp_enabledbooleanOptionalNoteApplies only to streaming output.
Set to true to receive word-level start and end times in output.sentence.words. Cloned voices support timestamps. For a system voice, check timestamp support in the voice list.
Default: false
seedintegerOptionalRandom seed. Range: [0, 65535]. With the same model version, text, voice, and other parameters, the same seed reproduces the same synthesis result.
Default: 0
language_hintsarray[string]OptionalSpecifies the language in which to read the input text. Use this hint if numbers, abbreviations, or symbols are pronounced in the wrong language, or if speech in a less common language sounds unnatural.
For example, to have @ read as “at” in English text, pass ["en"]. Specify one language code per request. If you pass several, only the first takes effect.
NoteFor the multilingual and dialect voices of qwen-audio-3.1-tts-flash, this parameter specifies the language or dialect. See multilingual and dialect voice settings for details.
Supported language codes
-
zh: Chinese -
en: English -
fr: French -
de: German -
ja: Japanese -
ko: Korean -
ru: Russian -
pt: Portuguese -
th: Thai -
id: Indonesian -
vi: Vietnamese -
es: Spanish -
it: Italian -
ms: Malay -
fil: Filipino -
ar: Arabic -
other: Other languages (supported by qwen-audio-3.1-tts-flash)Bulgarian, Dutch, Hungarian, Romanian, Danish, Croatian, Greek, Czech, Norwegian, Swedish, Hindi, Slovak, Finnish, Urdu, Serbian, Mexican Spanish, Lithuanian, Latvian, Turkish, Persian, Hebrew, Mongolian, Slovenian, Azerbaijani, Polish, Catalan, Khmer, Brazilian Portuguese, Lao, Georgian, Afrikaans, Nepali, Belarusian, Malayalam, Luxembourgish, Albanian, Tamil, Sinhala, Telugu, Estonian, Cebuano, Bosnian, Burmese, Armenian, Latin, Icelandic, Maltese, Swahili, Kazakh, Seychellois Creole, Ukrainian.
When using a cloned voice, choose the language of the text you want to synthesize. To specify the language of the recording used for cloning, set it when you create the voice.
instructionstringOptionalAn instruction controlling dialect, emotion, or role. See Instruction control for model and voice support and usage.
enable_aigc_tagbooleanOptionalWhether to embed an invisible AIGC identifier in WAV, MP3, or Opus audio.
Default: false
aigc_propagatorstringOptionalNoteApplies only when enable_aigc_tag is set to true.
The ContentPropagator field of the identifier, identifying the distributor.
Default: Alibaba Cloud UID
aigc_propagate_idstringOptionalNoteApplies only when enable_aigc_tag is set to true.
The PropagateID field of the identifier, identifying this distribution operation.
Default: Request ID of this request
hot_fixobjectOptionalAdjusts how specific terms are spoken. Supply a Pinyin pronunciation to correct how a word sounds, or replace the term before synthesis to have the model read different text.
{
"hot_fix": {
"replace": [
{
"TTS": "text to speech"
}
]
}
}
pronunciationarray[object]OptionalMaps words to their Pinyin pronunciations.
replacearray[object]OptionalMaps source text to replacement text before synthesis.
enable_markdown_filterbooleanOptionalWhether to enable Markdown filtering. When enabled, the service converts Markdown into text suitable for reading aloud before synthesis.
Default: false
Response body
request_idstringThe unique request identifier.
outputobjectThe synthesis result. For streaming responses, parse the data: line of each SSE event as JSON, then read the output object.
finish_reasonstringThe reason the synthesis task stopped.
"null"— Synthesis is in progress."stop"— The task finished normally. When streaming, stop reading events after receiving this value.
typestringNoteThis field is returned only for sentence events in streaming responses.
The type of a sentence-level synthesis event. Use it to determine how to handle the text or audio for the current sentence.
sentence-begin— Synthesis of the sentence has started. Read the sentence text fromoutput.original_textwhen present.sentence-synthesis— The event carries one audio chunk for the current sentence inoutput.audio.data. A sentence can produce multiple consecutive chunks.sentence-end— Synthesis of the sentence has finished. The event returns sentence text and cumulativeusageup to this point. Continue reading events untiloutput.finish_reasonis"stop".
original_textstringA sentence segmented from the input text. May be absent for the final sentence.
sentenceobjectSentence information.
indexintegerThe sentence index, starting at 0.
wordsarray[object]Words in the sentence and their timestamps.
textstringA word or character.
begin_indexintegerThe start position in the sentence, starting at 0.
end_indexintegerThe end position in the sentence, starting at 1.
begin_timeintegerThe audio start timestamp of the word, in milliseconds.
end_timeintegerThe audio end timestamp of the word, in milliseconds.
audioobjectThe synthesized audio.
datastringIn streaming output, each sentence-synthesis event carries one Base64-encoded audio chunk in this field. Decode each chunk separately and append the decoded bytes to the same audio file in the order received.
In non-streaming output, this field is empty. Download the complete audio from output.audio.url.
urlstringThe complete audio file URL, valid for 24 hours.
idstringThe synthesized audio identifier.
expires_atintegerThe expiry timestamp of url.
usageobjectUsage is cumulative. For streaming requests, use the usage from the final event. Do not add the values from successive events.
Note
- qwen-audio-3.1-tts-flash: billed by input and output tokens, reported in
input_tokensandoutput_tokens, respectively. The combined usage is reported intotal_tokens. - qwen-audio-3.1-tts-plus: billed by character (
characters). It also returns the token statistics fields listed above. - qwen-audio-3.0-tts-plus and qwen-audio-3.0-tts-flash: billed by character (
characters).
input_tokensintegerThe number of input tokens consumed by this request.
output_tokensintegerThe number of output tokens consumed by this request.
total_tokensintegerThe total number of tokens consumed by this request, equal to the sum of input_tokens and output_tokens.
charactersintegerCumulative character count.
Non-streaming
curl "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
--data '{
"model": "qwen-audio-3.1-tts-flash",
"input": {
"text": "Welcome to Model Studio.",
"voice": "longanhuan_v3.1",
"format": "wav",
"sample_rate": 24000
}
}'
{
"output": {
"audio": {
"data": "",
"id": "audio_15dca606-a804-9cf9-88e3-adae3375af1c",
"expires_at": 1795794025,
"url": "https://example.com/output.wav"
},
"finish_reason": "stop"
},
"usage": {
"input_tokens": 5,
"output_tokens": 21,
"total_tokens": 26,
"characters": 24
},
"request_id": "15dca606-a804-9cf9-88e3-adae3375af1c"
}
Streaming (SSE)
curl --no-buffer "https://{WorkspaceId}.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" \
--data '{
"model": "qwen-audio-3.1-tts-flash",
"input": {
"text": "Welcome to Model Studio.",
"voice": "longanhuan_v3.1",
"format": "wav",
"sample_rate": 24000
}
}'
event:result
data:{"output":{"type":"sentence-begin","original_text":"Welcome to Model Studio.","normalized_text":"Welcome to Model Studio.","audio":{"data":"","id":"audio_dc707279-1337-920e-9347-d00f6c398ce7","expires_at":1795794025},"finish_reason":"null","sentence":{"index":0,"words":[]}},"request_id":"dc707279-1337-920e-9347-d00f6c398ce7"}
event:result
data:{"output":{"type":"sentence-synthesis","audio":{"data":"<base64 audio chunk>","id":"audio_dc707279-1337-920e-9347-d00f6c398ce7","expires_at":1795794025},"finish_reason":"null","sentence":{"index":0,"words":[]}},"request_id":"dc707279-1337-920e-9347-d00f6c398ce7"}
event:result
data:{"output":{"type":"sentence-end","original_text":"Welcome to Model Studio.","normalized_text":"Welcome to Model Studio.","audio":{"data":"","id":"audio_dc707279-1337-920e-9347-d00f6c398ce7","expires_at":1795794025},"finish_reason":"null","sentence":{"index":0,"words":[]}},"usage":{"input_tokens":5,"output_tokens":22,"total_tokens":27,"characters":24},"request_id":"dc707279-1337-920e-9347-d00f6c398ce7"}
event:result
data:{"output":{"audio":{"data":"","id":"audio_dc707279-1337-920e-9347-d00f6c398ce7","expires_at":1795794025,"url":"https://example.com/output.wav"},"finish_reason":"stop"},"usage":{"input_tokens":5,"output_tokens":22,"total_tokens":27,"characters":24},"request_id":"dc707279-1337-920e-9347-d00f6c398ce7"}