> 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/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/blueprint-reference/convai-player-component.md).

# Convai 玩家组件

玩家对话组件参考——Convai Player Component 暴露的每个 Blueprint 可见属性、函数和事件。

`UConvaiPlayerComponent` （蓝图显示名称 **Convai 玩家**）会添加到玩家的 `Actor` 中，用于代表对话中的人类一方。它管理玩家与 Convai 的会话、采集麦克风音频并将其流式传输到当前活动的聊天机器人会话，还提供注视注意力跟踪功能。

添加组件路径： **Convai 玩家**.

### 身份

这些属性用于向 Convai 标识玩家，并用于关联长期记忆。

| 属性                | 类型        | 访问权限                               | 类别       | 说明                                                                                                                                    |
| ----------------- | --------- | ---------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `PlayerName`      | `FString` | `EditAnywhere`, `Replicated`       | `Convai` | 聊天机器人用于称呼该玩家的显示名称。默认值： `"User"`。通过蓝图 setter 设置时会调用 `SetPlayerName`，该函数还会调用 `Server Reliable` RPC `SetPlayerNameServer` ，以便客户端更新自己的名称。 |
| `EndUserID`       | `FString` | `EditAnywhere`由 setter RPC 在服务器上更新 | `Convai` | 用于长期记忆的终端用户身份令牌。连接时发送给 Convai。蓝图 setter 会调用 `SetEndUserIDServer` ；组件启用复制时，该函数会更新服务器副本。                                                |
| `EndUserMetadata` | `FString` | `EditAnywhere`由 setter RPC 在服务器上更新 | `Convai` | 包含 LTM 附加用户元数据的 JSON 字符串。蓝图 setter 会调用 `SetEndUserMetadataServer` ；组件启用复制时，该函数会更新服务器副本。                                               |

{% hint style="info" %}
`SetPlayerName`, `SetEndUserID`和 `SetEndUserMetadata` 各自都有对应的 `Server Reliable` RPC（`SetPlayerNameServer`, `SetEndUserIDServer`, `SetEndUserMetadataServer`）。在当前源码中，只有 `PlayerName` 会注册到 `DOREPLIFETIME`; `EndUserID` 和 `EndUserMetadata` 会通过各自的 setter RPC 在服务器上更新，但不会作为属性复制回其他客户端。
{% endhint %}

### 会话

| 属性                       | 类型     | 默认值    | 类别                | 说明                                                      |
| ------------------------ | ------ | ------ | ----------------- | ------------------------------------------------------- |
| `bAutoInitializeSession` | `bool` | `true` | `Convai\|Session` | 当 `true`时，会 `StartSession` 在 Convai 连接状态达到 `Connected`. |

#### 会话函数

| 函数                  | 输入                                                                   | 返回     | 类别                | 说明                                                                             |
| ------------------- | -------------------------------------------------------------------- | ------ | ----------------- | ------------------------------------------------------------------------------ |
| `StartSession`      | —                                                                    | `bool` | `Convai\|Session` | 为此玩家打开 WebRTC 通道。初始化成功时返回 `true` 。                                             |
| `StopSession`       | —                                                                    | —      | `Convai\|Session` | 关闭通道。再次调用 `StartSession` 可重新打开通道。                                              |
| `IsPlayerConnected` | —                                                                    | `bool` | `Convai\|Session` | `BlueprintPure`。返回 `true` 当会话处于 `EC_ConnectionState::Connected` 状态时。           |
| `SendText`          | `ChatbotComponent (UConvaiConversationComponent*)`, `Text (FString)` | —      | `Convai\|Session` | 在玩家的活动会话中发送 `Text` ，绕过麦克风处理管线。在当前源码中， `ChatbotComponent` 引脚虽出现在函数签名中，但实现并未使用它。 |

请参阅 [会话生命周期](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/core-concepts/session-lifecycle.md) 了解连接状态以及会话的启动和停止行为。

### 麦克风采集

玩家组件通过附加的 `UConvaiAudioCaptureComponent` 采集麦克风音频，并将其馈送到活动会话中。

