> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vivix.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 切换服装和场景

让用户在同一个会话中选择休闲服装、碎花连衣裙或藏青色连衣裙。为每种造型准备一张图片，在创建会话时进行注册，并在用户作出选择时切换当前源图片。

## 1. 准备一组保持一致的图片

![角色穿着白色上衣和粉色半身裙](https://mintcdn.com/vivix-20d305ce/B_Ljoe3caVyoO-A7/images/streaming-avatar/outfit-white-top.webp?fit=max\&auto=format\&n=B_Ljoe3caVyoO-A7\&q=85\&s=dad599ca04d843d39a875d9dceaa587c)

白色上衣和粉色半身裙

![同一角色穿着碎花连衣裙](https://mintcdn.com/vivix-20d305ce/B_Ljoe3caVyoO-A7/images/streaming-avatar/outfit-floral-dress.webp?fit=max\&auto=format\&n=B_Ljoe3caVyoO-A7\&q=85\&s=bf46e38df3ad7e902e7e05bb25fd5b4c)

碎花连衣裙

![同一角色穿着藏青色连衣裙](https://mintcdn.com/vivix-20d305ce/B_Ljoe3caVyoO-A7/images/streaming-avatar/outfit-navy-dress.webp?fit=max\&auto=format\&n=B_Ljoe3caVyoO-A7\&q=85\&s=38842165c13ad4ef62b19d1e5a9e6e5d)

藏青色连衣裙

三张示例图片分别展示白色上衣搭配粉色半身裙、碎花连衣裙和藏青色连衣裙。请统一图片的宽高比，并让角色位置和取景范围尽量一致。姿势、镜头距离和背景也会随着所选图片变化，因此需要与服装一并考虑。

**这里会切换到已经准备好的图片**。用户提出“穿一条红色连衣裙”并不会自动生成新的服装图片。你的应用可以将衣橱按钮或工具调用映射到已有的图片 ID。

## 2. 创建会话时注册造型

以下内容是配置片段。将 `visual` 合并到创建请求中的同一个角色，并保留其 `avatar_id` 和其他配置。存在多张图片时，使用 `default_source_image_id` 选择初始造型。完整创建请求请参阅[快速开始](https://docs.vivix.ai/cn/streaming-avatar/get-started/quickstart.md)。

```json wrap theme={null}
{
  "visual": {
    "default_source_image_id": "look_pink_skirt",
    "source_images": [
      {
        "source_image_id": "look_pink_skirt",
        "url": "https://static.vivi-x.ai/images/2026/08/03/650665979f5d095f.jpg",
        "media_type": "image/jpeg",
        "description": "A stylized young woman with long wavy brown hair and a white flower hair clip faces the camera. She wears a white off-shoulder top, a pink skirt and a silver necklace. Her arms rest beside her body, with empty hands. Shopfronts and a flower cart line the sunlit street behind her. The vertical composition shows her from the head to the upper legs, in a medium-full shot."
      },
      {
        "source_image_id": "look_floral_dress",
        "url": "https://static.vivi-x.ai/images/2026/08/05/6b3d0c85f73a166f.jpg",
        "media_type": "image/jpeg",
        "description": "A stylized woman with long wavy brown hair and a white hair clip wears a floral dress, facing the camera in a sunlit shopping street. Her arms rest by her sides. Medium-full vertical shot."
      },
      {
        "source_image_id": "look_navy_dress",
        "url": "https://static.vivi-x.ai/images/2026/08/05/7412915837ccf5c2.jpg",
        "media_type": "image/jpeg",
        "description": "A stylized woman with long wavy brown hair wears a navy dress, facing the camera in a sunlit street. Medium-full vertical shot."
      }
    ]
  }
}
```

## 3. 用户选择造型时进行切换

通过当前会话的控制 WebSocket 发送以下事件：

```json theme={null}
{
  "event_id": "switch_floral_1",
  "type": "session.update",
  "session": {
    "source_image_id": "look_floral_dress"
  }
}
```

为每个请求生成新的 `event_id`，并显示切换中的状态。`session.updated` 表示请求已被接受。继续等待 `session.update.done`，并确认其中的 `request_event_id` 与本次请求匹配。

```json theme={null}
{
  "type": "session.update.done",
  "event_id": "server_switch_done_1",
  "request_event_id": "switch_floral_1",
  "status": "completed"
}
```

收到 `completed` 后，结束等待状态，并在视频中检查新造型。`cancelled` 表示请求未完成，可能已被后续请求取代。收到 `failed` 时，显示失败状态，并检查 `reason` 或错误详情。选择器状态应以事件结果为准，不要在用户按下按钮后立即宣布切换成功。

## 4. 将同一模式用于其他场景

* **地点**：在预先准备好的室内、街道和舞台图片之间切换。
* **取景**：提供适合对话的半身画面和适合表演的全身画面。
* **虚拟试穿**：将产品卡片映射到对应的预制服装图片，并保持 UI 选择状态同步。

如果需要在用户说“Show me the floral dress”时切换，请参阅[通过工具调用切换服装](https://docs.vivix.ai/cn/streaming-avatar/character/tools.md)。模型负责选择可用选项，你的应用执行同样的 `session.update`，再将结果返回给对话。预先准备产品放在桌面上或拿在手中的图片，也能明确展示这两种状态；详情请参阅[物体互动](https://docs.vivix.ai/cn/streaming-avatar/interaction/object-interaction.md)。

## 5. 同时检查下一轮互动

不要只检查切换发生的瞬间。选择碎花连衣裙，等待一段空闲时间，然后再发送一条消息。确认旧服装不会重新出现，并检查每段描述是否与各自图片一致。

该操作会更换同一角色的视觉源，不会清除对话。如果场景切换还需要重置订单、产品选择或任务，请在应用中显式处理。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.