> 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-unity-sdk/features/conversation-availability/local-player-activity.md).

# 响应玩家开始说话

在服务通过网络连接确认之前，先在本地响应玩家开始说话或按下按键通话。

玩家是否在说话一直由 Convai 自行判断，并通过网络回传通知——因此角色在那次往返完成之前什么也不会做，看起来就像是迟迟才注意到玩家。SDK 现在也会在本地监听，并发布 `LocalPlayerActivityChanged` 一旦它看到本地证据，就会立刻发布，在这两种轮流模式下都是如此。

### 前提条件

* 一个带有 `ConvaiManager` 已连接。请参见 [会话生命周期](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/core-concepts/session-lifecycle.md).

### 订阅该事件

`LocalPlayerActivityChanged` 在……上没有类型化属性 `ConvaiEvents`，因此请通过原始事件中心订阅：

```csharp
using Convai.Domain.DomainEvents.Runtime;
using Convai.Domain.EventSystem;
using Convai.Runtime.Components;
using UnityEngine;

public class MicrophoneMeter : MonoBehaviour
{
    private SubscriptionToken _token;

    private void OnEnable()
    {
        var hub = ConvaiManager.ActiveManager?.Events?.Raw;
        if (hub == null) return;

        _token = hub.Subscribe<LocalPlayerActivityChanged>(HandleLocalActivity);
    }

    private void OnDisable()
    {
        ConvaiManager.ActiveManager?.Events?.Raw?.Unsubscribe(_token);
        _token = default;
    }

    private void HandleLocalActivity(LocalPlayerActivityChanged e)
    {
        Debug.Log($"[MicrophoneMeter] {e.Source}: {(e.IsActive ? "active" : "inactive")} ({e.Level:F1})");
    }
}
```

### 每个来源的含义

`LocalPlayerActivityChanged.Source` 告诉你是哪个本地证据触发了该事件：

| 来源           | 触发者         | 在以下情况触发：                                                     |
| ------------ | ----------- | ------------------------------------------------------------ |
| `麦克风`        | 开启麦克风上的电平阈值 | 捕获到的音频超过了房间自身学到的噪声底。只要它没有回落到接近那个噪声底，就会保持活跃，因此句子中间的停顿不会让状态闪烁。 |
| `PushToTalk` | 按住说话控件      | 玩家按下该控件——这是一个决定，而不是一个声音，所以它会在玩家开口之前触发。                       |

麦克风源会学习房间自身的噪声底，而不是使用固定的响度阈值，因此它在安静的耳机和嘈杂的桌面麦克风上表现一致。只要角色自己的声音能通过玩家扬声器被听到，它就会保持关闭；除非输入设备上真正启用了声学回声消除——在这种情况下，角色的声音从一开始就不会进入麦克风信号。

`LocalPlayerActivityChanged.Level` 是相对于测得噪声底的一个比值，适合用于麦克风电平表。它是 `0` 对于 `PushToTalk` 以及 `麦克风`.

{% hint style="warning" %}
`LocalPlayerActivityChanged` 的下降沿的一个提示，而不是一个轮次。它是根据本地证据做出的猜测，绝不会路由消息、提交轮次或产生任何计费。 `PlayerSpeakingStateChanged` 仍然是 Convai 自己的最终判断——它是唯一会生成转录或让角色进入监听状态的事件。
{% endhint %}

### 角色如何处理它

注意到本地活动的角色会进入 **关注** 对话状态，仅此而已——它无法进入 **聆听**、轮到它发言，或者仅凭这个信号发送任何内容，所以误报带来的只是看一眼，而不是犯错。

### 角色是否据此行动

这种本地证据是否会进入角色的对话状态，由 `noticeYouLocally` 在 Conversation Flow 配置文件上控制，它默认启用且不对外开放编辑——该配置文件的 Inspector 不会绘制它，而且它没有公开的 setter。因此，每个角色都会对本地活动作出反应，而 `LocalPlayerActivityChanged` 无论如何都会到达你的代码。请参见 [对话流程参考](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/embodiment/conversation-flow/reference.md) 了解该配置文件其余的固定行为。

### 验证反应

进入 Play 模式，连接，然后对着麦克风说话，或者按下按住说话控件。确认你的订阅者会立即触发，早于 Convai 对该发言的转录。

### 下一步

{% content-ref url="/pages/5934199bac019b1c2ca54c38c1511321626637cc" %}
[对话流程](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/embodiment/conversation-flow.md)
{% endcontent-ref %}

{% content-ref url="/pages/66ee7fe1bbd8fe5aba610cee8f0dfd2573443acf" %}
[根据可用性控制 UI](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/conversation-availability/gate-your-ui.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-unity-sdk/features/conversation-availability/local-player-activity.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.