#### 设备选择

| 函数                                 | 输入                     | 返回值 / 输出                                        | 类别                   | 说明                                                                                                                                                                                                                                                                                                                 |
| ---------------------------------- | ---------------------- | ----------------------------------------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `GetDefaultCaptureDeviceInfo`      | —                      | `bool` 返回值， `OutInfo (FCaptureDeviceInfoBP)` 输出 | `Convai\|Microphone` | **当前源：** 验证 `AudioCaptureComponent`，然后始终返回 `false` 而不填充 `OutInfo`。请勿依赖此节点的 `OutInfo` 。请改用 `GetAvailableCaptureDeviceDetails` 或 `GetActiveCaptureDevice` 。请参阅 [麦克风和音频采集](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/blueprint-reference/microphone-and-audio-capture.md). |
| `GetCaptureDeviceInfo`             | `DeviceIndex (int)`    | `bool` 返回值， `OutInfo (FCaptureDeviceInfoBP)` 输出 | `Convai\|Microphone` | 返回给定 `DeviceIndex`.                                                                                                                                                                                                                                                                                                |
| `GetAvailableCaptureDeviceDetails` | —                      | `TArray<FCaptureDeviceInfoBP>` 返回值              | `Convai\|Microphone` | 返回所有可用采集设备的详细信息。                                                                                                                                                                                                                                                                                                   |
| `GetAvailableCaptureDeviceNames`   | —                      | `TArray<FString>` 返回值                           | `Convai\|Microphone` | 返回所有可用采集设备的显示名称。                                                                                                                                                                                                                                                                                                   |
| `GetActiveCaptureDevice`           | —                      | `OutInfo (FCaptureDeviceInfoBP)` 输出             | `Convai\|Microphone` | 将当前选中的采集设备信息填入 `OutInfo` 。                                                                                                                                                                                                                                                                                         |
| `SetCaptureDeviceByIndex`          | `DeviceIndex (int)`    | `bool` 返回值                                      | `Convai\|Microphone` | 切换到给定索引对应的设备。失败时返回 `false` 。                                                                                                                                                                                                                                                                                       |
| `SetCaptureDeviceByName`           | `DeviceName (FString)` | `bool` 返回值                                      | `Convai\|Microphone` | 切换到枚举列表中最后一个名称与 `DeviceName`匹配的设备。返回 `false` （如果没有找到匹配项）。                                                                                                                                                                                                                                                          |

`FCaptureDeviceInfoBP` 字段：

| 字段                     | 类型        | 说明                   |
| ---------------------- | --------- | -------------------- |
| `DeviceName`           | `FString` | 设备的易读名称。             |
| `DeviceIndex`          | `int`     | 设备列表中的索引。            |
| `LongDeviceId`         | `FString` | 特定于平台的设备标识符。         |
| `InputChannels`        | `int`     | 输入通道数。               |
| `PreferredSampleRate`  | `int`     | 设备的首选采样率。            |
| `bSupportsHardwareAEC` | `bool`    | `true` 表示设备支持硬件回声消除。 |

`FCaptureDeviceInfoBP` 也与音频捕获组件一同记录在 [麦克风与音频捕获](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/blueprint-reference/microphone-and-audio-capture.md).

#### 音量

| 函数                              | 输入                           | 输出                                                    | 类别                   | 说明                                                  |
| ------------------------------- | ---------------------------- | ----------------------------------------------------- | -------------------- | --------------------------------------------------- |
| `SetMicrophoneVolumeMultiplier` | `InVolumeMultiplier (float)` | `Success (bool)` 输出                                   | `Convai\|Microphone` | 调整麦克风输入增益。 `Success` 表示捕获组件是否可用，而非麦克风当前是否正在流式传输或录音。 |
| `GetMicrophoneVolumeMultiplier` | —                            | `OutVolumeMultiplier (float)` 输出， `Success (bool)` 输出 | `Convai\|Microphone` | 读取当前麦克风音量倍率。 `Success` 表示捕获组件是否可用。                  |

