> 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/microphone-and-audio-capture.md).

# 麦克风和音频捕获

Convai Player Component 和麦克风子系统中麦克风设备枚举、选择、音量以及持久化设置的参考。

`UConvaiPlayerComponent` 在以下分类下公开所有可由蓝图调用的麦克风函数： `Convai|Microphone` 。它在内部驱动一个 `UConvaiAudioCaptureComponent` 实例，该实例封装了 Unreal `AudioCapture` 引擎插件，并通过 `UConvaiMicrophoneSubsystem`在不同会话间保存玩家选择的设备和增益。在 Android 上， `AndroidPermission` 插件负责处理运行时麦克风权限。

如需查看 `UConvaiPlayerComponent` 的完整属性列表——包括身份信息、会话、注视注意力和音频处理——请参阅 [Convai 玩家组件](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/blueprint-reference/convai-player-component.md).

### FCaptureDeviceInfoBP

`FCaptureDeviceInfoBP` 是由设备枚举和选择函数返回的 `BlueprintType` 结构体。所有字段均为 `EditAnywhere`, `BlueprintReadWrite`, `Category = "Convai|Microphone"`.

| 字段                     | 类型        | 默认值     | 说明                                                   |
| ---------------------- | --------- | ------- | ---------------------------------------------------- |
| `DeviceName`           | `FString` | `""`    | 在设备菜单中显示的易读名称。                                       |
| `DeviceIndex`          | `int`     | `0`     | 采集设备列表中的从零开始的索引。添加或移除设备后，索引可能会在不同会话间发生变化。            |
| `LongDeviceId`         | `FString` | `""`    | 特定于平台的设备标识符。在 Windows 上，它比 `DeviceIndex` 在不同会话间更加稳定。 |
| `InputChannels`        | `int`     | `0`     | 设备报告的输入通道数。                                          |
| `PreferredSampleRate`  | `int`     | `0`     | 设备首选采样率，单位为 Hz。                                      |
| `bSupportsHardwareAEC` | `bool`    | `false` | `true` 表示设备支持硬件声学回声消除。                               |

### Convai|Microphone 函数

这些 `BlueprintCallable` 函数均位于 `UConvaiPlayerComponent` 上（蓝图显示名称为 **Convai 玩家**).

#### 设备枚举

| 函数                                 | 参数                                                       | 返回                             | 说明                                                                                                                                                          |
| ---------------------------------- | -------------------------------------------------------- | ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `GetAvailableCaptureDeviceNames`   | —                                                        | `TArray<FString>`              | 所有可用输入设备的名称。将这些字符串用作显示标签，并作为 `DeviceName` 的参数 `SetCaptureDeviceByName`.                                                                                     |
| `GetAvailableCaptureDeviceDetails` | —                                                        | `TArray<FCaptureDeviceInfoBP>` | 完整 `FCaptureDeviceInfoBP` 结构体，包含每个可用设备的信息，包括索引、长 ID、通道数、采样率和 AEC 标志。                                                                                        |
| `GetDefaultCaptureDeviceInfo`      | `OutInfo (FCaptureDeviceInfoBP)` 输出                      | `bool`                         | **当前源码：** 验证 `AudioCaptureComponent`，然后始终返回 `false` 而不填充 `OutInfo`。请勿依赖此节点获取 `OutInfo` 。请改用 `GetAvailableCaptureDeviceDetails` 或 `GetActiveCaptureDevice` 。 |
| `GetCaptureDeviceInfo`             | `OutInfo (FCaptureDeviceInfoBP)` 输出， `DeviceIndex (int)` | `bool`                         | 填充 `OutInfo` ，其中包含索引为 `DeviceIndex`的设备信息。返回 `false` （索引超出范围时）。                                                                                              |
| `GetActiveCaptureDevice`           | `OutInfo (FCaptureDeviceInfoBP)` 输出                      | —                              | 填充 `OutInfo` ，其中包含当前选定的采集设备信息。                                                                                                                              |

#### 设备选择

