使用实时连接传输语音和文本。
概览
通过 WebSocket 发送语音,在同一会话中逐轮接收音频片段和转写。每轮 response.done 事件返回该轮的用量。
- 版本
- qwen-audio-3.1-realtime-plus
- 输入 / 输出
- 文本, 音频 / 文本, 音频
- 接口路径
- /v1/realtime
接口协议与接入
Authorization: Bearer ITERACOMPUTE_API_KEY
WebSocket /v1/realtime
通过 WebSocket 建立会话,从 response.done 读取用量。
LLMs.txt
LLMs.txt
# qwen/qwen-audio-3.1-realtime-plus
Revision: deb6666506d9524945ea91dfdbba99d5165dbe6f350c29aadd7dfe1846563834
Authorization: Bearer ITERACOMPUTE_API_KEY
WebSocket wss://api.iteracompute.com/v1/realtime
- modalities · array · 需要的响应模态。
- instructions · string · 本次会话的指令。
- input_audio_format · enum · 16 kHz 单声道、小端 PCM16。 · ["pcm"]
- output_audio_format · enum · 24 kHz 单声道 PCM16。 · ["pcm"]
- turn_detection · object · 设为 null 使用手动提交,也可配置自动断句。
- voice · string · 此型号支持的音色。
安装 websocket-client,设置 ITERACOMPUTE_API_KEY。准备 16 kHz、单声道、小端 PCM16 原始录音 input.pcm。脚本将响应保存为可播放的 24 kHz WAV。
import base64, json, os, wave
from pathlib import Path
from urllib.parse import urlencode
from contextlib import closing
from websocket import create_connection
headers = {"Authorization": "Bearer " + os.environ["ITERACOMPUTE_API_KEY"]}
url = "wss://api.iteracompute.com/v1/realtime?" + urlencode({"model": "qwen/qwen-audio-3.1-realtime-plus"})
audio = Path("input.pcm").read_bytes()
with closing(create_connection(url, header=headers, timeout=60)) as ws:
def receive():
event = json.loads(ws.recv())
if event["type"] == "error":
raise RuntimeError(event.get("error"))
return event
def wait_for(kind):
while receive()["type"] != kind:
pass
wait_for("session.created")
ws.send(json.dumps({"type": "session.update", "session": {"modalities": ["text", "audio"], "turn_detection": None}}))
wait_for("session.updated")
for offset in range(0, len(audio), 3200):
chunk = base64.b64encode(audio[offset:offset+3200]).decode("ascii")
ws.send(json.dumps({"type": "input_audio_buffer.append", "audio": chunk}))
ws.send(json.dumps({"type": "input_audio_buffer.commit"}))
wait_for("input_audio_buffer.committed")
ws.send(json.dumps({"type": "response.create"}))
with wave.open("reply.wav", "wb") as out:
out.setparams((1, 2, 24000, 0, "NONE", "PCM"))
while True:
event = receive()
if event["type"] == "response.audio.delta":
out.writeframesraw(base64.b64decode(event["delta"]))
elif event["type"] == "response.done":
if event["response"]["status"] != "completed":
raise RuntimeError(event["response"]["status"])
break
https://www.alibabacloud.com/help/en/model-studio/audio-realtime-websocket-access接口参数
- 通过 WebSocket 建立会话,从 response.done 读取用量。
以下为当前线路接受的参数与取值范围,账户额度和上下文限制同时适用。参数可接收不代表相关模型能力已经完成验证。
- 工具调用
- 不支持
- 推理
- 不支持
- 视觉
- 不支持
- 流式输出
- 支持
- JSON 模式
- 不支持
参数与取值
点击参数名即可复制;表格可横向滚动查看全部列。用途栏标明协议差异,不能将同名字段视为跨接口通用。
| 参数 | 类型 | 接收状态 | 取值范围 | 用途 / 协议 |
|---|---|---|---|---|
| 字符串 | 可接收 | — | 此型号支持的音色。 | |
| 数组 | 可接收 | — | 需要的响应模态。 | |
| 字符串 | 可接收 | — | 本次会话的指令。 | |
| 对象 | 可接收 | — | 设为 null 使用手动提交,也可配置自动断句。 | |
| 枚举值 | 可接收 | ["pcm"] | 16 kHz 单声道、小端 PCM16。 | |
| 枚举值 | 可接收 | ["pcm"] | 24 kHz 单声道 PCM16。 |
当前配置调用示例
WebSocket /v1/realtime
请求示例
{
"type": "session.update",
"session": {
"modalities": [
"text",
"audio"
],
"turn_detection": null
}
}参数版本:deb6666506d9
API
安装 websocket-client,设置 ITERACOMPUTE_API_KEY。准备 16 kHz、单声道、小端 PCM16 原始录音 input.pcm。脚本将响应保存为可播放的 24 kHz WAV。
Python
import base64, json, os, wave
from pathlib import Path
from urllib.parse import urlencode
from contextlib import closing
from websocket import create_connection
headers = {"Authorization": "Bearer " + os.environ["ITERACOMPUTE_API_KEY"]}
url = "wss://api.iteracompute.com/v1/realtime?" + urlencode({"model": "qwen/qwen-audio-3.1-realtime-plus"})
audio = Path("input.pcm").read_bytes()
with closing(create_connection(url, header=headers, timeout=60)) as ws:
def receive():
event = json.loads(ws.recv())
if event["type"] == "error":
raise RuntimeError(event.get("error"))
return event
def wait_for(kind):
while receive()["type"] != kind:
pass
wait_for("session.created")
ws.send(json.dumps({"type": "session.update", "session": {"modalities": ["text", "audio"], "turn_detection": None}}))
wait_for("session.updated")
for offset in range(0, len(audio), 3200):
chunk = base64.b64encode(audio[offset:offset+3200]).decode("ascii")
ws.send(json.dumps({"type": "input_audio_buffer.append", "audio": chunk}))
ws.send(json.dumps({"type": "input_audio_buffer.commit"}))
wait_for("input_audio_buffer.committed")
ws.send(json.dumps({"type": "response.create"}))
with wave.open("reply.wav", "wb") as out:
out.setparams((1, 2, 24000, 0, "NONE", "PCM"))
while True:
event = receive()
if event["type"] == "response.audio.delta":
out.writeframesraw(base64.b64decode(event["delta"]))
elif event["type"] == "response.done":
if event["response"]["status"] != "completed":
raise RuntimeError(event["response"]["status"])
break价格
美元/百万 Token
文本输入$0.48
音频输入$3.84
文本输出$3.84
音频输出$14.40
- Model ID
qwen/qwen-audio-3.1-realtime-plus- 验证范围与来源
查看完整验证范围与来源
2026-11-21 · 通过 SG WebSocket 实测 PCM 音频流、纯文本输出、连续两轮独立扣费,以及上游确认取消但未返回用量时的估算扣费与预留返还。
- www.alibabacloud.comwww.alibabacloud.com/help/en/model-studio/audio-realtime-websocket-access
- www.alibabacloud.comwww.alibabacloud.com/help/en/model-studio/qwen-audio-3-1-realtime-plus
- www.alibabacloud.comwww.alibabacloud.com/help/en/model-studio/realtime
- www.alibabacloud.comwww.alibabacloud.com/help/en/model-studio/fun-audiochat-client-events
使用限制
- 带语音的回复只计音频输出费,随附转写不另收费。
适用任务
接入工具与指南
常见问题
如何接入?
如何计费?
最新上架
查看入选 New Arrivals 的模型,了解 API 价格、已支持能力与接入方式。
Qwen新上架
Qwen3.8-Omni-Flash-Realtime
qwen/qwen3.8-omni-flash-realtime
使用实时连接传输语音和文本。
IteraCompute 上线日期
Qwen新上架
Qwen3.7-Plus
qwen/qwen3.7-plus
Qwen3.7-Plus 接收文字与视觉输入,生成文本。
IteraCompute 上线日期
- 输入
- $0.384
- 输出
- $1.536
美元 / 百万 tokens
Alibaba Cloud新上架
Wan 3.0 Prime
wan/wan3.0-video-prime
万相 3.0 Prime 可根据文本和参考素材生成视频。
IteraCompute 上线日期