### 音频流式传输与录音

#### 流式传输

这些函数用于控制是否将麦克风音频实时发送到当前会话。

| 函数                                 | 返回     | 类别                   | 说明                                       |
| ---------------------------------- | ------ | -------------------- | ---------------------------------------- |
| `UnmuteStreamingAudio`             | `bool` | `Convai\|Session`    | 开始将麦克风音频转发到会话。成功时返回 `true` 。             |
| `MuteStreamingAudio`               | —      | `Convai\|Session`    | 停止转发麦克风音频。                               |
| `GetIsStreaming` （显示名称 **正在流式传输**) | `bool` | `Convai\|Microphone` | `BlueprintPure`. `true` 表示麦克风音频正在进行流式传输。 |

#### 录音

使用录音功能捕获完整语音片段，并获取一个 `USoundWave`.

| 函数                               | 返回            | 类别                   | 说明                                                  |
| -------------------------------- | ------------- | -------------------- | --------------------------------------------------- |
| `StartRecording`                 | —             | `Convai\|Microphone` | 开始缓冲麦克风音频。调用 `FinishRecording` 以停止录制并获取音频。          |
| `FinishRecording`                | `USoundWave*` | `Convai\|Microphone` | 停止录制，并将捕获的音频作为 `USoundWave`返回。若未录制任何音频，则返回 `null` 。 |
| `GetIsRecording` （显示名称 **正在录制**) | `bool`        | `Convai\|Microphone` | `BlueprintPure`. `true` 表示当前正在录制。                   |

### 静音与语音活动检测

| 属性      | 类型     | 默认值     | 类别                        | 说明                                                                                 |
| ------- | ------ | ------- | ------------------------- | ---------------------------------------------------------------------------------- |
| `bMute` | `bool` | `false` | `Convai\|AudioProcessing` | 当 `true`时，会阻止直接的非音频处理流式传输路径。若启用了 `IConvaiAudioProcessingInterface`，当前实现仍可转发处理后的音频。 |

| 函数            | 输入                 | 返回     | 类别                        | 说明                                          |
| ------------- | ------------------ | ------ | ------------------------- | ------------------------------------------- |
| `UpdateVadBP` | `EnableVAD (bool)` | `bool` | `Convai\|AudioProcessing` | 启用或禁用语音活动检测。当当前音频处理组件不支持 VAD 时，返回 `false` 。 |

### 视线关注

视线关注功能可根据玩家注视的位置，使玩家组件自动将场景中的对象提升为聊天机器人的“关注对象”。使用 `bEnableGazeAttention`启用该系统。有关跨组件 API、默认值、事件以及因版本而异的高亮行为，请参阅 [视线关注参考](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/gaze-attention/gaze-attention-reference.md).

#### 核心设置

| 属性                       | 类型                  | 默认值              | 类别                            | 说明                                                                          |
| ------------------------ | ------------------- | ---------------- | ----------------------------- | --------------------------------------------------------------------------- |
| `bEnableGazeAttention`   | `bool`              | `false`          | `Convai\|Gaze Attention`      | 总开关。此项为 `false`.                                                            |
| `时，以下所有视线关注属性均不生效。`      | `EC_RunLLMOption`   | `Never`          | `Convai\|Gaze Attention`      | 控制对象被提升为关注对象时聊天机器人是否回复： `Never` （静默更新）、 `Auto` （由 LLM 决定）或 `Always` （强制回复）。 |
| `GazeAttentionText`      | `FString`           | `""`             | `Convai\|Gaze Attention`      | 随关注对象提升事件一同发送的叙事文本。当 `GazeShouldRespond` 为 `Never`.                         |
| `GazeAttentionDelay`     | `float`             | `1.0`            | `Convai\|Gaze Attention`      | 持续注视物体的时长（秒），超过此时长后，该物体会被提升为“正在关注”。                                         |
| `GazeAttentionLossDelay` | `float`             | `5.0`            | `Convai\|Gaze Attention`      | 移开视线的时长（秒），超过此时长后会释放当前关注槽位。                                                 |
| `GazeMaxDistance`        | `float`             | `5000.0`         | `Convai\|Gaze Attention` （高级） | 从摄像机发出的线迹检测的最大距离，以世界单位（厘米）计。                                                |
| `GazeAngleTolerance`     | `float`             | `5.0`            | `Convai\|Gaze Attention`      | 点积备用锥体的半角（度）。当严格线迹检测未能锁定有效注视目标，且未被非 Convai 几何体阻挡时，将使用此锥体。 `0` 禁用备用机制。       |
| `GazeTraceChannel`       | `ECollisionChannel` | `ECC_Visibility` | `Convai\|Gaze Attention` （高级） | 注视线迹检测使用的碰撞通道。                                                              |

