Qwen-Audio-TTS client events
Client event reference for Qwen-Audio-TTS: run-task, continue-task, and finish-task fields, event order, and corresponding server events.
Event flow
- Send run-task to start and configure the task, then wait for task-started.
- After receiving
task-started, send text through continue-task while receiving result-generated events and synthesized audio. - After sending all text, send finish-task and keep receiving remaining results and audio until task-finished arrives. A failed task returns task-failed.
result-generated returns sentence metadata. Audio is transmitted separately as binary frames over WebSocket or through an Audio Track over AOQ. For connection setup, authentication, and audio transport, see WebSocket API or AOQ access.
run-task
Immediately after establishing the connection, the client sends run-task to start a speech synthesis task and set the model, voice, sample rate, and other parameters.
ImportantWait for task-started before sending continue-task. run-task only starts and configures the task. Send the text to synthesize through continue-task.
headerobjectRequiredactionstringRequiredThe command type. Set to run-task.
task_idstringRequiredA client-generated task ID in UUID format. This ID correlates subsequent events and must match the task_id in the continue-task and finish-task commands.
streamingstringRequiredSet to duplex.
payloadobjectRequiredtask_groupstringRequiredThe task group. Set to audio.
taskstringRequiredThe task type. Set to tts.
functionstringRequiredThe function type. Set to SpeechSynthesizer.
modelstringRequiredThe model name.
parametersobjectRequiredSpeech synthesis parameters.
text_typestringRequiredSet to PlainText.
voicestringRequiredThe voice used for speech synthesis.
- System voices: See Qwen-Audio-TTS voice list
- Cloned voices: Custom voices created through voice cloning
- Custom voices: Custom voices created through voice design
formatstringOptionalThe audio encoding format.
Valid values:
pcmwavmp3(default)opus
sample_rateintegerOptionalThe audio sample rate in Hz.
Valid values: 8000, 16000, 22050 (default), 24000, 44100, 48000.
volumeintegerOptionalThe volume level.
Default value: 50.
Valid values: [0, 100].
ratefloatOptionalThe speech rate.
Default value: 1.0.
Valid values: [0.5, 2.0].
pitchfloatOptionalThe pitch.
Default value: 1.0.
Valid values: [0.5, 2.0].
bit_rateintegerOptionalThe audio bit rate in kbps. When the audio format is mp3 or opus, use bit_rate to adjust the bit rate.
Default value: 32.
Valid values: [6, 510].
enable_ssmlbooleanOptionalSpecifies whether to enable SSML.
Default value: false.
NoteWhen set to true, only one continue-task command is allowed.
For the SSML usage restrictions (supported models, voices, and APIs), see Limitations.
word_timestamp_enabledbooleanOptionalSpecifies whether to enable word-level timestamps.
Default value: false.
NoteAvailable only in streaming output mode. Cloned voices are supported. For supported system voices, see Qwen-Audio-TTS voice list.
seedintegerOptionalA random seed for controlling variation in the synthesis output. When the model version, text, voice, and other parameters are unchanged, using the same seed produces identical results.
Default value: 0.
Valid values: [0, 65535].
language_hintsarray[string]OptionalNote
- This parameter is an array, but the current version only processes the first element. Pass a single value.
- This parameter specifies the target language for speech synthesis. It's unrelated to the language of the audio sample used in voice cloning. To set the source language for a cloning task, see the voice cloning API reference.
Specifies the target language for speech synthesis to improve output quality.
When digit pronunciation, abbreviation expansion, symbol reading, or minority-language synthesis doesn't meet expectations, use this parameter. For example:
- Unexpected digit
pronunciation: "hello, this is 110" is read as "hello, this is one one zero" instead of the expected Chinesepronunciation - Inaccurate symbol
pronunciation: "@" is read as the Chinese equivalent instead of "at" - Poor minor language synthesis quality with unnatural results
Valid values
-
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: Malaysian -
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.
instructionstringOptionalSets an instruction to control dialect, emotion, or voice character during synthesis. For detailed usage, see Instruction control.
enable_aigc_tagbooleanOptionalSpecifies whether to embed an AIGC watermark in the generated audio. When set to true, the watermark is embedded in audio files of supported formats (wav/mp3/opus).
Default value: false.
aigc_propagatorstringOptionalSets the ContentPropagator field in the AIGC watermark, identifying the content propagator. Takes effect only when enable_aigc_tag is true.
Default value: Alibaba Cloud UID.
aigc_propagate_idstringOptionalSets the PropagateID field in the AIGC watermark, uniquely identifying a specific propagation action. Takes effect only when enable_aigc_tag is true.
Default value: The request ID of the current speech synthesis request.
hot_fixobjectOptionalConfigures pronunciation corrections and text replacements applied before synthesis.
Parameters:
pronunciation: Custom pronunciation. Specifies pinyin annotations for words to correct inaccurate default pronunciations.replace: Text replacement. Replaces specified words with target text before synthesis. The replaced text is used as the actual synthesis input.
This example uses pinyin to specify the pronunciation of a Chinese word and replaces text before synthesis.
{
"hot_fix": {
"pronunciation": [
{
"天气": "tian1 qi4"
}
],
"replace": [
{
"今天": "金天"
}
]
}
}
inputobjectRequiredSet to an empty object {}. Send the text to synthesize through the continue-task command.
{
"header": {
"action": "run-task",
"task_id": "f604f46b-5329-4520-a767-4ede894e0418",
"streaming": "duplex"
},
"payload": {
"input": {},
"task_group": "audio",
"task": "tts",
"function": "SpeechSynthesizer",
"model": "qwen-audio-3.1-tts-flash",
"parameters": {
"text_type": "PlainText",
"voice": "longanhuan_v3.1",
"format": "mp3",
"sample_rate": 22050
}
}
}
{
"header": {
"task_id": "f604f46b-5329-4520-a767-4ede894e0418",
"task_uuid": "573f4010c82040ad90d2a15e7d8afdbd",
"event": "task-started",
"attributes": {}
},
"payload": {}
}
continue-task
After receiving task-started, the client sends continue-task to submit text for synthesis. Text can be sent all at once or in sequential segments.
headerobjectRequiredactionstringRequiredThe command type. Set to continue-task.
task_idstringRequiredThe task ID in UUID format. Must match the task_id in run-task.
streamingstringRequiredSet to duplex.
payloadobjectRequiredinputobjectRequiredContains the text to synthesize.
textstringRequiredThe text to synthesize. Maximum of 20,000 characters per message and 200,000 characters cumulatively.
NoteThe send interval must not exceed 23 seconds; otherwise, the connection times out.
{
"header": {
"action": "continue-task",
"task_id": "f604f46b-5329-4520-a767-4ede894e0418",
"streaming": "duplex"
},
"payload": {
"input": {
"text": "Welcome to the speech synthesis service."
}
}
}
{
"header": {
"task_id": "f604f46b-5329-4520-a767-4ede894e0418",
"event": "result-generated",
"attributes": {
"x-dashscope-inner-response-type": "ws"
}
},
"payload": {
"output": {
"sentence": {
"index": 0,
"words": []
},
"type": "sentence-begin",
"original_text": "Welcome to the speech synthesis service.",
"normalized_text": "Welcome to the speech synthesis service."
}
}
}
finish-task
Immediately after sending all text, the client sends finish-task to notify the server that text input is complete and request task completion. To cancel the current synthesis turn, set directive to cancel in input.
ImportantAfter sending finish-task, keep receiving remaining synthesis results and audio until task-finished arrives. When a task is cancelled, the server stops outputting subsequent audio and returns task-finished.
headerobjectRequiredactionstringRequiredThe command type. Set to finish-task.
task_idstringRequiredThe task ID in UUID format. Must match the task_id in run-task.
streamingstringRequiredSet to duplex.
payloadobjectRequiredinputobjectRequiredSet to {} for normal task completion. Include directive to cancel the current synthesis turn.
directivestringOptionalControls how the task ends. Currently only cancel is supported. When set to cancel, the current synthesis turn is canceled and the server immediately returns a task-finished event without producing further audio.
After cancellation, you can start a new synthesis task on the same WebSocket connection by sending a new run-task event without reconnecting.
Normal completion
{
"header": {
"action": "finish-task",
"task_id": "f604f46b-5329-4520-a767-4ede894e0418",
"streaming": "duplex"
},
"payload": {
"input": {}
}
}
{
"header": {
"task_id": "f604f46b-5329-4520-a767-4ede894e0418",
"event": "task-finished",
"attributes": {
"x-dashscope-inner-response-type": "ws"
}
},
"payload": {
"output": {},
"usage": {
"input_tokens": 7,
"output_tokens": 30,
"total_tokens": 37,
"characters": 40
}
}
}
Cancel task
{
"header": {
"action": "finish-task",
"task_id": "8dc46e0b-080a-4a40-bd6a-91d329221de1",
"streaming": "duplex"
},
"payload": {
"input": {
"directive": "cancel"
}
}
}
{
"header": {
"task_id": "8dc46e0b-080a-4a40-bd6a-91d329221de1",
"event": "task-finished",
"attributes": {
"x-dashscope-inner-response-type": "ws"
}
},
"payload": {
"output": {}
}
}