文档

​
​

Development

User Acquisition

Monetization

工业

Vivox Unity SDK

Vivox Unity SDK

Vivox
​
​
Vivox Unity SDK
  • Overview
  • Get started
  • Release notes
  • Developer guide
    • Set up your project
    • Create voice and text channels
    • Messaging
    • Player management
    • Device management
      • In-game audio device selection
    • Audio management
    • Mobile development
    • Text-to-speech
    • Speech-to-text
    • Real-time recording
    • Server-side-recording
    • Troubleshooting
  • Tutorials
  • Reference
  1. Vivox Unity SDK 文档
  2. Vivox Unity 开发者指南

音频设备管理

Allow players to select audio input and output devices.
阅读时间4 分钟
最后更新于 8 个月前

Vivox SDK 会自动使用系统默认音频输入和输出设备。您可以尝试覆盖此行为,让用户能够选择要用于群组语音聊天的音频设备(独立于用于游戏的音频设备)。
若要执行这种覆盖,请在游戏中构建一个用户界面,向用户显示他们可以从中选择设备的可用设备列表。请为 InputDevices 和 OutputDevices 构建此用户界面,并利用
VivoxService.Instance.AvailableInputDevices
和
VivoxService.Instance.AvailableOutputDevices
返回
VivoxInputDevices
或
VivoxOutputDevices
的一个 ReadOnlyCollection,然后使用这些设备的名称填充此 UI。
此用户界面应订阅
VivoxService.Instance.AvailableInputDevicesChanged
和
VivoxService.Instance.AvailableOutputDevicesChanged
操作,并使用
VivoxService.Instance.AvailableInputDevices
和
VivoxService.Instance.AvailableOutputDevices
中的新列表刷新 UI,以捕获 AudioDevices 列表中的任何添加或移除操作。
用户从列表中选择设备后,使用 V
ivoxService.Instance.SetActiveInputDeviceAsync(VivoxInputDevice device)
设置输入设备,使用
VivoxService.Instance.SetActiveOutputDeviceAsync(VivoxOutputDevice device)
设置输出设备。
以下示例说明从列表中选择音频设备后应如何设置该设备。此处还包括一项检查,确保音频设备仍在设备列表中,进而确保在加载用户界面时音频设备未发生变化。
async void SetVivoxInputDeviceAsync(VivoxInputDevice device){ if(VivoxService.Instance.AvailableInputDevices.Contains(device)) { await VivoxService.Instance.SetActiveInputDeviceAsync(device); }}await void SetVivoxOutputDeviceAsync(VivoxInputDevice device){ if(VivoxService.Instance.AvailableOutputDevices.Contains(device)) { await VivoxService.Instance.SetActiveOutputDeviceAsync(device); }}
Chat Channel Sample 有一个 UI 对象的示例在
AudioDeviceSettings.cs
中控制 AudioDevice 列表。

识别有效设备

参与者可以使用虚拟设备(例如
Default System Device
或
Default Communication Device
)作为进行语音聊天时的活动设备。有时,您可能需要虚拟设备所代表的物理设备的相关信息,例如在尝试对特定于设备的错误进行故障排除时。
物理设备在 Vivox SDK 中称为有效设备。
Vivox SDK 包含的一些属性和事件可以检查有效输入和输出设备并订阅相关更改。
VivoxService.Instance.EffectiveInputDeviceChanged;VivoxService.Instance.EffectiveOutputDeviceChanged;VivoxService.Instance.EffectiveInputDevice;VivoxService.Instance.EffectiveOutputDevice;
例如,当玩家选择
Default System Device
作为其游戏内输入设备时,在玩家系统设置中设置为
Default System Device
的底层麦克风将成为实际使用的设备。在这种情况下,
VivoxService.Instance.EffectiveInputDevice
返回一个代表正在使用的真实输入设备的对象。下图是 Chat Channel Sample 中的相关设置:
Chat Channel Sample 音频设备选择菜单的屏幕截图,其中显示了有效设备。

Chat Channel Sample 音频设备选择菜单的屏幕截图,其中显示了有效设备。

即使可用设备列表或活动设备没有改变,有效设备也可能改变,例如用户在 Windows 计算机上的 System Settings 中调整
Default System Device
。在这种情况下,可用设备列表和活动设备都不会改变,但有效设备会改变,因为
Default System Device
使用的实际设备已经改变。

Copyright © 2026 Unity Technologies
法律信息隐私政策CookiesDocumentation Terms of Use请勿出售或分享我的个人信息您的隐私选择(Cookie 设置)

“Unity”、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属公司在美国和其他地方的商标或注册商标(此处查看更多信息)。其他名称或品牌是其各自所有者的商标。

为方便起见,一些页面是机器翻译的,可能包含不准确的内容。如有信息不一致的情况,以英文版本为准。

  • 在本页上
    • 识别有效设备


报告此页面的问题