Skip to main content

Qwen-Audio-Live 用戶端事件

設定會話、傳送音訊並回傳工作結果。

透過控制 WebSocket 傳送 JSON 事件。連線與驗證請參閱 WebSocket 接入。

session.update

設定會話。服務會透過 session.updated 確認設定已生效。純 WebSocket 接入此時即可傳送音訊。WebRTC 與 AOQ 還需等待各自的媒體連線就緒。
typestring必要欄位
事件類型,固定為 session.update。
event_idstring必要欄位
用戶端事件 ID。不可為空,最長 128 個字元。
sessionobject必要欄位
會話設定。
modelstring必要欄位
會話所使用的前台語音模型 ID。可選 qwen-audio-4.0-realtime-preview 或 qwen-audio-3.1-realtime-flash。雙工對話使用 qwen-audio-4.0-realtime-preview,並將 turn_detection.type 設為 duplex。
instructionsstring選填欄位
初次設定會話時,如果省略 session.instructions,前台模型使用內建指令。設定 session.instructions 後,您填寫的指令會覆寫內建指令。
modalitiesarray選填欄位
輸出模態。預設包含 audio 和 text。
voicestring選填欄位
前台模型所使用的系統音色 ID。預設值為 yunshu。
音色名稱音色 ID
云舒yunshu
小满xiaoman
晚风wanfeng
青柚qingyou
破晓poxiao
麦芽maiya
乌龙wulong
雪松xuesong
turn_detectionobject選填欄位
輪次偵測設定。
typestring必要欄位
使用雙工對話時設為 duplex,前台模型選擇 qwen-audio-4.0-realtime-preview。
input_audio_formatstring選填欄位
輸入格式。純 WebSocket 使用 pcm,預設為 16 kHz、單聲道 PCM16LE。
output_audio_formatstring選填欄位
輸出格式。純 WebSocket 使用 pcm,預設為 24 kHz、單聲道 PCM16LE。
toolsarray[object]選填欄位
應用程式可執行的前台函式。預設為空陣列。
typestring
工具類型。自訂函數填入 function。
namestring
函數名稱。
descriptionstring
函數用途。
parametersobject
使用 JSON Schema 說明函數參數。
typestring
參數結構類型。物件填入 object。
propertiesobject
按參數名稱定義參數的類型和限制。鍵名由應用程式定義。
requiredarray[string]
必填參數的名稱清單。
additionalPropertiesboolean | object
控制是否允許傳入未宣告的參數。設為 false 時拒絕未宣告的參數。
delegationobject必要欄位
工作執行方式。
typestring必要欄位
client 由應用程式執行工作。responses 由服務呼叫後台 Responses 模式模型。
responsesobject條件性必要欄位
Responses 模式下為必要欄位。
modelstring必要欄位
處理委派工作的後台 Responses 模式模型 ID,例如 qwen4-max。
instructionsstring選填欄位
Responses 模式下的後台任務指令由您設定。省略時,Model Studio 不提供內建的後台指令。
toolsarray[object]選填欄位
宣告供後台模型使用的工具。 工具元素的結構由 type 決定。以下欄位適用於自訂函數(type 為 function)。
typestring
工具類型。自訂函數填入 function。
namestring
函數名稱。
descriptionstring
函數用途。
parametersobject
使用 JSON Schema 說明函數參數。
typestring
參數結構類型。物件填入 object。
propertiesobject
按參數名稱定義參數的類型和限制。鍵名由應用程式定義。
requiredarray[string]
必填參數的名稱清單。
additionalPropertiesboolean | object
控制是否允許傳入未宣告的參數。設為 false 時拒絕未宣告的參數。
transportobject選填欄位
省略或傳入空物件時,使用 WebSocket。
typestring條件性必要欄位
明確選擇傳輸方式時填寫。websocket 使用 WebSocket,rtc 使用 WebRTC,aoq 使用 AOQ。
sdpstring條件性必要欄位
當 type 為 rtc 時為必填欄位。需傳入用戶端產生的 Offer SDP。詳見 WebRTC 接入。
aoqobject選填欄位
AOQ 設定。
ws_audioboolean選填欄位
是否透過 WebSocket 附加一份下行音訊。預設為 false。
  • Client 模式
  • Responses 模式
{
  "type": "session.update",
  "event_id": "evt_update_client",
  "session": {
    "model": "qwen-audio-4.0-realtime-preview",
    "modalities": [
      "text",
      "audio"
    ],
    "turn_detection": {
      "type": "duplex"
    },
    "delegation": {
      "type": "client"
    }
  }
}

session.input_audio.append

於純 WebSocket 會話中傳送一幀音訊。AOQ 會話則透過 AOQ 傳送音訊。
typestring必要欄位
事件類型,固定為 session.input_audio.append。
event_idstring選填欄位
用戶端事件 ID。不可為空,最長 128 個字元。
audiostring必要欄位
Base64 編碼的 16 kHz、16 位、單聲道 PCM16LE。
{
  "type": "session.input_audio.append",
  "audio": "AAAAAA=="
}

session.input_audio.mute

將輸入靜音。服務回傳 session.input_audio.muted。
typestring必要欄位
事件類型,固定為 session.input_audio.mute。
event_idstring選填欄位
用戶端事件 ID。不可為空,最長 128 個字元。
{
  "type": "session.input_audio.mute",
  "event_id": "evt_mute"
}

session.input_audio.unmute

恢復音訊輸入。服務回傳 session.input_audio.unmuted。
typestring必要欄位
事件類型,固定為 session.input_audio.unmute。
event_idstring選填欄位
用戶端事件 ID。不可為空,最長 128 個字元。
{
  "type": "session.input_audio.unmute",
  "event_id": "evt_unmute"
}

