本文介绍千问实时语音/音视频翻译 API 的服务端事件,包括事件类型、参数和示例。
相关文档:实时语音/音视频翻译-千问。
本页为 Qwen-LiveTranslate-Realtime 的事件参考,事件定义以 WebSocket 接入为基础。AOQ、WebRTC 通过各自的数据通道收发模型事件,媒体通过媒体轨道传输。请先阅读WebSocket 接入、WebRTC 接入或AOQ 接入。
error
服务端返回的错误信息。
event_idstringtypestringerror。errorobject属性
属性
typestringcodestringmessagestringparamstringsession.modalities。session.created
客户端连接后,服务端返回的第一个事件,包含本次连接的默认配置信息。
event_idstringtypestringsession.created。sessionobject属性
属性
idstringobjectstringrealtime.session。modelstringinput_modalitiesarrayqwen3.8-livetranslate-flash-realtime。输入模态,例如 ["audio"]。output_modalitiesarrayqwen3.8-livetranslate-flash-realtime。输出模态:["text"] 或 ["text", "audio"]。audioobjectqwen3.8-livetranslate-flash-realtime。音频输入与输出配置。属性
属性
inputobject属性
属性
formatobjecttype 默认值为 pcm,sample_rate 默认值为 16000(Hz)。turn_detectionobjecttype 为 speaker_detection,threshold 为 0.5,silence_duration_ms 为 1000。outputobject属性
属性
formatobjecttype 为 pcm,sample_rate 为 24000(Hz)。voicestringTina。modalitiesarrayqwen3.5-livetranslate-flash-realtime 等模型。模型输出模态设置。voicestringqwen3.5-livetranslate-flash-realtime 等模型。模型生成音频的音色。input_audio_formatstringqwen3.5-livetranslate-flash-realtime 等模型。输入音频的格式,默认为pcm。sample_rateintegerqwen3.5-livetranslate-flash-realtime 等模型。输入音频的采样率,单位为Hz。output_audio_formatstringqwen3.5-livetranslate-flash-realtime 等模型。输出音频的格式,默认为pcm。turn_detectionobjectqwen3.5-livetranslate-flash-realtime 等模型。VAD(语音活动检测)配置。translationobject(可选)属性
属性
languagestring(可选)- qwen3.8-livetranslate-flash-realtime
- qwen3.5-livetranslate-flash-realtime
适用于
qwen3.8-livetranslate-flash-realtime。session.updated
收到用户的 session.update 请求后,若处理成功,则返回此事件;若出错,则返回 error 事件。
event_idstringtypestringsession.updated。sessionobject属性
属性
idstringobjectstringrealtime.session。modelstringinput_modalitiesarrayqwen3.8-livetranslate-flash-realtime。输入模态,例如 ["audio"]。output_modalitiesarrayqwen3.8-livetranslate-flash-realtime。输出模态:["text"] 或 ["text", "audio"]。audioobjectqwen3.8-livetranslate-flash-realtime。音频输入与输出配置。属性
属性
inputobject属性
属性
formatobjecttype 默认值为 pcm,sample_rate 默认值为 16000(Hz)。turn_detectionobjecttype 为 speaker_detection,threshold 为 0.5,silence_duration_ms 为 1000。outputobject属性
属性
formatobjectvoicestringTina。modalitiesarrayqwen3.5-livetranslate-flash-realtime 等模型。模型输出模态设置。voicestringqwen3.5-livetranslate-flash-realtime 等模型。模型生成音频的音色。sample_rateinteger(可选)qwen3.5-livetranslate-flash-realtime 等模型。输入音频的采样率。input_audio_formatstringqwen3.5-livetranslate-flash-realtime 等模型。输入音频的格式,固定为pcm。output_audio_formatstringqwen3.5-livetranslate-flash-realtime 等模型。输出音频的格式,固定为pcm。input_audio_transcriptionobjectqwen3.5-livetranslate-flash-realtime 等模型。输入音频转录配置。仅在会话配置了input_audio_transcription.model参数时返回。属性
属性
modelstringlanguagestringturn_detectionobjectqwen3.5-livetranslate-flash-realtime 等模型。VAD(语音活动检测)配置。Manual 模式下(客户端在session.update中将该参数设为null)不返回此字段。属性
属性
typestringserver_vad。thresholdfloatprefix_padding_msintegersilence_duration_msintegercreate_responsebooleaninterrupt_responsebooleantranslationobject(可选)属性
属性
languagestring(可选)corpusobject(可选)属性
属性
phrasesobject(可选)enable_voice_clonebooleanvoice_clone_optionsobjectenable_voice_clone为true时返回。属性
属性
frequencystring- qwen3.8-livetranslate-flash-realtime
- qwen3.5-livetranslate-flash-realtime
适用于
qwen3.8-livetranslate-flash-realtime。session.finished
会话结束事件,表示当前会话中,所有音频翻译已完成。
该事件在客户端发送 session.finish 后返回。客户端收到该事件后,如需播放剩余译音,应先完成本地播放,再主动断开连接。
event_idstringtypestringsession.finished。response.created
当服务端生成新的模型响应时,会返回此事件。
event_idstringtypestringresponse.created。responseobject属性
属性
idstringconversation_idstringobjectstringrealtime.response。statusstringcompleted(已完成)failed(失败)in_progress(进行中)incomplete(不完整)
modalitiesarrayvoicestringoutput_audio_formatstringoutputstringresponse.done
响应生成完成后,服务端会返回此事件。事件中的 response 对象包含除原始音频数据外的全部输出项。
event_idstringtypestringresponse.done。responseobject属性
属性
idstringconversation_idstringobjectstringrealtime.response。statusstringmodalitiesarrayvoicestringoutput_audio_formatstringoutputobject属性
属性
idstringtypestringmessage。objectstringrealtime.item。statusstringrolestringcontentarray属性
属性
typestringtext;输出包含音频时,为audio。textstringtranscriptstringusageobjectresponse.done 都会返回当前累计值。统计整个会话时,取最后一次的 usage,无需将各次结果相加。属性
属性
total_tokensintegerinput_tokens 与 output_tokens 之和。input_tokensintegeroutput_tokensintegerinput_tokens_detailsobject属性
属性
text_tokensintegeraudio_tokensintegervideo_tokensintegeroutput_tokens_detailsobject属性
属性
text_tokensintegeraudio_tokensintegerresponse.text.delta
适用于 qwen3.8-livetranslate-flash-realtime。 仅输出文本时,返回译文的新增文本片段。
event_idstringtypestringresponse.text.delta。response_idstringitem_idstringoutput_indexintegercontent_indexintegerdeltastringresponse.text.text
适用于 qwen3.5-livetranslate-flash-realtime 等模型。 使用 qwen3.8-livetranslate-flash-realtime 时,请处理 response.text.delta 事件。
当输出模态仅包含文本,且模型增量生成新的文本时,服务端将返回此事件。
event_idstringtypestringresponse.text.text。textstringresponse_idstringitem_idstringoutput_indexintegercontent_indexintegerstashstringtext 拼接后构成临时生成结果;系统会通过 response.text.text 事件持续更新 text 和 stash,直至收到response.text.done事件,此时可通过 text 字段获取完整的最终文本。response.text.done
当输出模态仅包含文本,且模型生成的文本结束时,服务端返回此事件。
当响应中断、不完整或取消时,服务端也会返回此事件。
event_idstringtypestringresponse.text.done。response_idstringitem_idstringoutput_indexintegercontent_indexintegertextstringresponse.audio.delta
WebSocket 接入时,当输出模态包含音频,且模型增量生成新的音频数据时,服务端返回此事件。
event_idstringtypestringresponse.audio.delta。response_idstringitem_idstringoutput_indexintegercontent_indexintegerdeltastringresponse.audio.done
当输出模态包含音频,且模型生成音频结束时,服务端返回此事件。
当响应中断、不完整或取消时,服务端也会返回此事件。
该事件不返回完整音频数据。
event_idstringtypestringresponse.audio.done。response_idstringitem_idstringoutput_indexintegercontent_indexintegerinput_audio_buffer.speech_started
当服务端 VAD(语音活动检测)检测到用户开始说话时,返回此事件。
event_idstringtypestringinput_audio_buffer.speech_started。audio_start_msintegeritem_idstringspeaker_idintegerqwen3.8-livetranslate-flash-realtime。启用 speaker_detection 时返回的说话人标识。可通过本事件的 item_id 关联语音识别结果,并通过翻译消息项的 previous_item_id 关联译文。input_audio_buffer.speech_stopped
当服务端 VAD 检测到用户停止说话时,返回此事件,标志本轮语音输入结束。由于翻译响应基于流式语音同步生成,实际的翻译响应可能已经在语音输入过程中开始,无需等待此事件。
event_idstringtypestringinput_audio_buffer.speech_stopped。audio_end_msintegeritem_idstringinput_audio_buffer.committed
Manual 模式(turn_detection为null)下,客户端发送input_audio_buffer.commit事件后,服务端返回此事件进行确认,并自动开始生成翻译响应。
event_idstringtypestringinput_audio_buffer.committed。input_audio_buffer.cleared
客户端发送input_audio_buffer.clear事件后,服务端返回此事件进行确认,表示已清空缓冲区中尚未提交的音频数据。
event_idstringtypestringinput_audio_buffer.cleared。conversation.item.created
当对话中创建新的消息项时,服务端返回此事件。以下场景会触发此事件:
- 服务端开始生成翻译响应时,创建对应的 assistant 消息项(此时
content为空数组,内容随流式响应逐步填充)。 - Manual 模式下,客户端发送
input_audio_buffer.commit事件后,服务端会额外创建一个对应用户输入音频的消息项(content中包含{"type": "input_audio"})。
item.id 与翻译结果事件的 previous_item_id 相同。客户端可据此关联原文和译文,并同时展示。
event_idstringtypestringconversation.item.created。previous_item_idstringitem.id 相同。itemobject属性
属性
idstringtypestringmessage。objectstringrealtime.item。statusstringrolestringassistant或user。contentarray{"type": "input_audio"}。conversation.item.input_audio_transcription.delta
适用于 qwen3.8-livetranslate-flash-realtime。 返回输入语音的原文识别增量。
event_idstringtypestringconversation.item.input_audio_transcription.delta。item_idstringcontent_indexintegerdeltastringconversation.item.input_audio_transcription.text
适用于 qwen3.5-livetranslate-flash-realtime 等模型。 使用 qwen3.8-livetranslate-flash-realtime 时,请处理 conversation.item.input_audio_transcription.delta 事件。
当配置了input_audio_transcription.model参数时,服务端会流式返回输入音频的语音识别结果(源语言原文)。
event_idstringtypestringconversation.item.input_audio_transcription.text。item_idstringcontent_indexintegertextstringstashstringlanguagestringemotionstringsurprised:惊讶neutral:平静happy:愉快sad:悲伤disgusted:厌恶angry:愤怒fearful:恐惧
conversation.item.input_audio_transcription.completed
当配置了input_audio_transcription.model参数时,语音识别完成后服务端会返回此事件,包含最终的完整识别结果。
event_idstringtypestringconversation.item.input_audio_transcription.completed。item_idstringcontent_indexintegertranscriptstringlanguagestringemotionstringsurprised:惊讶neutral:平静happy:愉快sad:悲伤disgusted:厌恶angry:愤怒fearful:恐惧
conversation.item.input_audio_transcription.failed
当输入了音频但识别失败时,服务端发送该事件。与其他error事件分开处理,便于客户端识别相关的具体项目。
typestringconversation.item.input_audio_transcription.failed。item_idstringcontent_indexintegererrorobject属性
属性
codestringmessagestringresponse.audio_transcript.delta
适用于 qwen3.8-livetranslate-flash-realtime。输出文本和音频时,返回译文的新增文本片段。
event_idstringtypestringresponse.audio_transcript.delta。response_idstringitem_idstringoutput_indexintegercontent_indexintegerdeltastringresponse.audio_transcript.text
适用于 qwen3.5-livetranslate-flash-realtime 等模型。 使用 qwen3.8-livetranslate-flash-realtime 时,请处理 response.audio_transcript.delta 事件。
当输出模态包含音频时,服务端可能返回此事件,用于展示实时翻译内容。
event_idstringtypestringresponse.audio_transcript.text。response_idstringitem_idstringoutput_indexintegercontent_indexintegertextstringstashstringtext 拼接后构成临时翻译结果;系统会通过 response.audio_transcript.text 事件持续更新 text 和 stash,直至收到response.audio_transcript.done事件,此时可通过 transcript 字段获取完整的最终翻译文本。response.audio_transcript.done
当输出模态包含音频,且模型生成文本结束时,服务端返回此事件。
event_idstringtypestringresponse.audio_transcript.done。response_idstringitem_idstringoutput_indexintegercontent_indexintegertranscriptstringresponse.output_item.added
在响应生成过程中创建新输出项时,服务端返回此事件。
event_idstringtypestringresponse.output_item.added。response_idstringoutput_indexintegeritemobject属性
属性
idstringtypestringmessage。objectstringrealtime.item 。statusstringrolestringcontentstringresponse.output_item.done
当新的项输出完成时,服务端返回此事件。
event_idstringtypestringresponse.output_item.done。response_idstringoutput_indexintegeritemobject属性
属性
idstringobjectstringrealtime.item 。typestringmessage。statusstringrolestringcontentstringresponse.content_part.added
当新的内容部分输出时,服务端返回此事件。
event_idstringtypestringresponse.content_part.added。response_idstringitem_idstringoutput_indexintegercontent_indexintegerpartobject属性
属性
typestringtextstringresponse.content_part.done
当新的内容部分输出完成时,服务端返回此事件。
event_idstringtypestringresponse.content_part.done。response_idstringitem_idstringoutput_indexintegercontent_indexintegerpartobject属性
属性
typestringtextstring