Qwen-Audio-ASR-Streaming 伺服器事件參考,介紹任務啟動、辨識結果、任務完成和任務失敗的欄位及對應請求。
事件互動流程
- 傳送 run-task,收到 task-started 後開始傳送音訊。
- 持續傳送音訊,同時接收 result-generated。
- 音訊傳送完畢後傳送 finish-task,繼續接收結果,直到收到 task-finished;任務失敗時傳回 task-failed。
音訊資料不透過 run-task 傳送:WebSocket 使用二進位訊框,AOQ 使用 Audio Track。連線、驗證和音訊傳輸方式請參閱 WebSocket API 或 AOQ 接入。
task-started
任務啟動成功,是用戶端開始傳送音訊的訊號。
重要收到 task-started 後才能傳送音訊。 run-task 僅用於啟動和設定任務,不攜帶音訊資料。
headerobjecttask_idstring用戶端產生的任務 ID(UUID 格式)。
eventstring事件類型,固定為 task-started。
attributesobject附加屬性(通常為空白)。
payloadobject固定為{}。
{
"header": {
"action": "run-task",
"task_id": "3756efcf-8388-41c8-832a-9a70bf046f55",
"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": {}
}
}
{
"header": {
"task_id": "3756efcf-8388-41c8-832a-9a70bf046f55",
"task_uuid": "69dc7ec7af9a40118edc548ac3f3d2b4",
"event": "task-started",
"attributes": {}
},
"payload": {}
}
result-generated
傳回辨識結果,包括句子開始、中間結果、句子最終結果和心跳。
重要sentence_end=true 僅表示目前句子結束,不表示任務結束。 心跳結果(heartbeat=true)可略過;任務是否結束以 task-finished 為準。
headerobjecttask_idstring用戶端產生的任務 ID(UUID 格式)。
eventstring事件類型,固定為 result-generated。
payloadobjectoutputobjectsentenceobjectsentence_idinteger句子的序號標識。正常識別結果中,sentence_id 從 1 開始遞增。當 heartbeat 為 true 時(即心跳包),sentence_id 固定為 0。
begin_timeinteger句子開始時間(ms)。
end_timeinteger | null句子結束時間(ms)。 在中間結果或心跳中可能為 null。
textstring識別文本。
sentence_beginboolean用於標識句子開始。
sentence_endboolean是否句子結束(true=最終結果,false=中間結果)。
heartbeatboolean若為 true,可跳過該結果(心跳包)。
wordsarray[object]字時間戳記資訊。
begin_timeinteger字開始時間(ms)。
end_timeinteger字結束時間(ms)。
textstring識別文本。
punctuationstring標點符號。
usageobject目前任務的累計用量。
說明usage 為目前任務的累計用量,部分中間結果可能不包含此欄位。請勿將各事件中的 usage 相加。 qwen-audio-3.0-asr-flash-streaming 按時長計費,qwen-audio-3.1-asr-flash-streaming 按 Token 計費;欄位適用範圍請參閱下文。
durationinteger累計音訊時長(秒)。
說明用於 qwen-audio-3.0-asr-flash-streaming 的計費。
input_tokensinteger累計輸入 Token 數。
說明適用於 qwen-audio-3.1-asr-flash-streaming。
output_tokensinteger累計輸出 Token 數。
說明適用於 qwen-audio-3.1-asr-flash-streaming。
total_tokensinteger累計 Token 總數,為輸入與輸出 Token 數之和。
說明適用於 qwen-audio-3.1-asr-flash-streaming。
句子開始
收到 task-started 後,傳送音訊。以下範例為伺服器隨後傳回的一個 result-generated 事件;音訊透過二進位訊框(WebSocket)或 Audio Track(AOQ)傳送。
{
"header": {
"action": "run-task",
"task_id": "3756efcf-8388-41c8-832a-9a70bf046f55",
"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": {}
}
}
{
"header": {
"task_id": "3756efcf-8388-41c8-832a-9a70bf046f55",
"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": "3756efcf-8388-41c8-832a-9a70bf046f55",
"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": "3756efcf-8388-41c8-832a-9a70bf046f55"
}
}
}
}
中間結果
收到 task-started 後,傳送音訊。以下範例為伺服器隨後傳回的一個 result-generated 事件;音訊透過二進位訊框(WebSocket)或 Audio Track(AOQ)傳送。
{
"header": {
"action": "run-task",
"task_id": "3756efcf-8388-41c8-832a-9a70bf046f55",
"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": {}
}
}
{
"header": {
"task_id": "3756efcf-8388-41c8-832a-9a70bf046f55",
"event": "result-generated",
"attributes": {}
},
"payload": {
"output": {
"sentence": {
"sentence_id": 1,
"begin_time": 0,
"end_time": null,
"text": "情感",
"channel_id": 0,
"sentence_end": false,
"words": [
{
"begin_time": 0,
"end_time": 320,
"text": "情感",
"punctuation": "",
"fixed": false,
"speaker_id": null
}
]
},
"text": "情感",
"request_id": "3756efcf-8388-41c8-832a-9a70bf046f55",
"output": {
"sentence": {
"sentence_id": 1,
"begin_time": 0,
"end_time": null,
"text": "情感",
"channel_id": 0,
"sentence_end": false,
"words": [
{
"begin_time": 0,
"end_time": 320,
"text": "情感",
"punctuation": "",
"fixed": false,
"speaker_id": null
}
]
},
"text": "情感",
"request_id": "3756efcf-8388-41c8-832a-9a70bf046f55"
}
}
}
}
句子最終結果
收到 task-started 後,傳送音訊。以下範例為伺服器隨後傳回的一個 result-generated 事件;音訊透過二進位訊框(WebSocket)或 Audio Track(AOQ)傳送。
{
"header": {
"action": "run-task",
"task_id": "3756efcf-8388-41c8-832a-9a70bf046f55",
"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": {}
}
}
{
"header": {
"task_id": "3756efcf-8388-41c8-832a-9a70bf046f55",
"event": "result-generated",
"attributes": {}
},
"payload": {
"output": {
"sentence": {
"sentence_id": 1,
"begin_time": 160,
"end_time": 6360,
"text": "请把漆原项目的报告发给罗科,下周我们要上线悬枢系统。",
"channel_id": 0,
"sentence_end": true,
"words": [
{
"begin_time": 160,
"end_time": 600,
"text": "请把",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 600,
"end_time": 840,
"text": "漆",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 840,
"end_time": 1160,
"text": "原",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 1160,
"end_time": 1680,
"text": "项目的",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 1680,
"end_time": 2160,
"text": "报告",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 2160,
"end_time": 2600,
"text": "发给",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 2600,
"end_time": 2840,
"text": "罗",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 2840,
"end_time": 3480,
"text": "科",
"punctuation": ",",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 3480,
"end_time": 4000,
"text": "下周",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 4000,
"end_time": 4520,
"text": "我们要",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 4520,
"end_time": 5160,
"text": "上线",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 5160,
"end_time": 5440,
"text": "悬",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 5440,
"end_time": 5680,
"text": "枢",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 5680,
"end_time": 5900,
"text": "系",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 5900,
"end_time": 6360,
"text": "统",
"punctuation": "。",
"fixed": true,
"speaker_id": null
}
],
"stash": {
"sentence_id": 2,
"text": "",
"begin_time": 6360,
"current_time": 6360,
"words": []
}
},
"text": "请把漆原项目的报告发给罗科,下周我们要上线悬枢系统。",
"request_id": "3756efcf-8388-41c8-832a-9a70bf046f55",
"output": {
"sentence": {
"sentence_id": 1,
"begin_time": 160,
"end_time": 6360,
"text": "请把漆原项目的报告发给罗科,下周我们要上线悬枢系统。",
"channel_id": 0,
"sentence_end": true,
"words": [
{
"begin_time": 160,
"end_time": 600,
"text": "请把",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 600,
"end_time": 840,
"text": "漆",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 840,
"end_time": 1160,
"text": "原",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 1160,
"end_time": 1680,
"text": "项目的",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 1680,
"end_time": 2160,
"text": "报告",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 2160,
"end_time": 2600,
"text": "发给",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 2600,
"end_time": 2840,
"text": "罗",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 2840,
"end_time": 3480,
"text": "科",
"punctuation": ",",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 3480,
"end_time": 4000,
"text": "下周",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 4000,
"end_time": 4520,
"text": "我们要",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 4520,
"end_time": 5160,
"text": "上线",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 5160,
"end_time": 5440,
"text": "悬",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 5440,
"end_time": 5680,
"text": "枢",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 5680,
"end_time": 5900,
"text": "系",
"punctuation": "",
"fixed": true,
"speaker_id": null
},
{
"begin_time": 5900,
"end_time": 6360,
"text": "统",
"punctuation": "。",
"fixed": true,
"speaker_id": null
}
],
"stash": {
"sentence_id": 2,
"text": "",
"begin_time": 6360,
"current_time": 6360,
"words": []
}
},
"text": "请把漆原项目的报告发给罗科,下周我们要上线悬枢系统。",
"request_id": "3756efcf-8388-41c8-832a-9a70bf046f55"
},
"usage": {
"duration": 6,
"input_tokens": 80,
"output_tokens": 16,
"total_tokens": 96
}
},
"usage": {
"duration": 6,
"input_tokens": 80,
"output_tokens": 16,
"total_tokens": 96
}
}
}
心跳
在 run-task 中設定 heartbeat=true,持續傳送靜音音訊。以下範例展示伺服器傳回的心跳事件。
{
"header": {
"action": "run-task",
"task_id": "eac269a3-a31d-417a-979d-51066926d8a6",
"streaming": "duplex"
},
"payload": {
"task_group": "audio",
"task": "asr",
"function": "recognition",
"model": "qwen-audio-3.1-asr-flash-streaming",
"parameters": {
"format": "pcm",
"sample_rate": 16000,
"heartbeat": true
},
"input": {}
}
}
{
"header": {
"task_id": "eac269a3-a31d-417a-979d-51066926d8a6",
"event": "result-generated",
"attributes": {}
},
"payload": {
"output": {
"sentence": {
"sentence_id": 0,
"begin_time": 0,
"end_time": null,
"text": "",
"channel_id": 0,
"speaker_id": null,
"sentence_end": false,
"heartbeat": true,
"words": []
},
"text": "",
"request_id": "eac269a3-a31d-417a-979d-51066926d8a6",
"output": {
"sentence": {
"sentence_id": 0,
"begin_time": 0,
"end_time": null,
"text": "",
"channel_id": 0,
"speaker_id": null,
"sentence_end": false,
"heartbeat": true,
"words": []
},
"text": "",
"request_id": "eac269a3-a31d-417a-979d-51066926d8a6"
}
},
"usage": {
"duration": 2
}
}
}
task-finished
任務處理完成。收到此事件後,本次任務的辨識結果已傳回完畢。
headerobjecttask_idstring用戶端產生的任務 ID(UUID 格式)。
eventstring事件類型,固定為 task-finished。
attributesobject附加屬性(通常為空白)。
payloadobjectusageobject任務結束時的累計用量。欄位含義與 result-generated.usage相同。
{
"header": {
"action": "finish-task",
"task_id": "3756efcf-8388-41c8-832a-9a70bf046f55",
"streaming": "duplex"
},
"payload": {
"input": {}
}
}
{
"header": {
"task_id": "3756efcf-8388-41c8-832a-9a70bf046f55",
"event": "task-finished",
"attributes": {}
},
"payload": {
"output": {},
"usage": {
"duration": 6,
"input_tokens": 80,
"output_tokens": 16,
"total_tokens": 96
}
}
}
task-failed
任務失敗。透過 error_code 和 error_message 取得錯誤原因。WebSocket 連線在任務失敗後會關閉,無法重複使用。
headerobjecttask_idstring用戶端產生的任務 ID(UUID 格式)。
eventstring事件類型,固定為 task-failed。
error_codestring錯誤類型描述。
error_messagestring具體錯誤原因。
attributesobject附加屬性(通常為空白)。
payloadobject固定為{}。
以下請求使用不支援的音訊格式,以展示 task-failed。錯誤碼和錯誤訊息隨失敗原因而變化。
{
"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": {}
}
}
{
"header": {
"task_id": "9272a5a2-8df4-4f2d-af0e-e544c17f3e42",
"event": "task-failed",
"error_code": "UNSUPPORTED_FORMAT",
"error_message": "UNSUPPORTED_FORMAT"
},
"payload": {}
}