session.item.create

輸入使用者文字,或回傳前台函數執行結果。應用程式對同一 call_id 僅執行一次函數。
typestring必要欄位
事件類型,固定為 session.item.create。
event_idstring選填欄位
用戶端事件 ID。不可為空,最長 128 個字元。
itemobject依用途填寫
待寫入的對話內容。
typestring必要欄位
填寫 message 或 function_call_output。
rolestring依類型填寫
message 的範例填 user。
contentarray依類型填寫
message 的內容。
typestring必要欄位
文字輸入請填 input_text。
textstring必要欄位
使用者文字。
call_idstring依類型填寫
function_call_output 對應的前台函數呼叫 ID。
outputstring依類型填寫
function_call_output 的字串結果。
  • 回傳函數結果
  • 輸入文字
{
  "type": "session.item.create",
  "event_id": "evt_function_result",
  "item": {
    "type": "function_call_output",
    "call_id": "call_stock",
    "output": "{\"stock\":7}"
  }
}

session.thinking.append

更新工作進度。服務回傳 session.thinking.appended。
typestring必要欄位
事件類型,固定為 session.thinking.append。
event_idstring選填欄位
用戶端事件 ID。不可為空,最長 128 個字元。
delegation_idstring必要欄位
使用目前連線所收到的 session.delegation.created 中的 ID。
contentstring必要欄位
工作進度。
start_msnumber選填欄位
會話時間軸上的開始時間,單位為毫秒。
end_msnumber選填欄位
結束時間,單位為毫秒。與 start_ms 成對提供。兩者皆須為有限的非負數,且結束時間不得早於開始時間。
{
  "type": "session.thinking.append",
  "event_id": "evt_thinking",
  "delegation_id": "task_stock",
  "content": "正在查询库存。"
}

session.instruction.append

提供需使用者補充的問題。服務回傳 session.instructions.appended。
typestring必要欄位
事件類型,固定為 session.instruction.append。
event_idstring選填欄位
用戶端事件 ID。不可為空,最長 128 個字元。
delegation_idstring必要欄位
使用目前連線所收到的 session.delegation.created 中的 ID。
task_idstring選填欄位
通常省略。
contentstring必要欄位
需使用者補充的資訊。
start_msnumber選填欄位
會話時間軸上的開始時間,單位為毫秒。
end_msnumber選填欄位
結束時間,單位為毫秒。與 start_ms 成對提供。兩者皆須為有限的非負數,且結束時間不得早於開始時間。
{
  "type": "session.instruction.append",
  "event_id": "evt_instruction",
  "delegation_id": "task_stock",
  "content": "请问要查哪种商品的库存?"
}

session.commentary.append

回傳本連線所受理之工作結果,亦可提交使用者輸入的文字內容。服務回傳 session.commentary.appended。
typestring必要欄位
事件類型,固定為 session.commentary.append。
event_idstring選填欄位
用戶端事件 ID。不可為空,最長 128 個字元。
delegation_idstring回傳工作結果時必填
使用目前連線所收到的 session.delegation.created 中的 ID。
contentstring選填欄位
工作結果或使用者輸入的文字內容。
start_msnumber選填欄位
會話時間軸上的開始時間,單位為毫秒。
end_msnumber選填欄位
結束時間,單位為毫秒。與 start_ms 成對提供。兩者皆須為有限的非負數,且結束時間不得早於開始時間。
errorobject選填欄位
工作錯誤訊息。
  • 回傳工作結果
  • 輸入文字
{
  "type": "session.commentary.append",
  "event_id": "evt_stock_result",
  "delegation_id": "task_stock",
  "content": "库存还有七把雨伞。"
}

response.item.create

於 Responses 模式中新增後台輸入。隨後傳送 response.create 以啟動生成。
typestring必要欄位
事件類型,固定為 response.item.create。
event_idstring選填欄位
用戶端事件 ID。不可為空,最長 128 個字元。
itemobject必要欄位
後台輸入。支援 message 和 function_call_output。
typestring必要欄位
輸入項目類型。
rolestring依類型填寫
message 的範例填 user。
contentarray依類型填寫
使用者訊息內容。
typestring必要欄位
文字輸入請填 input_text。
textstring必要欄位
使用者文字。
call_idstring
function_call_output 的函數呼叫 ID。請使用後台事件回傳的 call_id。
outputstring
function_call_output 的函數結果,格式為字串。
  • 輸入文字
  • 回傳後台函數結果
{
  "type": "response.item.create",
  "event_id": "evt_backend_item",
  "item": {
    "role": "user",
    "type": "message",
    "content": [
      {
        "type": "input_text",
        "text": "请查询雨伞库存。"
      }
    ]
  }
}

response.create

啟動新的後台工作。服務透過 response.event 回傳後台事件。若為明確啟動,服務將直接回傳後台事件;僅在自動委派流程中才會傳送 session.delegation.created。
typestring必要欄位
事件類型,固定為 response.create。
event_idstring選填欄位
用戶端事件 ID。不可為空,最長 128 個字元。
responseobject選填欄位
傳入後台生成設定。設定格式請參閱 Responses API。
{
  "type": "response.create",
  "event_id": "evt_backend_create"
}

session.close

結束會話。服務回傳 session.closed。
typestring必要欄位
事件類型,固定為 session.close。
event_idstring必要欄位
用戶端事件 ID。不可為空,最長 128 個字元。
{
  "type": "session.close",
  "event_id": "evt_close"
}