本文介紹 qwen3.5-livetranslate-flash-realtime API 的服務端事件。
相關文檔:即時語音/音視頻翻譯-千問。
error
服務端返回的錯誤資訊。
event_idstring本次事件唯一識別碼。typestring事件類型,固定為error。errorobject錯誤的詳細資料。
屬性 type string錯誤類型。codestring錯誤碼。messagestring錯誤資訊。paramstring與錯誤相關的參數,如session.modalities。 |
session.created
用戶端串連後,服務端返回的第一個事件,包含本次串連的預設配置資訊。
event_idstring本次事件唯一識別碼。typestring事件類型,固定為session.created。sessionobject會話的配置。
屬性 id string會話的唯一識別碼。objectstring固定為realtime.session。modelstring使用的模型。modalitiesarray模型輸出模態設定。voicestring模型產生音訊音色。input_audio_formatstring輸入音訊格式,預設為pcm。sample_rateinteger輸入音訊採樣率,單位為Hz。output_audio_formatstring輸出音訊格式,預設為pcm。turn_detectionobjectVAD(語音活動檢測)配置。translationobject(可選)翻譯配置。
屬性 language string(可選)設定的翻譯目標語種。corpusobject (可選)熱詞配置,用於提升特定詞彙的翻譯準確性。
屬性 corpus.phrases object (可選)熱詞映射表。key 為源語言詞彙,value 為目標語言對應翻譯,參見支援的語種 。 |
session.updated
收到使用者的 session.update 請求後,若處理成功,則返回此事件;若出錯,則返回 error 事件。
event_idstring本次事件唯一識別碼。typestring事件類型,固定為session.updated。sessionobject會話的配置。
屬性 id string會話的唯一識別碼。objectstring固定為realtime.session。modelstring使用的模型。modalitiesarray模型輸出模態設定。voicestring模型產生音訊音色。sample_rateinteger(可選)輸入音訊採樣率。input_audio_formatstring輸入音訊格式,固定為pcm。output_audio_formatstring輸出音訊格式,固定為pcm。input_audio_transcriptionobject輸入音頻轉錄配置。僅在會話配置了input_audio_transcription.model參數時返回。
屬性 model string語音辨識模型。languagestring設定的語音辨識語種。objectVAD(語音活動檢測)配置。Manual 模式下(用戶端在session.update中將該參數設為null)不返回此欄位。
屬性 type stringVAD 類型,固定為server_vad。thresholdfloatVAD 檢測靈敏度。prefix_padding_msinteger語音開始前保留的音頻時間長度(毫秒),避免丟失語音起始部分。silence_duration_msinteger語音結束後需保持靜音的最短時間長度(毫秒),超過該時間長度即判定語音結束。create_responsebooleanVAD 檢測到語音結束後,是否自動觸發翻譯響應。interrupt_responsebooleanVAD 檢測到新一輪語音開始時,是否打斷當前正在產生的翻譯響應。object(可選)翻譯配置。
屬性 language string(可選)設定的翻譯目標語種。corpusobject(可選)熱詞配置,用於提升特定詞彙的翻譯準確性。
屬性 corpus.phrases object(可選)熱詞映射表。key 為源語言詞彙,value 為目標語言對應翻譯。boolean是否啟用聲音複刻。voice_clone_optionsobject聲音複刻控制參數,僅在enable_voice_clone為true時返回。
屬性 frequency string音色複刻頻率。 |
session.finished
會話結束事件,表示當前會話中,所有音頻翻譯已完成。
該事件在用戶端發送session.finish後才會發送,用戶端接收到該事件後可主動中斷連線。
event_idstring本次事件唯一識別碼。typestring事件類型,固定為session.finished。 |
response.created
當服務端產生新的模型響應時,會返回此事件。
event_idstring本次事件唯一識別碼。typestring事件類型,固定為response.created。responseobject響應對象。
屬性 id string響應的唯一識別碼。conversation_id string當前會話的唯一識別碼。object string物件類型,此事件下固定為realtime.response。status string響應狀態,取值範圍:
array響應的模態。voice string模型產生音訊音色。output_audio_formatstring輸出音訊格式。output string此事件下目前為空白。 |
response.done
響應產生完成後,服務端會返回此事件。事件中的 response 對象包含除原始音頻資料外的全部輸出項。
event_idstring本次事件唯一識別碼。typestring事件類型,固定為response.done。responseobject響應對象。
屬性 id string響應的唯一識別碼。conversation_id string當前會話的唯一識別碼。object string物件類型,此事件下固定為realtime.response。status string響應的狀態。modalities array響應的模態。voice string模型產生音訊音色。output_audio_formatstring輸出音訊格式。output object響應的輸出。
屬性 id string響應輸出的唯一識別碼。type string輸出項的類型,當前固定為message。object string輸出項的物件類型,當前固定為realtime.item。status string輸出項的狀態。role string輸出項的角色。content array輸出項的內容。
屬性 type string輸出內容的類型。輸出為純文字時,為text;輸出包含音頻時,為audio。text string輸出的常值內容。transcript string音頻轉錄為文字後的內容。object本次響應的 Token 消耗資訊。 |
response.text.text
當輸出模態僅包含文本,且模型增量產生新的文本時,服務端將返回此事件。
event_idstring本次事件唯一識別碼。typestring事件類型,固定為response.text.text。textstring返回的增量文本。response_idstring回複的ID。item_idstring訊息項ID,可以關聯同一個訊息項。output_indexinteger目前固定為 0。content_indexinteger目前固定為 0。stashstring初步產生的臨時文本,與當前 text 拼接後構成臨時產生結果;系統會通過 response.text.text 事件持續更新 text 和 stash,直至收到response.text.done事件,此時可通過 text 欄位擷取完整的最終文本。 |
response.text.done
當輸出模態僅包含文本,且模型產生的文本結束時,服務端返回此事件。
當響應中斷、不完整或取消時,服務端也會返回此事件。
event_idstring本次事件唯一識別碼。typestring事件類型,固定為response.text.done。response_idstring響應的唯一識別碼。item_idstring訊息項的唯一識別碼。output_indexinteger目前固定為 0。content_indexinteger目前固定為 0。text string模型輸出的完整文本。 |
response.audio.delta
當輸出模態包含音頻,且模型增量產生新的音頻資料時,服務端將返回此事件。
event_idstring本次事件唯一識別碼。typestring事件類型,固定為response.audio.delta。response_idstring響應的唯一識別碼。item_idstring訊息項唯一識別碼。output_indexinteger目前固定為 0。content_indexinteger目前固定為 0。delta string模型增量輸出的音頻資料,使用Base64編碼。 |
response.audio.done
當輸出模態包含音頻,且模型產生音頻結束時,服務端返回此事件。
當響應中斷、不完整或取消時,服務端也會返回此事件。
該事件不返回完整音頻資料。
event_idstring本次事件唯一識別碼。typestring事件類型,固定為response.audio.done。response_idstring響應的唯一識別碼。item_idstring訊息項唯一識別碼。output_indexinteger目前固定為 0。content_indexinteger目前固定為 0。 |
input_audio_buffer.speech_started
當服務端 VAD(語音活動檢測)檢測到使用者開始說話時,返回此事件。
event_idstring本次事件唯一識別碼。typestring事件類型,固定為input_audio_buffer.speech_started。audio_start_msinteger檢測到語音開始的時間點(毫秒),相對於音頻流開始的位移量。item_idstring關聯的訊息項唯一識別碼。 |
input_audio_buffer.speech_stopped
當服務端 VAD 檢測到使用者停止說話時,返回此事件,標誌本輪語音輸入結束。由於翻譯響應基於流式語音同步產生,實際的翻譯響應可能已經在語音輸入過程中開始,無需等待此事件。
event_idstring本次事件唯一識別碼。typestring事件類型,固定為input_audio_buffer.speech_stopped。audio_end_msinteger檢測到語音結束的時間點(毫秒),相對於音頻流開始的位移量。item_idstring關聯的訊息項唯一識別碼。 |
input_audio_buffer.committed
Manual 模式(turn_detection為null)下,用戶端發送input_audio_buffer.commit事件後,服務端返回此事件進行確認,並自動開始產生翻譯響應。
event_idstring本次事件唯一識別碼。typestring事件類型,固定為input_audio_buffer.committed。 |
input_audio_buffer.cleared
用戶端發送input_audio_buffer.clear事件後,服務端返回此事件進行確認,表示已清空緩衝區中尚未提交的音頻資料。
event_idstring本次事件唯一識別碼。typestring事件類型,固定為input_audio_buffer.cleared。 |
conversation.item.created
當對話中建立新的訊息項時,服務端返回此事件。以下情境會觸發此事件:
- 服務端開始產生翻譯響應時,建立對應的 assistant 訊息項(此時
content為空白數組,內容隨流式響應逐步填充)。 - Manual 模式下,用戶端發送
input_audio_buffer.commit事件後,服務端會額外建立一個對應使用者輸入音訊訊息項(content中包含{"type": "input_audio"})。
item.id 與翻譯結果事件的 previous_item_id 相同。用戶端可據此關聯原文和譯文,並同時展示。
event_idstring本次事件唯一識別碼。typestring事件類型,固定為conversation.item.created。previous_item_idstring前一訊息項的唯一識別碼。對於翻譯結果事件,該值與同一 VAD 片段的語音辨識結果訊息項 item.id 相同。itemobject訊息項資訊。
屬性 id string訊息項的唯一識別碼。typestring固定為message。objectstring固定為realtime.item。statusstring訊息項的狀態。rolestring訊息的角色,取值為assistant或user。contentarray訊息的內容。響應剛建立時為空白數組,隨流式響應逐步填充;Manual 模式下 commit 產生的使用者訊息項中包含{"type": "input_audio"}。 |
conversation.item.input_audio_transcription.text
當配置了input_audio_transcription.model參數時,服務端會流式返回輸入音訊語音辨識結果(源語言原文)。
event_idstring本次事件唯一識別碼。typestring事件類型,固定為conversation.item.input_audio_transcription.text。item_idstring訊息項唯一識別碼。content_indexinteger目前固定為 0。textstring已確認的識別文本。stashstring待確認的識別文本(可能會被後續事件修正)。languagestring檢測到的源語種。emotionstring被識別音訊情感。支援的情感如下:
|
conversation.item.input_audio_transcription.completed
當配置了input_audio_transcription.model參數時,語音辨識完成後服務端會返回此事件,包含最終的完整識別結果。
event_idstring本次事件唯一識別碼。typestring事件類型,固定為conversation.item.input_audio_transcription.completed。item_idstring訊息項唯一識別碼。content_indexinteger目前固定為 0。transcriptstring完整的語音辨識結果(源語言原文)。languagestring檢測到的源語種。emotionstring被識別音訊情感。支援的情感如下:
|
conversation.item.input_audio_transcription.failed
當輸入了音頻但識別失敗時,服務端發送該事件。與其他error事件分開處理,便於用戶端識別相關的具體專案。
typestring事件類型,固定為conversation.item.input_audio_transcription.failed。item_idstring關聯的對話項 ID。content_indexinteger包含音訊內容部分的索引。error.codestring錯誤碼。error.messagestring錯誤訊息。 |
response.audio_transcript.text
當輸出模態包含音頻時,服務端可能返回此事件,用於展示即時翻譯內容。
event_idstring本次事件唯一識別碼。typestring事件類型,固定為response.audio_transcript.text。response_idstring響應的唯一識別碼。item_idstring訊息項唯一識別碼。output_indexinteger目前固定為 0。content_indexinteger目前固定為 0。textstring已確認無誤的翻譯文本片段。stashstring初步翻譯的臨時文本,與當前 text 拼接後構成臨時翻譯結果;系統會通過 response.audio_transcript.text 事件持續更新 text 和 stash,直至收到response.audio_transcript.done事件,此時可通過 transcript 欄位擷取完整的最終翻譯文本。 |
response.audio_transcript.done
當輸出模態包含音頻,且模型產生文本結束時,服務端返回此事件。
event_idstring本次事件唯一識別碼。typestring事件類型,固定為response.audio_transcript.done。response_idstring響應的唯一識別碼。item_idstring訊息項唯一識別碼。output_indexinteger目前固定為 0。content_indexinteger目前固定為 0。transcriptstring完整文本。 |
response.output_item.added
在響應產生過程中建立新輸出項時,服務端返回此事件。
event_idstring本次事件唯一識別碼。typestring事件類型,固定為response.output_item.added。response_idstring響應的唯一識別碼。output_indexinteger目前固定為 0。itemobject輸出項資訊。
屬性 id string輸出項的唯一識別碼。typestring固定為 message。objectstring始終為 realtime.item 。statusstring輸出項的狀態。rolestring訊息的角色。contentstring訊息的內容。 |
response.output_item.done
當新的項輸出完成時,服務端返回此事件。
event_idstring本次事件唯一識別碼。typestring事件類型,固定為response.output_item.done。response_idstring響應的唯一識別碼。output_indexinteger目前固定為 0。itemobject輸出項資訊。
屬性 id string輸出項的唯一識別碼。objectstring始終為 realtime.item 。typestring固定為 message。statusstring輸出項的狀態。rolestring發送訊息的角色。contentstring訊息的內容。 |
response.content_part.added
當新的內容部分輸出時,服務端返回此事件。
event_idstring本次事件唯一識別碼。typestring事件類型,固定為response.content_part.added。response_idstring響應的唯一識別碼。item_idstring訊息項唯一識別碼。output_indexinteger目前固定為 0。content_indexinteger目前固定為 0。partobject輸出項資訊。
屬性 type string內容部分的類型。textstring內容部分的文本。 |
response.content_part.done
當新的內容部分輸出完成時,服務端返回此事件。
event_idstring本次事件唯一識別碼。typestring事件類型,固定為response.content_part.done。response_idstring響應的唯一識別碼。item_idstring訊息項唯一識別碼。output_indexinteger目前固定為 0。content_indexinteger目前固定為 0。partobject輸出項資訊。
屬性 type string內容部分的類型。textstring內容部分的文本。 |