Qwen-Audio-ASR-Message のサーバーイベントリファレンス。タスク開始、認識結果、完了、失敗のフィールドと対応するリクエストを説明します。
イベントフロー
- run-task を送信し、task-started を受信してから音声の送信を開始します。
- 音声を継続して送信しながら、result-generated を受信します。
- タスクの実行中は、continue-task で会話コンテキストを更新できます。音声は引き続き音声チャネルで送信します。
- すべての音声の送信後に 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": "ab4f7812-2d71-4e3d-93d3-b68ab80d3755",
"streaming": "duplex"
},
"payload": {
"input": {},
"task_group": "audio",
"task": "asr",
"function": "recognition",
"model": "qwen-audio-3.1-asr-flash-message",
"parameters": {
"format": "pcm",
"sample_rate": 16000
}
}
}
{
"header": {
"task_id": "ab4f7812-2d71-4e3d-93d3-b68ab80d3755",
"task_uuid": "852196dba9d14bea9cf0d6e04ff0b027",
"event": "task-started",
"attributes": {}
},
"payload": {}
}
result-generated
文の開始、中間結果、文の最終結果、ハートビートなどの認識結果を返します。中間結果はデフォルトで無効です。intermediate_result_enabled=true を設定すると有効になります。
重要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文の開始時刻(ミリ秒)。
end_timeinteger文の終了時刻(ミリ秒)。
中間結果またはハートビートでは null の場合があります。
textstring認識されたテキスト。
注記中間テキストは認識の進行に伴って更新される場合があります。中間テキストをそのまま連結せず、同じ sentence_id の表示内容を更新してください。
sentence_beginbooleantrue は文の開始を示します。この時点では text が空の場合があります。
sentence_endboolean文が終了したかどうか(true:最終結果、false:中間結果)。
heartbeatboolean値が true の場合、結果はハートビートパケットのため無視できます。
wordsarray[object]単語レベルのタイムスタンプ情報。
begin_timeinteger単語の開始時刻(ミリ秒)。
end_timeinteger単語の終了時刻(ミリ秒)。
textstring認識されたテキスト。
punctuationstring句読点。
usageobjectこのイベント時点での現在のタスクの累積使用量。
注記usage は現在のタスクの累積使用量です。イベント間で usage を合計しないでください。 完了後は task-finished の最終累積使用量を使用します。
durationinteger互換性のために保持される累積音声時間(秒)。
input_tokensinteger入力トークンの累積数。
output_tokensinteger出力トークンの累積数。
total_tokensinteger累積トークン総数。input_tokens と output_tokens の合計。
文の開始
{
"header": {
"action": "run-task",
"task_id": "ab4f7812-2d71-4e3d-93d3-b68ab80d3755",
"streaming": "duplex"
},
"payload": {
"input": {},
"task_group": "audio",
"task": "asr",
"function": "recognition",
"model": "qwen-audio-3.1-asr-flash-message",
"parameters": {
"format": "pcm",
"sample_rate": 16000
}
}
}
{
"header": {
"task_id": "ab4f7812-2d71-4e3d-93d3-b68ab80d3755",
"event": "result-generated",
"attributes": {}
},
"payload": {
"output": {
"sentence": {
"sentence_id": 1,
"begin_time": 0,
"end_time": null,
"text": "",
"sentence_end": false,
"sentence_begin": true,
"words": []
}
}
}
}
中間結果
{
"header": {
"action": "run-task",
"task_id": "5d3db44d-b246-4354-9440-7574e347c163",
"streaming": "duplex"
},
"payload": {
"input": {},
"task_group": "audio",
"task": "asr",
"function": "recognition",
"model": "qwen-audio-3.1-asr-flash-message",
"parameters": {
"format": "pcm",
"sample_rate": 16000,
"intermediate_result_enabled": true
}
}
}
{
"header": {
"task_id": "5d3db44d-b246-4354-9440-7574e347c163",
"event": "result-generated",
"attributes": {}
},
"payload": {
"output": {
"sentence": {
"sentence_id": 1,
"begin_time": 0,
"end_time": null,
"text": "Please",
"sentence_end": false,
"words": [
{
"begin_time": 0,
"end_time": 0,
"text": "Please",
"punctuation": "",
"fixed": false
}
]
}
}
}
}
文の最終結果
{
"header": {
"action": "run-task",
"task_id": "ab4f7812-2d71-4e3d-93d3-b68ab80d3755",
"streaming": "duplex"
},
"payload": {
"input": {},
"task_group": "audio",
"task": "asr",
"function": "recognition",
"model": "qwen-audio-3.1-asr-flash-message",
"parameters": {
"format": "pcm",
"sample_rate": 16000
}
}
}
{
"header": {
"task_id": "ab4f7812-2d71-4e3d-93d3-b68ab80d3755",
"event": "result-generated",
"attributes": {}
},
"payload": {
"output": {
"sentence": {
"sentence_id": 1,
"begin_time": 120,
"end_time": 4040,
"text": "Please send the quarterly project report to Kellera before Friday. ",
"sentence_end": true,
"words": [
{
"begin_time": 120,
"end_time": 320,
"text": "Please",
"punctuation": "",
"fixed": false
},
{
"begin_time": 320,
"end_time": 560,
"text": " send",
"punctuation": "",
"fixed": false
},
{
"begin_time": 560,
"end_time": 760,
"text": " the",
"punctuation": "",
"fixed": false
},
{
"begin_time": 760,
"end_time": 1360,
"text": " quarterly",
"punctuation": "",
"fixed": false
},
{
"begin_time": 1360,
"end_time": 1800,
"text": " project",
"punctuation": "",
"fixed": false
},
{
"begin_time": 1800,
"end_time": 2120,
"text": " report",
"punctuation": "",
"fixed": false
},
{
"begin_time": 2120,
"end_time": 2280,
"text": " to",
"punctuation": "",
"fixed": false
},
{
"begin_time": 2280,
"end_time": 2336,
"text": " ",
"punctuation": "",
"fixed": false
},
{
"begin_time": 2336,
"end_time": 2560,
"text": "Kell",
"punctuation": "",
"fixed": false
},
{
"begin_time": 2560,
"end_time": 2800,
"text": "era",
"punctuation": "",
"fixed": false
},
{
"begin_time": 2800,
"end_time": 3160,
"text": " before",
"punctuation": "",
"fixed": false
},
{
"begin_time": 3160,
"end_time": 4040,
"text": " Friday",
"punctuation": ". ",
"fixed": false
}
],
"stash": {
"sentence_id": 2,
"text": "",
"begin_time": 4040,
"current_time": 4040,
"words": []
}
}
},
"usage": {
"duration": 4,
"input_tokens": 51,
"output_tokens": 13,
"total_tokens": 64
}
}
}
task-finished
タスクの処理が完了し、すべての認識結果が返されました。クライアントは接続を閉じるか、接続を再利用して新しいタスクを開始できます。
headerobjecttask_idstringクライアントが生成したタスク ID(UUID 形式)。
eventstringイベントタイプ。値は常に task-finished です。
attributesobject追加属性。通常は空です。
payloadobjectoutput(空のオブジェクト)と usage(このタスクの最終累積使用量)を含みます。usage の各フィールドは result-generated と同じ定義です。
{
"header": {
"action": "finish-task",
"task_id": "ab4f7812-2d71-4e3d-93d3-b68ab80d3755",
"streaming": "duplex"
},
"payload": {
"input": {}
}
}
{
"header": {
"task_id": "ab4f7812-2d71-4e3d-93d3-b68ab80d3755",
"event": "task-finished",
"attributes": {}
},
"payload": {
"output": {},
"usage": {
"duration": 4,
"input_tokens": 51,
"output_tokens": 13,
"total_tokens": 64
}
}
}
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": "5927b897-6890-45cd-9b85-bc58bdaaadfb",
"streaming": "duplex"
},
"payload": {
"input": {},
"task_group": "audio",
"task": "asr",
"function": "recognition",
"model": "qwen-audio-3.1-asr-flash-message",
"parameters": {
"format": "invalid-format",
"sample_rate": 16000
}
}
}
{
"header": {
"task_id": "5927b897-6890-45cd-9b85-bc58bdaaadfb",
"event": "task-failed",
"error_code": "UNSUPPORTED_FORMAT",
"error_message": "UNSUPPORTED_FORMAT"
},
"payload": {}
}