Important: This is documentation for the legacy version of the Vivox Unity SDK. This documentation will be removed after July 2025. Refer to the v16 documentation for the new version of the SDK.

In-game audio device selection

The Vivox SDK automatically uses the system default audio input and output devices. However, you can override this behavior and provide users with a choice of which audio device to use for group voice chat independent of the audio devices that are used for the game.

To perform this override, build a user interface for the game that displays a list of available devices to users that they can select a device from. Build this user interface with the following requests, where audio output devices are called render devices, and audio input devices are called capture devices:

  • IAudioDevices.AvailableDevices
  • IAudioDevices.CommunicationDevice
  • IAudioDevices.SystemDevice
  • IAudioDevices.BeginSetActiveDevice
  • IAudioDevices.EndSetActiveDevice
  • IAudioDevices.EffectiveDevice

IAudioDevices.AvailableDevices returns an IReadOnlyDictionary<string, IAudioDevice> dictionary that contains a list of every device name and its corresponding Vivox IAudioDevice object. Use this request to populate a drop-down menu or to pass the appropriate IAudioDevice device in to IAudioDevices.BeginSetActiveDevice.

The following code is an example of a scenario in which a user has already selected an IAudioDevice and needs to pass it in.

public void SetAudioDevices(IAudioDevice targetInput = null, IAudioDevice targetOutput = null)
{
    IAudioDevices inputDevices = _client.AudioInputDevices;
    IAudioDevices outputDevices = _client.AudioOutputDevices;
    if(targetInput != null && targetInput != _client.AudioInputDevices.ActiveDevice)
    {
        _client.AudioInputDevices.BeginSetActiveDevice(targetInput, ar => 
        {
            if(ar.IsCompleted)
            {
                _client.AudioInputDevices.EndSetActiveDevice(ar);
            }
        }
    });
    if(targetOutput != null && targetOutput!= _client.AudioOutputDevices.ActiveDevice)
    {
        _client.AudioOutputDevices.BeginSetActiveDevice(targetOutput, ar =>
        {
            if(ar.IsCompleted)
            {
                _client.AudioOutputDevices.EndSetActiveDevice(ar);
            }
        }
    });
}

When a user selects a new device, the game passes the appropriate IAudioDevice in to IAudioDevices.BeginSetActiveDevice.

Alternately, you can pass IAudioDevices.SystemDevice() or IAudioDevices.CommunicationDevice() in to IAudioDevices.BeginSetActiveDevice to set the ActiveDevice to the system's default device or the system's communication device, respectively.

To alert the game to changes in the IAudioDevices setup, bind to the following events:

  • VivoxClient.AudioInputDevices.AvailableDevices.AfterKeyAdded
  • VivoxClient.AudioInputDevices.AvailableDevices.BeforeKeyRemoved
  • VivoxClient.AudioInputDevices.AvailableDevices.AfterValueUpdated

Binding to these events helps you to build a responsive system that can handle device hotswapping.