跳转到主要内容
实时

LiveTranslate client events

WebSocket 客户端事件参考

客户端通过 WebSocket 向服务端发送的事件。
参考:语音翻译

Connect

建立 WebSocket 连接以启动会话。连接就绪后,服务端会发送 session.created 事件。
配置项
端点wss://dashscope.aliyuncs.com/api-ws/v1/realtime
查询参数model=qwen3.5-livetranslate-flash-realtime
鉴权头Authorization: Bearer $DASHSCOPE_API_KEY
协议JSON 文本帧
完整 URL:
wss://dashscope.aliyuncs.com/api-ws/v1/realtime?model=qwen3.5-livetranslate-flash-realtime

session.update

连接建立后更新会话配置。服务端会校验参数并返回完整配置;如果参数无效则返回错误。
Example
{
  "event_id": "event_ToPZqeobitzUJnt3QqtWg",
  "type": "session.update",
  "session": {
    "modalities": [
      "text",
      "audio"
    ],
    "voice": "Cherry",
    "sample_rate": 16000,
    "input_audio_format": "pcm",
    "output_audio_format": "pcm",
    "input_audio_transcription": {
      "model": "qwen3-asr-flash-realtime",
      "language": "zh"
    },
    "translation": {
      "language": "en"
    }
  }
}
启用声音复刻(frequency=once)的示例:
Example (voice clone)
{
  "event_id": "event_ToPZqeobitzUJnt3QqtWg",
  "type": "session.update",
  "session": {
    "modalities": [
      "text",
      "audio"
    ],
    "voice": "default",
    "enable_voice_clone": true,
    "voice_clone_options": {
      "frequency": "once"
    },
    "sample_rate": 16000,
    "input_audio_format": "pcm",
    "output_audio_format": "pcm",
    "translation": {
      "language": "en"
    }
  }
}
string
body
必填
固定为 "session.update"
object
body
会话配置。

input_audio_buffer.append

向输入缓冲区追加音频数据。服务端使用该缓冲区进行语音检测和提交时机判断。
Example
{
  "event_id": "event_xxx",
  "type": "input_audio_buffer.append",
  "audio": "xxx"
}
string
body
必填
固定为 "input_audio_buffer.append"
string
body
必填
Base64 编码的音频数据。

input_image_buffer.append

从本地文件或实时视频流添加图像数据到缓冲区。 图像限制:
  • 格式:JPG 或 JPEG。推荐分辨率:480p 或 720p。最大:1080p。
  • 最大文件大小:500 KB(Base64 编码前)。
  • 必须进行 Base64 编码。
  • 最大速率:每秒 2 张图像。
  • 建议先发送至少一个 input_audio_buffer.append 事件,以确保服务端有音频上下文。
Example
{
  "event_id": "event_xxx",
  "type": "input_image_buffer.append",
  "image": "xxx"
}
string
body
必填
固定为 "input_image_buffer.append"
string
body
必填
Base64 编码的图像数据。

session.finish

结束会话。服务端根据是否检测到语音做出不同响应: 收到 session.finished 后断开连接。
Example
{
  "event_id": "event_xxx",
  "type": "session.finish"
}
string
body
必填
固定为 "session.finish"