qwen-audio-3.0-realtime-plus(实时语音对话)。wss://{base_url}/v1/realtime?model=qwen-audio-3.0-realtime-plus必须使用 WebSocket( ws://或wss://),不是普通 HTTP POST。
| 参数 | 是否必填 | 说明 |
|---|---|---|
Authorization | 是 | Bearer + 平台令牌(控制台「令牌管理」里复制,格式通常为 sk-xxxx) |
| 方向 | 格式 | 采样率 | 位深 | 声道 | 传输方式 |
|---|---|---|---|---|---|
| 上行(你 → 模型) | PCM | 16 kHz | 16 bit | 单声道 | Base64,放在 input_audio_buffer.append |
| 下行(模型 → 你) | PCM | 24 kHz | 16 bit | 单声道 | Base64,在 response.audio.delta |
Authorization)response.done{
"type": "session.update",
"session": {
"modalities": ["text", "audio"],
"voice": "longanqian",
"instructions": "你是一个友好的中文语音助手,回答简洁自然。",
"turn_detection": {
"type": "server_vad",
"threshold": 0.5,
"silence_duration_ms": 800
}
}
}{
"type": "conversation.item.create",
"item": {
"type": "message",
"role": "user",
"content": [
{
"type": "input_text",
"text": "你好,请用一句话介绍你自己。"
}
]
}
}{
"type": "response.create"
}response.audio_transcript.delta(助手文字)response.audio.delta(助手语音 Base64 PCM)response.done(本轮结束,含 usage)连接成功
→ 收到 session.created
→ 发送 session.update
→ 持续发送 input_audio_buffer.append(约每 20~40ms 一片)
→ 服务端自动断句并回复
→ 收到 response.audio.delta / response.audio_transcript.delta
→ 收到 response.done{
"type": "session.update",
"session": {
"modalities": ["text", "audio"],
"voice": "longanqian",
"instructions": "你是一个友好的中文语音助手,回答简洁自然。",
"enable_speech_emotion": true,
"max_history_turns": 20,
"turn_detection": {
"type": "server_vad",
"threshold": 0.5,
"silence_duration_ms": 800
}
}
}{
"type": "input_audio_buffer.append",
"audio": "<Base64 编码的 16kHz/16bit/mono PCM 分片>"
}session.update — 更新会话配置| 参数 | 类型 | 说明 |
|---|---|---|
type | string | 固定 session.update |
session.modalities | array | 输出模态:["text"] 仅文本;["text","audio"] 文本+音频(默认) |
session.voice | string | TTS 音色。3.0 常用 longanqian;也可 longanlingxin / longanxiaoxin 等。仅首次 session.update 生效 |
session.instructions | string | 系统提示词(角色、风格) |
session.enable_speech_emotion | boolean | 是否开启情感增强,默认 true |
session.input_audio_format | string | 输入格式,目前仅 pcm(16k)。仅首次发音频前可改 |
session.output_audio_format | string | 输出格式,目前仅 pcm(24k) |
session.max_history_turns | int | 保留历史轮次,1~50,默认 20 |
session.enable_search | boolean | 是否联网搜索;不可与 tools 同时开启 |
session.search_options.enable_source | boolean | 是否返回搜索来源 |
session.tools | array | Function Calling 工具定义 |
session.turn_detection | object / null | 轮次检测;设为 null 表示按键说话 |
session.turn_detection.type | string | server_vad(声学 VAD)或 smart_turn(语义轮次) |
session.turn_detection.threshold | float | VAD 灵敏度,仅 server_vad,默认 0.5,范围 [-1, 1] |
session.turn_detection.silence_duration_ms | int | 静音多久触发回复,仅 server_vad,默认 800,范围 [200, 6000] |
session.turn_detection.voiceprint_audio_urls | array | 仅 smart_turn;说话人预录音频 URL,最多 5 个,仅首次生效 |
{
"type": "session.update",
"session": {
"modalities": ["text", "audio"],
"voice": "longanqian",
"turn_detection": null
}
}input_audio_buffer.append — 追加音频| 参数 | 类型 | 说明 |
|---|---|---|
type | string | 固定 input_audio_buffer.append |
audio | string | Base64 PCM(16kHz / 16bit / mono) |
input_audio_buffer.commit — 提交音频(仅 push-to-talk){ "type": "input_audio_buffer.commit" }response.create。server_vad / smart_turn 下会被忽略。input_audio_buffer.clear — 清空未提交音频(仅 push-to-talk){ "type": "input_audio_buffer.clear" }conversation.item.create — 注入对话 / 回写工具结果{
"type": "conversation.item.create",
"item": {
"type": "message",
"role": "user",
"content": [
{ "type": "input_text", "text": "今天天气怎么样?" }
]
}
}{
"type": "conversation.item.create",
"item": {
"type": "function_call_output",
"call_id": "call_xxx",
"output": "{\"temperature\":18,\"condition\":\"sunny\"}"
}
}| 参数 | 类型 | 说明 |
|---|---|---|
previous_item_id | string | 可选,插入到该 item 之后;不传则追加到末尾 |
item.type | string | message / function_call / function_call_output |
item.role | string | message 时必填:system / user / assistant |
item.content | array | 消息内容;input_text / input_audio / output_text 等 |
item.call_id | string | 函数调用关联 ID |
item.output | string | 工具结果(JSON 字符串) |
conversation.item.retrieve / delete{ "type": "conversation.item.retrieve", "item_id": "item_xxx" }{ "type": "conversation.item.delete", "item_id": "item_xxx" }response.create — 手动触发推理{
"type": "response.create",
"response": {
"modalities": ["audio", "text"]
}
}| 参数 | 类型 | 说明 |
|---|---|---|
response.modalities | array | 可选,覆盖本轮输出模态 |
response.voice | string | 可选,覆盖本轮音色 |
commitresponse.cancel — 取消当前回复{ "type": "response.cancel" }| type | 含义 |
|---|---|
session.created | 连接后首个事件,含默认会话配置 |
session.updated | session.update 成功后的完整配置 |
error | 错误;invalid_request_error 不断连,server_error 会断连 |
input_audio_buffer.speech_started | VAD 检测到说话开始 |
input_audio_buffer.speech_stopped | VAD 检测到说话结束;smart_turn 可能带 reason=turn_invalid |
input_audio_buffer.committed | 音频已提交 |
conversation.item.created | 对话项已创建 |
conversation.item.input_audio_transcription.delta | 用户语音转写增量 |
conversation.item.input_audio_transcription.completed | 用户语音转写完成 |
conversation.item.ambient_audio_transcription.delta | smart_turn 无语义环境音转写 |
response.audio.delta | 助手音频增量(Base64 PCM 24k) |
response.audio_transcript.delta | 助手文本增量 |
response.audio_transcript.done | 助手文本完成 |
response.done | 本轮结束(含 usage;cancelled 表示被打断/取消) |
response.done 中的 usage 示例:{
"type": "response.done",
"response": {
"status": "completed",
"usage": {
"total_tokens": 403,
"input_tokens": 333,
"output_tokens": 70,
"input_tokens_details": {
"text_tokens": 333
},
"output_tokens_details": {
"text_tokens": 14,
"audio_tokens": 56
}
}
}
}response.audio.delta 里的 delta 是 Base64 PCM(24kHz / 16bit / mono),调试工具一般不会直接播。response.audio.delta 的 deltaAudio 播放,或交给 AudioContext| 模式 | turn_detection | 适用场景 |
|---|---|---|
| server_vad | {"type":"server_vad",...} | 免提连续对话(最常用) |
| smart_turn | {"type":"smart_turn",...} | 更 自然打断,过滤「嗯啊」等 |
| push-to-talk | null | 按键说话,精确控制 |
append 音频 → commit → response.create → 收音频/文本 → response.done| 计费项 | 说明 |
|---|---|
| 输入:文本 | 文本输入 tokens |
| 输入:音频 | 音频输入 tokens |
| 输出:文本 | 仅文本输出时计费 |
| 输出:文本+音频 | 有音频输出时,输出文本不计费,按音频输出档计费 |
response.done 中的 usage 为准。Authorization 必须是令牌管理的令牌 sk-xxxx(不是个人设置的系统访问令牌)。response.audio.delta 但听不到声音?session.createdresponse.audio_transcript.delta 和 response.doneinput_audio_buffer.append 做语音对话response.audio.delta