| 函数                        | 参数                     | 返回     | 说明                                                    |
| ------------------------- | ---------------------- | ------ | ----------------------------------------------------- |
| `SetCaptureDeviceByIndex` | `DeviceIndex (int)`    | `bool` | 打开索引为 `DeviceIndex`的采集设备。返回 `false` （索引超出范围或设备无法打开时）。 |
| `SetCaptureDeviceByName`  | `DeviceName (FString)` | `bool` | 打开枚举列表中最后一个其 `DeviceName` 与输入匹配。未找到匹配项时返回 `false` 。   |

这两个选择函数都可以在游戏开始前或进行中调用。调用成功后， `GetActiveCaptureDevice` 会反映新设备。

#### 音量

| 函数                              | 参数                           | 返回                                              | 说明                                                      |
| ------------------------------- | ---------------------------- | ----------------------------------------------- | ------------------------------------------------------- |
| `SetMicrophoneVolumeMultiplier` | `InVolumeMultiplier (float)` | `Success (bool)`                                | 缩放捕获的音频信号。 `Success` 表示捕获组件是否可用，而不表示麦克风捕获当前是否正在流式传输或录制。 |
| `GetMicrophoneVolumeMultiplier` | —                            | `OutVolumeMultiplier (float)`, `Success (bool)` | 读取当前音量倍率。 `Success` 表示捕获组件是否可用。                         |

`InVolumeMultiplier` 在 API 中没有强制规定取值范围。值为 `1.0` 时不改变增益。高于 `1.0` 的值会放大信号；低于 `1.0` 的值会衰减信号。值为 `0.0` 时会静音捕获的音频，同时保持捕获会话处于活动状态。

#### 流式传输和录制状态

