Skip to main content

Qwen-Audio-ASR-Streaming server events

Server event reference for Qwen-Audio-ASR-Streaming: task startup, recognition results, completion, failure, and corresponding requests.

Event flow

  1. Send run-task. Wait for task-started before sending audio.
  2. Continue sending audio while receiving result-generated events.
  3. After sending all audio, send finish-task and receive results until task-finished arrives. A failed task returns task-failed.
Audio is not sent in run-task: WebSocket uses binary frames, and AOQ uses an Audio Track. 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 audio.
Wait for task-started before sending audio. run-task only starts and configures the task; it does not carry audio data.
headerobject
task_idstring
The task ID generated by the client (in UUID format).
eventstring
The event type. This value is always task-started.
attributesobject
Additional attributes. This value is usually empty.
payloadobject
This value is always {}.
Request:
{
  "header": {
    "action": "run-task",
    "task_id": "3d30b8aa-8859-46ef-a65a-32cf5a9f0ca4",
    "streaming": "duplex"
  },
  "payload": {
    "task_group": "audio",
    "task": "asr",
    "function": "recognition",
    "model": "qwen-audio-3.1-asr-flash-streaming",
    "parameters": {
      "format": "pcm",
      "sample_rate": 16000
    },
    "input": {}
  }
}
Response:
{
  "header": {
    "task_id": "3d30b8aa-8859-46ef-a65a-32cf5a9f0ca4",
    "task_uuid": "f32fbf86736e4c279b5d133bff74b657",
    "event": "task-started",
    "attributes": {}
  },
  "payload": {}
}

result-generated

Returns recognition results, including sentence starts, intermediate results, final sentence results, and heartbeats.
sentence_end=true marks the end of a sentence, not the task. You can skip heartbeat results (heartbeat=true). The task ends when task-finished arrives.
headerobject
task_idstring
The task ID generated by the client (in UUID format).
eventstring
The event type. This value is always result-generated.
payloadobject
outputobject
sentenceobject
sentence_idinteger
The sequence identifier of the sentence. In normal recognition results, sentence_id increments from 1. When heartbeat is true (that is, a heartbeat packet), sentence_id is always 0.
begin_timeinteger
The start time of the sentence, in milliseconds.
end_timeinteger | null
The end time of the sentence, in milliseconds. May be null in intermediate results or heartbeats.
textstring
The recognized text.
sentence_beginboolean
Indicates the start of a sentence.
sentence_endboolean
Whether the sentence has ended (true = final result, false = intermediate result).
heartbeatboolean
If this value is true, the result is a heartbeat packet and can be ignored.
wordsarray[object]
Word-level timestamp information.
begin_timeinteger
The start time of the word, in milliseconds.
end_timeinteger
The end time of the word, in milliseconds.
textstring
The recognized text.
punctuationstring
The punctuation mark.
usageobject
Cumulative usage for the current task.
usage contains cumulative usage for the current task and may be absent from some intermediate results. Do not add usage values across events. qwen-audio-3.0-asr-flash-streaming is billed by duration, and qwen-audio-3.1-asr-flash-streaming by tokens. See the field descriptions for applicability.
durationinteger
Cumulative audio duration, in seconds.
Used for billing for qwen-audio-3.0-asr-flash-streaming.
input_tokensinteger
Cumulative input tokens.
Applies to qwen-audio-3.1-asr-flash-streaming.
output_tokensinteger
Cumulative output tokens.
Applies to qwen-audio-3.1-asr-flash-streaming.
total_tokensinteger
Total cumulative tokens, equal to the sum of input and output tokens.
Applies to qwen-audio-3.1-asr-flash-streaming.
  • Sentence start
  • Intermediate result
  • Final sentence result
  • Heartbeat
After receiving task-started, send audio. The example below is one subsequent result-generated event. Audio is sent as binary frames over WebSocket or through the Audio Track over AOQ.
Request:
{
  "header": {
    "action": "run-task",
    "task_id": "3d30b8aa-8859-46ef-a65a-32cf5a9f0ca4",
    "streaming": "duplex"
  },
  "payload": {
    "task_group": "audio",
    "task": "asr",
    "function": "recognition",
    "model": "qwen-audio-3.1-asr-flash-streaming",
    "parameters": {
      "format": "pcm",
      "sample_rate": 16000
    },
    "input": {}
  }
}
Response:
{
  "header": {
    "task_id": "3d30b8aa-8859-46ef-a65a-32cf5a9f0ca4",
    "event": "result-generated",
    "attributes": {}
  },
  "payload": {
    "output": {
      "sentence": {
        "sentence_id": 1,
        "begin_time": 0,
        "end_time": null,
        "text": "",
        "channel_id": 0,
        "sentence_end": false,
        "sentence_begin": true,
        "words": []
      },
      "text": "",
      "request_id": "3d30b8aa-8859-46ef-a65a-32cf5a9f0ca4",
      "output": {
        "sentence": {
          "sentence_id": 1,
          "begin_time": 0,
          "end_time": null,
          "text": "",
          "channel_id": 0,
          "sentence_end": false,
          "sentence_begin": true,
          "words": []
        },
        "text": "",
        "request_id": "3d30b8aa-8859-46ef-a65a-32cf5a9f0ca4"
      }
    }
  }
}

task-finished

Indicates that task processing is complete. All recognition results for the task have been returned.
headerobject
task_idstring
The task ID generated by the client (in UUID format).
eventstring
The event type. This value is always task-finished.
attributesobject
Additional attributes. This value is usually empty.
payloadobject
usageobject
Cumulative usage at the end of the task. The fields have the same meanings as in result-generated.usage.
Request:
{
  "header": {
    "action": "finish-task",
    "task_id": "3d30b8aa-8859-46ef-a65a-32cf5a9f0ca4",
    "streaming": "duplex"
  },
  "payload": {
    "input": {}
  }
}
Response:
{
  "header": {
    "task_id": "3d30b8aa-8859-46ef-a65a-32cf5a9f0ca4",
    "event": "task-finished",
    "attributes": {}
  },
  "payload": {
    "output": {},
    "usage": {
      "duration": 4,
      "input_tokens": 50,
      "output_tokens": 13,
      "total_tokens": 63
    }
  }
}

task-failed

Indicates that the task failed. Check error_code and error_message for the cause. After a task fails, the WebSocket connection is closed and cannot be reused.
headerobject
task_idstring
The task ID generated by the client (in UUID format).
eventstring
The event type. This value is always task-failed.
error_codestring
A description of the error type.
error_messagestring
The specific cause of the error.
attributesobject
Additional attributes. This value is usually empty.
payloadobject
This value is always {}.
This request uses an unsupported audio format to demonstrate task-failed. The error code and message depend on the cause of failure.
Request:
{
  "header": {
    "action": "run-task",
    "task_id": "9272a5a2-8df4-4f2d-af0e-e544c17f3e42",
    "streaming": "duplex"
  },
  "payload": {
    "task_group": "audio",
    "task": "asr",
    "function": "recognition",
    "model": "qwen-audio-3.1-asr-flash-streaming",
    "parameters": {
      "format": "invalid-format",
      "sample_rate": 16000
    },
    "input": {}
  }
}
Response:
{
  "header": {
    "task_id": "9272a5a2-8df4-4f2d-af0e-e544c17f3e42",
    "event": "task-failed",
    "error_code": "UNSUPPORTED_FORMAT",
    "error_message": "UNSUPPORTED_FORMAT"
  },
  "payload": {}
}