Skip to main content

Qwen-Audio-TTS server events

Server event reference for Qwen-Audio-TTS: task startup, sentence synthesis, completion, failure, and corresponding requests.

Event flow

  1. Send run-task to start and configure the task, then wait for task-started.
  2. After receiving task-started, send text through continue-task while receiving result-generated events and synthesized audio.
  3. 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.

task-started

Indicates that the task has started successfully and the client can begin sending text for synthesis.
Wait for task-started before sending continue-task. run-task only starts and configures the task. Send the text to synthesize through continue-task.
headerobject
task_idstring
The task ID generated by the client.
eventstring
Event type. Fixed value: task-started.
payloadobject
Empty object.
Request:
{
  "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
    }
  }
}
Response:
{
  "header": {
    "task_id": "f604f46b-5329-4520-a767-4ede894e0418",
    "task_uuid": "573f4010c82040ad90d2a15e7d8afdbd",
    "event": "task-started",
    "attributes": {}
  },
  "payload": {}
}

result-generated

Returns sentence metadata, including sentence starts, audio chunk markers, and sentence ends.
sentence-end marks the completion of a sentence, not the entire task. The task ends when task-finished arrives. Audio is returned through WebSocket binary frames or an AOQ Audio Track.
headerobject
task_idstring
The task ID generated by the client.
eventstring
Event type. Fixed value: result-generated.
payloadobject
outputobject
Output information.
sentenceobject
indexinteger
Sentence index, starting from 0.
wordsarray
Word-level timestamp array.
textstring
Text content of the word.
begin_indexinteger
Start character index of the word within the sentence. Starts at 0.
end_indexinteger
End character index of the word within the sentence. Starts at 1.
begin_timeinteger
Start time of the word's corresponding audio, in milliseconds.
end_timeinteger
End time of the word's corresponding audio, in milliseconds.
typestring
Sub-event type. Valid values:
  • sentence-begin: Sentence start. Returns the text to be synthesized.
  • sentence-synthesis: Marks an audio frame. One audio frame is transmitted over the WebSocket binary channel immediately after each event.
  • sentence-end: Sentence end. Returns the text content and usage information (usage).
original_textstring
Text of the sentence as segmented for synthesis.
usageobject
Billing usage, returned in the sentence-end event.
  • usage contains cumulative usage for the current task. Do not add usage values across events. After the task completes, use the final cumulative usage in task-finished.
  • qwen-audio-3.1-tts-flash: billed by input and output tokens, reported in input_tokens and output_tokens, respectively. The combined usage is reported in total_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_tokensinteger
Input token count for this request.
output_tokensinteger
Output token count for this request.
total_tokensinteger
Sum of input and output tokens.
charactersinteger
Cumulative number of billed characters.
The following examples set word_timestamp_enabled=true when starting the task.
  • sentence-begin
  • sentence-synthesis
  • sentence-end
Request:
{
  "header": {
    "action": "continue-task",
    "task_id": "51bcc1f0-b65f-484a-8f5f-5f22b2a90607",
    "streaming": "duplex"
  },
  "payload": {
    "input": {
      "text": "Welcome to the speech synthesis service."
    }
  }
}
Response:
{
  "header": {
    "task_id": "51bcc1f0-b65f-484a-8f5f-5f22b2a90607",
    "event": "result-generated",
    "attributes": {
      "x-dashscope-inner-response-type": "ws"
    }
  },
  "payload": {
    "output": {
      "sentence": {
        "index": 0,
        "words": [
          {
            "text": "Welcome",
            "begin_index": 0,
            "end_index": 1,
            "begin_time": 80,
            "end_time": 400
          },
          {
            "text": " to",
            "begin_index": 1,
            "end_index": 2,
            "begin_time": 400,
            "end_time": 640
          },
          {
            "text": " the",
            "begin_index": 2,
            "end_index": 3,
            "begin_time": 640,
            "end_time": 720
          },
          {
            "text": " speech",
            "begin_index": 3,
            "end_index": 4,
            "begin_time": 720,
            "end_time": 1040
          },
          {
            "text": " synthesis",
            "begin_index": 4,
            "end_index": 5,
            "begin_time": 1120,
            "end_time": 1600
          }
        ]
      },
      "type": "sentence-begin",
      "original_text": "Welcome to the speech synthesis service.",
      "normalized_text": "Welcome to the speech synthesis service."
    }
  }
}

task-finished

The server returns a task-finished event when the task completes. The client can then close the WebSocket connection or reuse it to start a new task.
headerobject
task_idstring
The task ID generated by the client.
eventstring
Event type. Fixed value: task-finished.
payloadobject
usageobject
The fields are the same as usage in result-generated.
Request:
{
  "header": {
    "action": "finish-task",
    "task_id": "f604f46b-5329-4520-a767-4ede894e0418",
    "streaming": "duplex"
  },
  "payload": {
    "input": {}
  }
}
Response:
{
  "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
    }
  }
}

task-failed

The server returns a task-failed event when the task fails. On receiving this event, the client must close the WebSocket connection and handle the error.
headerobject
task_idstring
The task ID generated by the client.
eventstring
Event type. Fixed value: task-failed.
error_codestring
Error code.
error_messagestring
Detailed error message.
This example uses an unsupported audio format. After the task starts and text is sent, the server returns an error. The error code and message depend on the cause of failure.
Request:
{
  "header": {
    "action": "run-task",
    "task_id": "7b091c3c-4b35-4c54-9b22-250749ce1b74",
    "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": "invalid-format",
      "sample_rate": 22050
    }
  }
}
Response:
{
  "header": {
    "task_id": "7b091c3c-4b35-4c54-9b22-250749ce1b74",
    "event": "task-failed",
    "error_code": "InvalidParameter",
    "error_message": "Request format is invalid!"
  },
  "payload": {}
}