| 函数                                  | 类别       | 返回           | 说明     |
| ----------------------------------- | -------- | ------------ | ------ |
| `GetIsStreaming` （显示名称： **正在流式传输**) | \`Convai | Microphone\` | `bool` |
| `GetIsRecording` （显示名称： **正在录制**)   | \`Convai | Microphone\` | `bool` |

`StartRecording`, `FinishRecording`, `UnmuteStreamingAudio`和 `MuteStreamingAudio` 的说明位于 **音频流式传输和录制** 章节，详见 [Convai Player Component](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/blueprint-reference/convai-player-component.md).

#### 持久化设置

| 函数                             | 参数 | 返回     | 说明                                                                                                                         |
| ------------------------------ | -- | ------ | -------------------------------------------------------------------------------------------------------------------------- |
| `SaveMicrophoneSettings`       | —  | `bool` | 对播放器组件当前的捕获设备和增益进行快照，然后通过 `UConvaiMicrophoneSubsystem`将其持久化。播放器确认设备选择后调用此函数——选择设备只会将其应用于当前会话，直到调用此函数为止。子系统不可用时返回 `false` 。 |
| `ApplySavedMicrophoneSettings` | —  | `bool` | 将持久化的设备（如果设备已不再连接，则跳过）和增益重新应用到播放器组件。会在 `BeginPlay`期间自动调用；如果某个 UI 需要撤销未保存的更改，请再次调用此函数。子系统不可用时返回 `false` 。                   |

这两个函数都委托给下文介绍的 `UConvaiMicrophoneSubsystem`。

### UConvaiMicrophoneSubsystem

`UConvaiMicrophoneSubsystem` （Blueprint 显示名称： **Convai 麦克风子系统**）是一个 `UGameInstanceSubsystem` ，用于跨会话保存玩家的麦克风设备和增益偏好设置，因此每次启动时都不会重置为系统默认值。该类中所有向 Blueprint 暴露的成员均使用 `Category = "Convai|Microphone"`.

| 节点                                                                                | 类型                       | 参数                                         | 返回                            | 说明                                                                                                                      |
| --------------------------------------------------------------------------------- | ------------------------ | ------------------------------------------ | ----------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `Get` （显示名称： **Get**，派生生成——未显式设置 `DisplayName` 元数据）                               | `BlueprintPure`，静态       | `WorldContextObject`                       | `UConvaiMicrophoneSubsystem*` | 返回当前游戏实例的子系统实例。                                                                                                         |
| `GetMicrophoneSettings` （显示名称： **获取麦克风设置**)                                       | `BlueprintPure`          | —                                          | `FConvaiMicrophoneSettings`   | 返回子系统当前持有的设置。                                                                                                           |
| `HasSavedMicrophoneSettings` （显示名称： **是否已保存麦克风设置**)                               | `BlueprintPure`          | —                                          | `bool`                        | `true` 表示本次会话在磁盘上找到了已保存的记录，而非回退到默认值。                                                                                    |
| `SaveMicrophoneSettings` （显示名称： **保存麦克风设置**)                                      | `BlueprintCallable`      | `InSettings (FConvaiMicrophoneSettings)`   | —                             | 替换当前持有的设置，并将其写入共享记录。会广播 `OnMicrophoneSettingsChanged`。需要显式传入设置值——这不同于 `UConvaiPlayerComponent`上同名的节点；后者会读取组件当前使用的设备和增益。 |
| `SaveMicrophoneSettingsFromPlayerComponent` （显示名称 **从 Player Component 保存麦克风设置**) | `BlueprintCallable`      | `PlayerComponent (UConvaiPlayerComponent)` | `bool`                        | 快照 `PlayerComponent`的实时采集设备和增益，然后将其持久化。这是 `UConvaiPlayerComponent::SaveMicrophoneSettings` 在内部调用的函数。                    |
| `ResetMicrophoneSettingsToDefaults` （显示名称 **将麦克风设置重置为默认值**)                       | `BlueprintCallable`      | —                                          | —                             | 清除已保存的选择并删除共享记录。                                                                                                        |
| `GetAvailableMicrophoneNames` （显示名称 **获取可用的麦克风名称**)                               | `BlueprintCallable`      | —                                          | `TArray<FString>`             | 当前存在的设备名称，与 `UConvaiPlayerComponent::GetAvailableCaptureDeviceNames`.                                                   |
| `IsSavedMicrophoneAvailable` （显示名称 **检查已保存的麦克风是否可用**)                             | `BlueprintCallable`      | —                                          | `bool`                        | `true` ：已保存设备，且当前已连接。 `false` 未保存任何设备时属于正常的“跟随系统默认设置”情况，并非错误。                                                           |
| `ApplySavedSettingsToPlayerComponent` （显示名称 **将已保存的设置应用到 Player Component**)      | `BlueprintCallable`      | `PlayerComponent (UConvaiPlayerComponent)` | `bool`                        | 将已保存的增益以及仍然可用的已保存设备应用到 `PlayerComponent`。返回 `true` 仅当已解析并选中已保存的设备时返回。                                                   |
| `OnMicrophoneSettingsChanged` （显示名称 **麦克风设置已更改时**)                                | `BlueprintAssignable` 事件 | `NewSettings (FConvaiMicrophoneSettings)`  | —                             | 每当 `SaveMicrophoneSettings` 在子系统上运行时广播。                                                                                 |

### FConvaiMicrophoneSettings

`FConvaiMicrophoneSettings` (`BlueprintType`, `Category = "Convai|Microphone"`）是 `UConvaiMicrophoneSubsystem` 持久化的结构体。

| 字段                | 类型        | 默认值   | 说明                                                                                            |
| ----------------- | --------- | ----- | --------------------------------------------------------------------------------------------- |
| `InputDeviceName` | `FString` | `""`  | 留空表示使用系统默认设备。否则， `DeviceName` 值必须来自 `UConvaiPlayerComponent::GetAvailableCaptureDeviceNames`. |
| `InputGain`       | `float`   | `1.0` | 应用于麦克风输入增益的倍率。 `1.0` 保持不变；编辑器 UI 会将字段限制在 `0.0`–`2.0` 范围内。                                     |

### ConvaiAudioCaptureComponent

`UConvaiAudioCaptureComponent` （C++ 类， `ClassGroup = Synth`）继承自 `USynthComponent` ，并封装了 `FConvaiAudioCaptureSynth`；后者又封装了 Unreal 的 `FAudioCapture` 对象。 `UConvaiPlayerComponent` 会自动创建并拥有一个实例；你无需手动将其添加到 Actor。 `UConvaiAudioCaptureComponent` 。

{% hint style="info" %}
在大多数蓝图中，请使用 `UConvaiPlayerComponent` 上的麦克风函数，而不要直接与 `UConvaiAudioCaptureComponent` 交互。玩家组件会在内部转发调用，并提供前文各节所述的更高层级流式传输 API。
{% endhint %}

该组件声明了一个可通过蓝图配置的 Convai 专属属性；继承自 `USynthComponent` 的属性同样适用。

| 属性                    | 类型      | 类别        | 约束                                | 说明                                                          |
| --------------------- | ------- | --------- | --------------------------------- | ----------------------------------------------------------- |
| `JitterLatencyFrames` | `int32` | `Latency` | `ClampMin = 0`, `ClampMax = 1024` | 用于抖动缓冲的延迟设置。在当前插件源码中，Convai 采集实现不会读取此属性，因此更改它不会产生已验证的运行时效果。 |

大多数设备枚举和设备切换行为都通过 `UConvaiPlayerComponent` 实现——上文列出的蓝图函数会在内部转发到底层的 `UConvaiAudioCaptureComponent` ，但 `GetDefaultCaptureDeviceInfo` （玩家组件上的该函数）除外；它目前不会将调用转发到采集组件。

在 C++ 层， `UConvaiAudioCaptureComponent::GetDefaultCaptureDeviceInfo` 会填充系统默认设备信息。该方法未向蓝图公开。组件的其他设备方法（`GetCaptureDevicesAvailable`, `GetCaptureDeviceInfo`, `GetActiveCaptureDevice`, `SetCaptureDevice`) 也是 C++ 内部实现。

### 插件依赖项

这两个依赖项都在 `ConvAI.uplugin` 中声明，并且在安装 Convai 插件时会自动启用。无需手动激活插件。

| 插件                  | 已启用    | 用途                                                                                                   |
| ------------------- | ------ | ---------------------------------------------------------------------------------------------------- |
| `AudioCapture`      | `true` | Unreal Engine 内置插件，提供 `FAudioCapture` 和 `USynthComponent`驱动的音频采集。在 Win64 和 Android 上采集所有麦克风输入都需要此插件。 |
| `AndroidPermission` | `true` | Unreal Engine 内置插件，提供用于检查和请求 Android 运行时权限的蓝图节点。在 Android 上访问麦克风需要此插件。                               |

#### Android 麦克风权限

在 Android 上，操作系统要求获得运行时权限才能采集音频。若未获得该权限， `UConvaiAudioCaptureComponent` 已初始化，但未捕获到音频——Convai 角色收不到语音输入。插件不会记录权限被拒绝的消息，不过打开流失败时仍可能产生采集警告。

{% hint style="warning" %}
请在调用 `android.permission.RECORD_AUDIO` 之前请求权限，然后再调用 `StartSession` 或 `UnmuteStreamingAudio`。如果权限被拒绝，音频采集会静默地不产生任何数据。
{% endhint %}

使用 `AndroidPermission` 用于请求权限的蓝图节点：

1. 调用 `Check Android Permission` 并传入权限字符串 `android.permission.RECORD_AUDIO`.
2. 如果返回值为 `false`，则调用 `Request Android Permission` 并传入相同的权限字符串。
3. 绑定到 `On Permission Request Complete` 委托，并且仅在确认已获得权限后才开始对话。

&#x20;`AndroidPermission` 插件节点位于 `Android Permission` Blueprint 类别中。在 Win64 上，这些节点不执行任何操作——同一个 Blueprint 图可在两个平台上使用，无需添加平台保护条件。

### 相关参考

玩家组件页面介绍了完整的属性范围；操作指南则会演示如何在发布前选择并测试设备。

{% content-ref url="/pages/7882b4c0154c419a4eb6df2db3b2035b55cacb03" %}
[Convai 玩家组件](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/blueprint-reference/convai-player-component.md)
{% endcontent-ref %}

{% content-ref url="/pages/ddab80eff30a95a57bb3cec04bc4566233e30263" %}
[配置麦克风](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/getting-started/configure-the-microphone.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/microphone-and-audio-capture.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.