`GazeShouldRespond` 接受 `EC_RunLLMOption` 值（`Auto`, `Always`, `Never`）。有关各值的说明，请参阅 [数据类型和枚举](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/blueprint-reference/data-types-and-enums.md).

#### 高亮设置

这些设置用于控制绘制在被注视物体上的轮廓叠加效果。

| 属性                               | 类型                                       | 默认值                    | 类别                                       | 说明                                                                                                                                         |
| -------------------------------- | ---------------------------------------- | ---------------------- | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| `GazeHighlightActorClass`        | `TSubclassOf<AConvaiGazeHighlightActor>` | 插件默认值                  | `Convai\|Gaze Attention\|Highlight`      | 用于显示高亮效果的 Actor 类。可将 `AConvaiGazeHighlightActor` 子类化，以自定义视觉效果。                                                                             |
| `GazeHighlightColor`             | `FLinearColor`                           | `(1.0, 0.9, 0.2, 1.0)` | `Convai\|Gaze Attention\|Highlight`      | 应用于轮廓或线框的色调。                                                                                                                               |
| `GazeOverlayMaterial`            | `TSoftObjectPtr<UMaterialInterface>`     | 未设置                    | `Convai\|Gaze Attention\|Highlight`      | 通过 `UMeshComponent::SetOverlayMaterial`应用的叠加材质。留空则使用插件内置的菲涅耳边缘材质（`/ConvAI/Highlights/M_ConvaiGazeOverlay`）。该材质必须公开一个 `EmissiveColor` 向量参数。 |
| `GazeHighlightEmissiveIntensity` | `float`                                  | `2.5`                  | `Convai\|Gaze Attention\|Highlight` （高级） | 转发到高亮显示执行者的 `EmissiveIntensity` 标量参数。插件叠加材质会在内部将 `EmissiveColor` 乘以此值。                                                                     |

#### 光标设置

| 属性                      | 类型                                     | 默认值                    | 类别                                    | 说明                                            |
| ----------------------- | -------------------------------------- | ---------------------- | ------------------------------------- | --------------------------------------------- |
| `bShowGazeCursor`       | `bool`                                 | `true`                 | `Convai\|Gaze Attention\|Cursor`      | 启用注视追踪时，在屏幕中央显示一个小型准星。                        |
| `bAlwaysShowGazeCursor` | `bool`                                 | `false`                | `Convai\|Gaze Attention\|Cursor`      | 当 `true`时，即使注视目标下没有 Convai 对象，光标也会保持为激活颜色。    |
| `GazeCursorWidgetClass` | `TSubclassOf<UConvaiGazeCursorWidget>` | 插件默认值                  | `Convai\|Gaze Attention\|Cursor`      | 用于绘制光标的控件类。                                   |
| `GazeCursorActiveColor` | `FLinearColor`                         | 白色                     | `Convai\|Gaze Attention\|Cursor`      | 注视落在 `UConvaiObjectComponent`.                |
| `上时的光标颜色`               | `FLinearColor`                         | `(1.0, 1.0, 1.0, 0.0)` | `Convai\|Gaze Attention\|Cursor` （高级） | 注视未落在任何对象上时的光标颜色。默认 alpha `0.0` 会使光标在空闲时完全透明。 |
| `GazeCursorDotSize`     | `float`                                | `6.0`                  | `Convai\|Gaze Attention\|Cursor` （高级） | 光标正方形边长（Slate 单位）。                            |
| `GazeCursorFadeInTime`  | `float`                                | `0.1`                  | `Convai\|Gaze Attention\|Cursor` （高级） | 注视首次落在 Convai 对象上时，光标从空闲状态淡入激活状态所需的秒数。        |
| `GazeCursorFadeOutTime` | `float`                                | `0.25`                 | `Convai\|Gaze Attention\|Cursor` （高级） | 注视离开 Convai 对象时，光标从激活状态淡出为空闲状态所需的秒数。          |

