> 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` 会告诉你是哪种本地证据触发了该事件：

| 来源           | 由以下触发      | 当                                                      |
| ------------ | ---------- | ------------------------------------------------------ |
| `Microphone` | 开放麦克风的电平门限 | 采集到的音频高于房间自身学习到的噪声底。只要它仍高于该噪声底附近就保持激活，因此句子中的停顿不会让状态闪烁。 |
| `PushToTalk` | 按住说话控件     | 玩家按下该控件——这是一个决策，不是声音，因此会在玩家开口之前触发。                     |

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

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

{% hint style="warning" %}
`LocalPlayerActivityChanged` 只是一个提示，不是一次轮次。它只是基于本地证据的推测，绝不会路由消息、提交轮次或产生任何计费。 `PlayerSpeakingStateChanged` 仍然是 Convai 自己的最终判定——这是唯一会生成转写内容或将角色切换到监听状态的事件。
{% endhint %}

### 角色如何处理它

注意到本地活动的角色会进入 **关注中** 对话状态，仅此而已——它不能进入 **倾听中**、轮到发言，或仅凭该信号发送任何内容，因此一次误报带来的只是一次查看，而不是一次错误。

### 角色是否会据此行动

这种本地证据是否会让角色进入对话状态，由……控制 `noticeYouLocally` Conversation Flow 配置文件中的该项默认随版本提供，且不对编辑开放——该配置文件的 Inspector 不会显示它，也没有公开的 setter。因此每个角色都会对本地活动作出反应，而 `LocalPlayerActivityChanged` 无论哪种情况，该事件都会传到你自己的代码中。请参见 [Conversation flow 参考](/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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
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=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
