> For the complete documentation index, see [llms.txt](https://docs.convai.com/api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.convai.com/api-docs/zh/api-can-kao/core-api-reference/live-apis-beta/server-to-client-messages.md).

# 服务器到客户端消息

Convai 在 Live API 中通过 WebRTC 数据通道发送给客户端的所有消息的完整参考，包括字段、类型和建议操作。

在会话进行期间，Convai Live API 服务器会通过 WebRTC 数据通道发送这些消息。每种消息类型都表示一个不同的事件——确认、机器人状态变更、动画数据或会话限制。有关所有消息类型及其封装格式的摘要，请参阅 [消息术语表](https://docs.convai.com/api-docs/zh/api-can-kao/core-api-reference/live-apis-beta/message-glossary.md) 。

大多数服务器消息都使用 RTVI 封装格式，如 [`interaction-created`](#interaction-created)下方所示。后续示例仅展示内部的 `data` 负载。 `server-response` 使用扁平的旧版结构，而 [机器人输出流](#bot-output-stream) 则将事件类型放在顶层。有关消息分流逻辑，请参阅 [轮次生命周期与消息顺序](https://docs.convai.com/api-docs/zh/api-can-kao/core-api-reference/live-apis-beta/turn-lifecycle-and-message-ordering.md#two-envelope-forms) 。

字段是否存在并不统一。有些可选字段会以 `null`形式发送，而另一些则会被省略。请阅读 [字段存在规则](https://docs.convai.com/api-docs/zh/api-can-kao/core-api-reference/live-apis-beta/turn-lifecycle-and-message-ordering.md#field-presence-rules) ，并使用可选访问方式，而不要假定某个键一定存在。

***

### 机器人输出流

这些消息携带角色的回复文本及其语音状态转换。与本页其他消息不同，它们将事件类型放在消息的 **顶层** ，而不是嵌套在 `data`.

#### bot-llm-text

机器人的文本投影，以分块形式流式传输。按接收顺序拼接 `data.text` ，即可重建在 `/connect`.

**处选择的投影全文。**

```json
{ "label": "rtvi-ai", "type": "bot-llm-text", "data": { "text": "Sure, on my way." } }
```

| 字段     | 类型  | 说明          |
| ------ | --- | ----------- |
| `text` | 字符串 | 所选文本投影的增量分块 |

未指定功能，或设置为 `bot_llm_text_mode: "legacy"`时，这是对话流程使用的经过筛选的文本。设置为 `bot_llm_text_mode: "raw"`时，这是 Convai 进行结构化输出解析和对话筛选之前、提供方可见的文本。Raw 模式用于诊断，可能包含 JSON、控制语法、拒绝文本或其他不应执行或发送到语音合成的内容。它不保证包含非文本形式的原生工具调用增量。请参阅 [响应契约与解析](https://docs.convai.com/api-docs/zh/api-can-kao/core-api-reference/live-apis-beta/response-contract-and-parsing.md#bot-llm-text-modes).

**建议操作：** 将内容追加到转录界面中正在生成的机器人消息。

***

#### bot-llm-started / bot-llm-stopped

标记一个轮次中的模型生成阶段的开始和结束。两者都携带一个空的 `data` 对象。

```json
{ "label": "rtvi-ai", "type": "bot-llm-started", "data": {} }
{ "label": "rtvi-ai", "type": "bot-llm-stopped", "data": {} }
```

**建议操作：** 显示和隐藏“思考中”指示器。不要使用 `bot-llm-stopped` 来控制操作执行——请参阅 [顺序保证](https://docs.convai.com/api-docs/zh/api-can-kao/core-api-reference/live-apis-beta/turn-lifecycle-and-message-ordering.md#ordering-guarantees).

***

#### bot-tts-started

此轮次的语音合成已开始。携带一个空的 `data` 对象。

```json
{ "label": "rtvi-ai", "type": "bot-tts-started", "data": {} }
```

***

#### bot-started-speaking / bot-stopped-speaking

标记机器人的轮次中的音频边界。这些消息使用 `server-message` 信封格式，并且还会在 `label` 内重复 `data`.

**处选择的投影全文。**

```json
{
  "label": "rtvi-ai",
  "type": "server-message",
  "data": {
    "label": "rtvi-ai",
    "type": "bot-started-speaking",
    "response_id": "session-id:r4",
    "epoch": 1,
    "sequence": 3
  }
}
```

| 字段                  | 类型  | 是否存在  | 说明                |
| ------------------- | --- | ----- | ----------------- |
| `label`             | 字符串 | 始终    | 始终为 `"rtvi-ai"`   |
| `response_id`       | 字符串 | 仅在设置时 | 此机器人响应的标识符        |
| `neurosync_turn_id` | 整数  | 仅在设置时 | NeuroSync 轮次标识符   |
| `epoch`             | 整数  | 仅在设置时 | NeuroSync 连接/会话周期 |
| `sequence`          | 整数  | 仅在设置时 | 每轮消息序列号           |

**建议操作：** 驱动一个 `isSpeaking` 指示器。使用 `response_id` 将 blendshape 和 cancel 消息与生成它们的轮次关联起来。

***

### 确认

#### server-response

`server-response` 会针对每条客户端到服务器的消息发送，用于确认已收到消息并报告处理结果。它使用 **直接格式（旧版）** ——而非 RTVI 信封格式——因此字段位于 JSON 对象的顶层，而不是嵌套在 `data`.

```json
{
  "type": "server-response",
  "event_type": "tts-toggle",
  "status": "success",
  "message": "TTS enabled",
  "extras": {
    "enabled": true
  }
}
```

| 字段           | 类型          | 说明                                                         |
| ------------ | ----------- | ---------------------------------------------------------- |
| `type`       | 字符串         | 始终为 `"server-response"`                                    |
| `event_type` | 字符串         | 触发此响应的客户端消息类型                                              |
| `status`     | 字符串         | 处理状态： `"success"`, `"error"`, `"processing"`，或 `"pending"` |
| `message`    | 字符串 \| null | 对结果的易读描述                                                   |
| `extras`     | 对象 \| null  | 附加的事件特定数据                                                  |

**状态值**

| 值              | 含义                     |
| -------------- | ---------------------- |
| `"success"`    | 消息已成功处理                |
| `"error"`      | 发生错误；详情请参阅 `message` 。 |
| `"processing"` | 消息正在异步处理中              |
| `"pending"`    | 已收到消息，但处理有所延迟          |

**`extras` 字段（按事件类型划分）**

| `event_type`        | `extras` 字段                                                                                                                                                                              |
| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `context-update`    | `token_count`, `static_token_count`, `runtime_token_count`, `max_tokens`, `static_max_tokens`, `runtime_max_tokens`, `remaining_tokens`, `content`, `update_id`, `revision`, `duplicate` |
| `tts-toggle`        | `enabled`                                                                                                                                                                                |
| `stt-toggle`        | `muted`                                                                                                                                                                                  |
| `usage-toggle`      | `enabled`                                                                                                                                                                                |
| `trigger-message`   | `trigger_name`, `has_speak_tag`                                                                                                                                                          |
| `user_text_message` | `text`                                                                                                                                                                                   |
| `action-result`     | `tool_call_id`, `idempotent`；错误还包含 `error_code`                                                                                                                                          |

**关于 `message` 字段**

`message` 是一个 **面向开发者和日志的、人类可读的诊断字符串**。它不是稳定标识符。

{% hint style="danger" %}
不要根据以下内容进行应用逻辑分支处理： `message`。它没有版本控制，措辞可能会随版本发布而变化。请根据 `status`以及 `extras`.
{% endhint %}

以下是一些代表性取值，供你了解可能看到的内容：

| 情况                   | 示例 `message`                                                                                                     |
| -------------------- | ---------------------------------------------------------------------------------------------------------------- |
| 上下文已正常应用             | `Context updated successfully (append mode, run_llm=auto)`                                                       |
| 上下文已应用，但因用户正在讲话而暂不回复 | `Context updated silently (requested run_llm=true, but user is speaking - bot will respond after user finishes)` |
| 上下文已应用，但因机器人状态而暂不回复  | `Context updated silently (requested run_llm=true, downgraded due to bot state: speaking)`                       |
| 上下文已应用，机器人被打断以作出回复   | `Context updated with INTERRUPTION (run_llm=true interrupted bot speaking, triggering new response)`             |
| 开关                   | `TTS enabled`, `STT muted`, `Usage-update streaming enabled`                                                     |
| 已去抖的重复操作             | `TTS toggle debounced (duplicate enable within window)`, `Bot interrupt debounced (duplicate within window)`     |
| 成功但无实际操作             | `Trigger message processed without response`, `Trigger processed but no context generated`                       |
| 失败                   | `Narrative design service not available`, `No text provided in dynamic info`, `Usage limit exceeded`             |
| 未处理的服务器错误            | `Failed to process <event_type>: <error detail>`                                                                 |

如果处理程序成功完成，但没有内容需要报告， `message` 将 **完全省略** 而不是作为空字符串或 `null`.

**错误示例**

```json
{
  "type": "server-response",
  "event_type": "tts-toggle",
  "status": "error",
  "message": "TTS bypass filter not available"
}
```

**验证错误 — JSON 无效**

```json
{
  "type": "server-response",
  "event_type": "parse-error",
  "status": "error",
  "message": "Failed to parse message: invalid JSON or UTF-8 encoding"
}
```

**验证错误 — 缺少 type 字段**

```json
{
  "type": "server-response",
  "event_type": "validation-error",
  "status": "error",
  "message": "Message missing required 'type' field"
}
```

**验证错误 — 未知消息类型**

```json
{
  "type": "server-response",
  "event_type": "unknown-message-type",
  "status": "error",
  "message": "未知的消息类型：unknown-message-type",
  "extras": {
    "supported_types": ["trigger-message", "context-update", "tts-toggle"]
  }
}
```

**建议操作：** 检查每条 `status` 字段（位于 `server-response`中）。对于 `"error"` 响应，请读取 `message` 并更新 UI。使用 `extras` 字段反映当前状态——例如，在 `event_type` 为 `stt-toggle`.

***

### 会话与生命周期

#### interaction-created

在会话生命周期早期创建交互 ID 时发送。这是第一条携带完整 RTVI 信封的消息。

**完整 RTVI 信封**

```json
{
  "label": "rtvi-ai",
  "type": "server-message",
  "data": {
    "type": "interaction-created",
    "interaction_id": "int_abc123def456",
    "character_session_id": "cs_xyz789"
  }
}
```

**内部 `data` 负载**

```json
{
  "type": "interaction-created",
  "interaction_id": "int_abc123def456",
  "character_session_id": "cs_xyz789"
}
```

| 字段                     | 类型  | 说明                          |
| ---------------------- | --- | --------------------------- |
| `type`                 | 字符串 | 始终为 `"interaction-created"` |
| `interaction_id`       | 字符串 | 此交互会话的唯一标识符                 |
| `character_session_id` | 字符串 | 角色会话标识符                     |

**建议操作：** 保存 `interaction_id` 以用于分析、日志记录或会话跟踪。

***

#### usage-limit-reached

使用配额超限时发送。处理此消息以显示相应提示并关闭会话。

```json
{
  "type": "usage-limit-reached",
  "quota_type": "minutes",
  "message": "您已超出每月配额"
}
```

| 字段           | 类型  | 说明                                     |
| ------------ | --- | -------------------------------------- |
| `type`       | 字符串 | 始终为 `"usage-limit-reached"`            |
| `quota_type` | 字符串 | 超出配额的类型，例如 `"minutes"` 或 `"api_calls"` |
| `message`    | 字符串 | 以人类可读的消息说明限制                           |

**建议操作：** 向用户显示 `message` ，并妥善结束会话。

***

#### bot-turn-completed

当机器人进入终止回合状态时发送：机器人已完成发言、被用户打断，或因无法传送必需输出而中止。

```json
{
  "type": "bot-turn-completed",
  "was_interrupted": false
}
```

| 字段                | 类型  | 说明                                        |
| ----------------- | --- | ----------------------------------------- |
| `type`            | 字符串 | 始终 `"bot-turn-completed"`                 |
| `was_interrupted` | 布尔值 | `true` 表示用户打断了机器人； `false` 表示回合正常完成       |
| `was_aborted`     | 布尔值 | 可选。 `true` 表示回合因无法传送必需的机器人输出而结束           |
| `error_reason`    | 字符串 | 可选。机器可读的中止原因；目前 `"audio_delivery_failed"` |

`was_aborted` 和 `error_reason` 是附加的可选字段。正常完成时不会包含这些字段。

**建议操作：** 收到此消息后，更新 UI 状态并重新启用用户输入控件。

***

#### user-idle-warning

当用户在设定时段内处于空闲状态时发送，提醒用户即将断开连接。

```json
{
  "type": "user-idle-warning",
  "remaining_seconds": 300,
  "message": "您已处于空闲状态。5 分钟后将断开连接。"
}
```

| 字段                  | 类型          | 说明                       |
| ------------------- | ----------- | ------------------------ |
| `type`              | 字符串         | 始终 `"user-idle-warning"` |
| `remaining_seconds` | 整数          | 会话断开连接前剩余的秒数             |
| `message`           | 字符串 \| null | 可选的人类可读警告消息              |

**建议操作：** 向用户显示警告并提示其进行操作，或者发送 [`reset-idle-timer`](https://docs.convai.com/api-docs/zh/api-can-kao/core-api-reference/live-apis-beta/client-to-server-messages.md#reset-idle-timer) 消息以重置空闲计时器。

***

#### llm-no-response

当 LLM 明确决定不回应用户输入时发送。

```json
{
  "type": "llm-no-response",
  "reason": "abstain"
}
```

| 字段       | 类型          | 说明                            |
| -------- | ----------- | ----------------------------- |
| `type`   | 字符串         | 始终 `"llm-no-response"`        |
| `reason` | 字符串 \| null | 无响应的原因； `"abstain"` 表示模型选择不发言 |

**建议操作：** 更新 UI，以表明机器人选择不作回应；也可以根据 UX 需求静默处理此事件。

***

### 交互与转录

#### final-user-transcription

随当前轮次用户所说内容的最终转录一起发送。

```json
{
  "type": "final-user-transcription",
  "text": "Hello, how are you today?",
  "speaker_id": "user_123",
  "speaker_name": "Alice",
  "participant_id": "participant_456"
}
```

| 字段               | 类型          | 说明                              |
| ---------------- | ----------- | ------------------------------- |
| `type`           | 字符串         | 始终 `"final-user-transcription"` |
| `text`           | 字符串         | 转录文本                            |
| `speaker_id`     | 字符串 \| null | 说话者标识符                          |
| `speaker_name`   | 字符串 \| null | 说话者的显示名称                        |
| `participant_id` | 字符串 \| null | 参与者标识符                          |

**建议操作：** 在聊天界面中显示 `text` ，或将其追加到对话历史记录中。

***

#### moderation-response

用户输入经过内容审核后发送。

```json
{
  "type": "moderation-response",
  "result": false,
  "user_input": "the flagged content",
  "reason": "Inappropriate language"
}
```

| 字段           | 类型          | 说明                               |
| ------------ | ----------- | -------------------------------- |
| `type`       | 字符串         | 始终 `"moderation-response"`       |
| `result`     | 布尔值         | `true` 表示内容通过审核； `false` 表示内容被拦截 |
| `user_input` | 字符串         | 经过审核的输入文本                        |
| `reason`     | 字符串 \| null | 拦截原因； `null` 表示内容通过审核            |

**建议操作：** 如果 `result` 为 `false`，可以选择向用户显示反馈，说明其输入已被拦截。

***

#### behavior-tree-response

随角色 AI 行为的行为树数据一起发送。

```json
{
  "type": "behavior-tree-response",
  "bt_code": "...",
  "bt_constants": "..."
  "narrative_section_id": "section_1"
}
```

| 字段                     | 类型  | 说明                            |
| ---------------------- | --- | ----------------------------- |
| `type`                 | 字符串 | 始终 `"behavior-tree-response"` |
| `bt_code`              | 字符串 | 行为树代码                         |
| `bt_constants`         | 字符串 | 行为树常量                         |
| `narrative_section_id` | 字符串 | 当前叙事章节标识符                     |

***

### 规范模型输出

#### model-output

在客户端协商时发送 `capabilities.model_output_version: 2`。这是可渲染和可执行模型输出的类型化权威来源。旧版 `action-response` 也可能作为兼容性投影发送；应处理其中一个权威来源，而不是两者。

```json
{
  "type": "model-output",
  "version": 2,
  "output_id": "out_abc123",
  "logical_turn_id": "turn_42",
  "format": "convai-combined-json",
  "raw": "{\"response\":\"I will open it.\",\"actions\":[\"Wave\"]}",
  "items": [
    {
      "type": "message",
      "role": "assistant",
      "channel": "final",
      "content": "I will open it."
    },
    {
      "type": "semantic_action",
      "id": "act_abc123",
      "name": "Wave",
      "target": null
    }
  ],
  "final": true
}
```

| 字段                | 类型        | 说明                                                                                          |
| ----------------- | --------- | ------------------------------------------------------------------------------------------- |
| `type`            | 字符串       | 始终 `"model-output"`.                                                                        |
| `version`         | 整数        | 始终 `2`.                                                                                     |
| `output_id`       | 字符串       | 信封标识符。根据此字段对重复投递进行去重。                                                                       |
| `logical_turn_id` | 字符串       | 可选的关联 ID，由同一逻辑轮次的输出信封共享。该值（若存在）最多为 `128` UTF-8 字节。                                          |
| `format`          | 字符串       | `"text"`, `"convai-combined-json"`, `"semantic-actions-json"`，或 `"client-tool-calls-json"`. |
| `raw`             | 字符串       | 为诊断而保留的提供方或运行时原始输出。切勿将此字段作为可信内容执行或渲染。                                                       |
| `items`           | object\[] | 经 Convai 验证的语义项。                                                                            |
| `final`           | 布尔值       | 始终 `true` 表示此信封已完成。它并不意味着后续信封不能共用同一个 `logical_turn_id`.                                     |

| 项 `type`          | 字段                                         | 含义                                                                                                                                                                          |
| ----------------- | ------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `message`         | `role`, `channel`, `content`               | 适用于 `"final"` 或 `"commentary"`.                                                                                                                                             |
| `semantic_action` | `id`, `name`, `target`                     | 已解析的语义动作。 `target` 可以是 `null`.                                                                                                                                              |
| `tool_call`       | `id`, `name`, `target`, `arguments`        | 已关联的客户端工具调用。请为其返回 [`action-result`](https://docs.convai.com/api-docs/zh/api-can-kao/core-api-reference/live-apis-beta/client-to-server-messages.md#action-result) 对应的 `id`. |
| `emotion`         | `name`, `scale`                            | 带有量表的轮次情绪 `1`, `2`，或 `3`.                                                                                                                                                   |
| `extension`       | `schema`, `version`, `payload`, `fallback` | 采用架构版本管理的扩展项。此预览未定义显示或快速响应扩展架构。                                                                                                                                             |

当前的生成端会发出 final 通道消息、语义动作、客户端工具调用和情绪。commentary 通道消息和 `extension` 项由候选协议和解析器支持，但当前运行时不会生成这些内容。

多个信封可以共用一个 `logical_turn_id`，例如先输出文本信封，再输出语义动作或客户端工具调用。仅按 `output_id`去重。Convai 不会执行或授权 `tool_call` 项；请在应用中验证并执行这些项，然后再返回结果。

***

### 动作

#### action-response

随附按顺序排列的语义动作或客户端工具调用兼容投影。请参阅 [Connect API](https://docs.convai.com/api-docs/zh/api-can-kao/core-api-reference/live-apis-beta/connect-api.md) 了解 `action_config` 和能力选择。

```json
{
  "type": "action-response",
  "actions": [
    { "name": "Move To", "target": "cube" },
    { "name": "Wave" }
  ]
}
```

| 字段                 | 类型        | 说明                      |
| ------------------ | --------- | ----------------------- |
| `type`             | 字符串       | 始终为 `"action-response"` |
| `actions`          | object\[] | 要触发的有序动作数组              |
| `actions[].name`   | 字符串       | 动作或动画标识符                |
| `actions[].target` | 字符串       | 可选的目标对象或角色名称            |

旧版语义动作使用 `{ name, target? }`。Convai 会在发出语义动作前，根据会话可执行能力验证动作名称和任何非空目标。

Action protocol v2 也会以此格式投影客户端工具调用：

```json
{
  "type": "action-response",
  "actions": [
    {
      "kind": "tool_call",
      "id": "call_abc123",
      "name": "open_training_record",
      "arguments": {
        "record_id": "record-42"
      }
    }
  ]
}
```

| 字段          | 类型  | 说明                                 |
| ----------- | --- | ---------------------------------- |
| `kind`      | 字符串 | 始终为 `"tool_call"` （用于 v2 客户端工具调用）。 |
| `id`        | 字符串 | 必需终止结果的关联 ID。                      |
| `name`      | 字符串 | 已声明的客户端工具名称。                       |
| `target`    | 字符串 | 可选兼容字段。不要将其视为对工具参数的授权。             |
| `arguments` | 对象  | 根据工具已声明的输入架构验证过的 JSON 对象。          |

数组顺序会保留，但 Convai 不会执行这些操作，也不保证客户端按顺序执行。请自行制定授权、调度、取消和重试策略。如果协商使用了模型输出 v2，请使用 `model-output.items` 并忽略重复的 `action-response` 投影。

***

### 动画与口型同步

#### bot-emotion

当机器人表达情绪时发送。可用于触发头像动画或更新视觉反馈元素。

```json
{
  "type": "bot-emotion",
  "emotion": "happy",
  "scale": 2
}
```

| 字段        | 类型  | 说明                                                  |
| --------- | --- | --------------------------------------------------- |
| `type`    | 字符串 | 始终 `"bot-emotion"`                                  |
| `emotion` | 字符串 | 情绪名称，例如 `"happy"`, `"sad"`, `"excited"`，或 `"angry"` |
| `scale`   | 整数  | 强度级别： `1` = 轻微， `2` = 中等， `3` = 强烈                  |

**建议操作：** 根据收到的 `emotion` 和 `scale`.

***

#### visemes

机器人说话时会频繁发送，并携带用于头像嘴部动画的唇形同步数据。各值表示对应嘴型的混合权重。

```json
{
  "type": "visemes",
  "visemes": {
    "sil": 0.0,
    "pp": 0.8,
    "ff": 0.0,
    "th": 0.0,
    "dd": 0.0,
    "kk": 0.0,
    "ch": 0.0,
    "ss": 0.0,
    "nn": 0.0,
    "rr": 0.0,
    "aa": 0.2,
    "e": 0.0,
    "ih": 0.0,
    "oh": 0.0,
    "ou": 0.0
  }
}
```

| 字段        | 类型  | 说明                       |
| --------- | --- | ------------------------ |
| `type`    | 字符串 | 始终 `"visemes"`           |
| `visemes` | 对象  | 嘴型键到混合权重的映射（`0.0`–`1.0`) |

**嘴型键**

| 键     | 音素      |
| ----- | ------- |
| `sil` | 静音      |
| `pp`  | P、B、M   |
| `ff`  | F、V     |
| `th`  | TH      |
| `dd`  | T、D     |
| `kk`  | K、G     |
| `ch`  | CH、J、SH |
| `ss`  | S、Z     |
| `nn`  | N、L     |
| `rr`  | R       |
| `aa`  | A       |
| `e`   | E       |
| `ih`  | I       |
| `oh`  | O       |
| `ou`  | U、W     |

**建议操作：** 每次收到此消息时，将视素权重应用于头像的唇形同步混合变形。

***

#### neurosync-blendshapes

随附单帧面部动画混合变形数据（每帧 251 个值）。

```json
{
  "type": "neurosync-blendshapes",
  "blendshapes": [0.0, 0.1, 0.05, 0.0]
}
```

| 字段            | 类型       | 说明                                    |
| ------------- | -------- | ------------------------------------- |
| `type`        | 字符串      | 始终 `"neurosync-blendshapes"`          |
| `blendshapes` | float\[] | 由 251 个混合变形值组成的数组，每个值的范围为 `0.0`–`1.0` |

**建议操作：** 将混合变形值应用于当前帧的头像面部骨架。

***

#### chunked-neurosync-blendshapes

随附多个帧的混合变形数据，并将其批量打包在单条消息中。当服务器为提高效率发送批量数据时，请使用此消息类型代替 `neurosync-blendshapes` 。

```json
{
  "type": "chunked-neurosync-blendshapes",
  "blendshapes": [
    [0.0, 0.1, 0.05],
    [0.02, 0.12, 0.04],
    [0.01, 0.09, 0.06]
  ]
}
```

| 字段            | 类型          | 说明                                   |
| ------------- | ----------- | ------------------------------------ |
| `type`        | 字符串         | 始终 `"chunked-neurosync-blendshapes"` |
| `blendshapes` | float\[]\[] | 混合形状帧数组；每帧包含 251 个值，范围为 `0.0`–`1.0`  |

**建议操作：** 将这些帧加入队列，并按顺序应用，以生成流畅的面部动画。

***

#### neurosync-blendshapes-cancel

当提前发送的 NeuroSync 回合被截断时发送——例如因中断、强制结束回合或输出会话被取代。正常完成时 **不会** 发送此消息。仅发送给选择接收提前发送分块的客户端。

```json
{
  "type": "neurosync-blendshapes-cancel",
  "response_id": "session-id:r4",
  "neurosync_turn_id": 4,
  "epoch": 1,
  "sequence": 18,
  "valid_through_frame_index": 179,
  "reason": "interruption"
}
```

| 字段                          | 类型              | 说明                                        |
| --------------------------- | --------------- | ----------------------------------------- |
| `response_id`               | 字符串             | 要取消的生命周期响应标识符                             |
| `neurosync_turn_id`         | 整数              | 要取消的 NeuroSync 回合标识符                      |
| `epoch`                     | 整数              | NeuroSync 连接/会话周期                         |
| `sequence`                  | 整数              | 每回合的消息序列号                                 |
| `valid_through_frame_index` | integer \| null | 由已释放音频支持的最后一帧索引（含）。如果省略或 `null`，则彻底丢弃所属对象 |
| `reason`                    | 字符串             | 取消原因，例如 `"interruption"`                  |

**建议操作：** 清除消息中所标识对象的缓冲混合形状数据。

* 如果 `valid_through_frame_index` 存在，则保留截至该索引（含）的帧，并丢弃其后的所有帧。
* 如果省略或 `null`，则立即彻底丢弃该对象的缓冲帧。这种情况会发生在活动中断和已完成对象被取代时；若保留视觉尾帧，音频停止后嘴唇仍会继续运动。
* 请 **不要** 将取消操作应用于当前活动对象，除非它与消息中标识的对象相匹配。

***

#### blendshape-turn-stats

在机器人回合结束时发送，包含该回合混合形状生成情况的统计信息。可用于调试或分析。

```json
{
  "type": "blendshape-turn-stats",
  "stats": {
    "total_blendshapes": 150,
    "total_audio_bytes": 48000,
    "total_turn_duration_ms": 3000.0,
    "total_audio_duration_ms": 2800.0,
    "fps": 50.0,
    "was_interrupted": false
  }
}
```

| 字段                              | 类型  | 说明                           |
| ------------------------------- | --- | ---------------------------- |
| `type`                          | 字符串 | 始终 `"blendshape-turn-stats"` |
| `stats.total_blendshapes`       | 整数  | 该回合生成的混合形状帧总数                |
| `stats.total_audio_bytes`       | 整数  | 音频数据总大小（字节）                  |
| `stats.total_turn_duration_ms`  | 浮点数 | 回合总时长（毫秒）                    |
| `stats.total_audio_duration_ms` | 浮点数 | 音频总时长（毫秒）                    |
| `stats.fps`                     | 浮点数 | Blendshape 每秒帧数              |
| `stats.was_interrupted`         | 布尔值 | `true` 表示回合是否在完成前被中断         |

***

### 音频

#### audio-data

当音频通过数据通道传输，而非使用标准 WebRTC 音轨传输（或在此基础上额外通过数据通道传输）时发送。只有在 `audio_routing` 设为 `"data_only"` 或 `"both"` 时，此消息才会收到；该设置位于 `audio_config` 中，属于 `/connect` 请求。

```json
{
  "type": "audio-data",
  "sample_rate": 48000,
  "channels": 1,
  "audio": "AAEAAg==...",
  "includes_wav_header": false
}
```

| 字段                    | 类型  | 说明                                                  |
| --------------------- | --- | --------------------------------------------------- |
| `type`                | 字符串 | 始终 `"audio-data"`                                   |
| `sample_rate`         | 整数  | 音频采样率，单位为 Hz，例如 `16000`, `24000`，或 `48000`          |
| `channels`            | 整数  | 音频声道数： `1` = 单声道， `2` = 立体声                         |
| `audio`               | 字符串 | Base64 编码的音频数据（原始 PCM 或带标头的 WAV）                    |
| `includes_wav_header` | 布尔值 | `true` 表示音频负载是否包含 44 字节的 WAV 标头； `false` 表示使用原始 PCM |

完整的解码步骤、播放实现和配置选项，请参阅 [通过数据通道传输音频数据](https://docs.convai.com/api-docs/zh/api-can-kao/core-api-reference/live-apis-beta/audio-data-via-data-channel.md).

***

### 语音活动检测

这些消息来自基于 VAD 的语音转文本门控系统，该系统仅在检测到语音时才会激活 STT 服务。可使用这些消息驱动聆听状态指示器。

#### vad-stt-started

检测到确认的语音后，STT 服务已解除静音并开始处理音频。

```json
{
  "type": "vad-stt-started",
  "timestamp": "2026-08-10T10:30:45.123Z",
  "pre_roll_ms": 1500
}
```

| 字段            | 类型  | 说明                                |
| ------------- | --- | --------------------------------- |
| `timestamp`   | 字符串 | STT 解除静音时的 ISO 8601 时间戳           |
| `pre_roll_ms` | 整数  | 在 *语音检测* 之前捕获并添加到流中的音频时长，确保不会遗漏内容 |

**建议操作：** 显示“正在聆听”或“正在转写”指示器。

***

#### vad-stt-stopped

静默延长期结束后，STT 服务已静音。

```json
{
  "type": "vad-stt-stopped",
  "timestamp": "2026-08-10T10:30:48.456Z",
  "reason": "hangover_elapsed",
  "audio_duration_ms": 3200
}
```

| 字段                  | 类型              | 说明                              |
| ------------------- | --------------- | ------------------------------- |
| `timestamp`         | 字符串             | STT 静音时的 ISO 8601 时间戳           |
| `reason`            | 字符串             | 转写停止的原因，例如 `"hangover_elapsed"` |
| `audio_duration_ms` | integer \| null | 此片段中处理的音频总时长                    |

**建议操作：** 移除“正在聆听”指示器。

***

#### vad-stt-debug

详细的 VAD 状态变更、语音检测和静音检测事件。仅当会话连接时才会发送，且需设置 `debug: true` 并启用调试事件。负载结构因事件而异，仅供诊断使用，不适用于应用程序逻辑。

***

### 诊断

仅当会话连接时才会发送这些消息，且需设置 `debug: true`.

| 消息             | 用途                                                                                                                                                                      |
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `turn-trace`   | 每轮的计时和阶段转换跟踪信息                                                                                                                                                          |
| `server-log`   | 呈现给客户端的服务器端日志行                                                                                                                                                          |
| `usage-update` | 每轮的用量和费用信息。可通过以下选项切换流式传输： [`usage-toggle`](https://docs.convai.com/api-docs/zh/api-can-kao/core-api-reference/live-apis-beta/client-to-server-messages.md#usage-toggle) |
| `metrics`      | 管道性能指标。请参阅 [指标](https://docs.convai.com/api-docs/zh/api-can-kao/core-api-reference/live-apis-beta/metrics.md)                                                           |

{% hint style="warning" %}
诊断消息负载不属于稳定的 API 范围，可能会在不另行通知的情况下发生变化。请勿基于这些消息构建应用程序逻辑。
{% endhint %}

***

### 相关页面

{% content-ref url="/pages/52997086a1139479d2cbe158e37133880276b547" %}
[消息术语表](https://docs.convai.com/api-docs/zh/api-can-kao/core-api-reference/live-apis-beta/message-glossary.md)
{% endcontent-ref %}

{% content-ref url="/pages/70d752d330612b0fbf1290588e718236d6a18f0e" %}
[连接 API](https://docs.convai.com/api-docs/zh/api-can-kao/core-api-reference/live-apis-beta/connect-api.md)
{% endcontent-ref %}

{% content-ref url="/pages/29ba5f52bd1ff6aac10fb390cafb074f474ab066" %}
[音频数据（通过数据通道）](https://docs.convai.com/api-docs/zh/api-can-kao/core-api-reference/live-apis-beta/audio-data-via-data-channel.md)
{% endcontent-ref %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.convai.com/api-docs/zh/api-can-kao/core-api-reference/live-apis-beta/server-to-client-messages.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