### 事件（可在蓝图中指定的委托）

在玩家蓝图中使用 **Assign** 节点，将这些事件绑定到 `Convai Player` 组件引用。

#### 继承自 `UConvaiConversationComponent`

| 事件                                      | 类别                      | 触发时机                                                                                                                   |
| --------------------------------------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| `OnTranscriptionReceivedDelegate`       | `Convai\|Transcription` | 收到该玩家发言的语音转文字更新。参数： `Speaker`, `Listener`, `Transcription (FString)`, `IsTranscriptionReady (bool)`, `IsFinal (bool)`. |
| `OnAttendeeConnectionStateChangedEvent` | `Convai\|Connection`    | 参会者的连接状态发生变化。参数： `ConvaiConversationComponent`, `AttendeeID (FString)`, `ConnectionState (EC_ConnectionState)`.        |

#### 注视事件

四个注视委托的签名都相同： `PlayerComponent (UConvaiPlayerComponent*)` 和 `ObjectComponent (UConvaiObjectComponent*)`.

大多数注视事件会在 `bEnableGazeAttention` 为 `true`; `OnAttentionLost` 注视注意力被禁用时，在拆除过程中也可能触发。

| 事件                  | 类别                               | 触发时机                                                                  |
| ------------------- | -------------------------------- | --------------------------------------------------------------------- |
| `OnGazeBegin`       | `Convai\|Gaze Attention\|Events` | 玩家的视线首次进入 `UConvaiObjectComponent`的边界范围时触发。在达到任何注意力阈值之前触发。            |
| `OnGazeEnd`         | `Convai\|Gaze Attention\|Events` | 玩家的视线离开 `UConvaiObjectComponent`时触发，无论该对象是否已被提升为注意力目标。                |
| `OnAttentionGained` | `Convai\|Gaze Attention\|Events` | 持续注视的停留阈值（`GazeAttentionDelay`）已达到，并已尝试提升注视优先级。即使所有聊天机器人都拒绝更新，也会触发。   |
| `OnAttentionLost`   | `Convai\|Gaze Attention\|Events` | 注意力槽位被释放：玩家移开视线的时间超过了 `GazeAttentionLossDelay`、其他对象占用了该槽位，或注意力目标已被销毁。 |

请参阅 [事件系统](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/core-concepts/event-system.md) ，了解绑定模式和完整参数详情。有关麦克风设置和注视任务流程，请参阅 [配置麦克风](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/getting-started/configure-the-microphone.md) 和 [注视注意力参考](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/gaze-attention/gaze-attention-reference.md).

### 相关参考

{% content-ref url="/pages/4a6e5ee0afdb709983f0b5685e8cf00febcf5282" %}
[Convai 聊天机器人组件](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/blueprint-reference/convai-chatbot-component.md)
{% endcontent-ref %}

{% content-ref url="/pages/66c756b3aff92ca8b5e88b114dba034ef0b5618c" %}
[麦克风和音频捕获](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/blueprint-reference/microphone-and-audio-capture.md)
{% endcontent-ref %}

{% content-ref url="/pages/a8878427b216a80d6b385f1a342c440aa9b398c9" %}
[会话生命周期](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/core-concepts/session-lifecycle.md)
{% endcontent-ref %}

{% content-ref url="/pages/ddcceab71734a05a1e99c8599b42f364e146005e" %}
[事件系统](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/core-concepts/event-system.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/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/blueprint-reference/convai-player-component.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.
