Volume / Audio Settings

Inherit from EasyManager.cs

using EasyCodeForVivox;

public class VivoxManager : EasyManager
{

}

Inject EasyAudio

using EasyCodeForVivox;
using System.IO;
using System.Linq;
using UnityEngine;
using Zenject;

public class VivoxAudio : MonoBehaviour
{
        EasyAudio _audio;

        [Inject]
        private void Initialize(EasyAudio audio)
        {
            _audio = audio;
        }
}

Volume Adjustment

Adjust Volume for Local User, only int values are valid.

Vivox Documentation recommends only letting users set the volume up to 25. Accepted values are between -50 and 50 int

  • Adjust volume for local player volume level to 15.

EasyManager

public void AdjustLocalPlayerVolume()
{
    AdjustLocalUserVolume(15);
}

EasyAudio

public void AdjustLocalPlayerAudioVolume()
{
    _audio.AdjustLocalPlayerAudioVolume(15, EasySession.Client);
}

Remote Player Volume

Adjust Volume for Remote User, only int values are valid. Player must be logged in and in the same channel as the user calling this method.

Vivox Documentation recommends only letting users set the volume up to 25. Accepted values are between -50 and 50 int

  • Adjust volume for Remote player "userName", in channel "channelName", and changes volume level to 15.

EasyManager

public void AdjustRemotePlayerVolume()
{
    AdjustRemoteUserVolume("userName", "channelName", 15);
}

EasyAudio

public void AdjustRemotePlayerAudioVolume()
{
    _audio.AdjustRemotePlayerAudioVolume("userName", EasySession.ChannelSessions["channelName"], 15);
}

Auto Voice Activity Detection

For More information on Voice Activity Detection check out the Vivox Docs

  • Set Auto Voice Activity Detection (VAD) - Recommended by Vivox

EasyManager

public void SetAutoVoiceActivity()
{
    SetAutoVoiceActivityDetection("userName");
}

EasyAudio

public void SetAutoVoiceActivityDetection()
{
    _audio.SetAutoVoiceActivityDetection("userName");
}

Custom Voice Activity Detection

For More information on Voice Activity Detection check out the Vivox Docs

Set custom values for Voice Activity Detection (VAD). For more information on what the parameters do check out Vivox Docs

EasyManager

public void SetVoiceActivity()
{
    SetVoiceActivityDetection("userName", hangover: 2000, sensitivity: 43, noiseFloor: 576);
}

EasyAudio

public void SetVoiceActivityDetection()
{
    _audio.SetVoiceActivityDetection("userName", hangover: 2000, sensitivity: 43, noiseFloor: 576);
}

Get Audio Input/Output Devices

Get all Audio Input or Output devices to display to players or use internally in your app/game

  • Input devices - Microphones

  • Output devices - Speakers / Headphones

EasyManager

public void GetAllAudioInputDevices()
{
    var audioDevices = GetAudioInputDevices();
}

public void GetAllAudioOutputDevices()
{
    var audioDevices = GetAudioOutputDevices();
}

EasyAudio

public void GetAllAudioInputDevices()
{
    var audioDevices = _audio.GetAudioInputDevices(EasySession.Client);
}

public void GetAllAudioOutputDevices()
{
    var audioDevices = _audio.GetAudioOutputDevices(EasySession.Client);
}

Set Audio Input/Output Devices

If you allow your users to change Audio Device settings within your app/game, then you want to use the following methods to change

  • Input devices - Microphones

  • Output devices - Speakers / Headphones

In the code example I get all the current available audio devices. You should display these options to your players in a dropdown or type of list. Then whatever device the player chooses you would then call the Set methods for changing audio devices. As you can see I am choosing the first device in the list and setting that as the current audio device Vivox will use.

Only affects Vivox, your in-game audio/SFX should still use any previous selected or default Audio device

These are examples and not meant to replicate real world use cases.

EasyManager

public void SetAudioInputDevice()
{
    var audioDevices = GetAudioInputDevices().ToList();
    foreach (var device in audioDevices)
    {
        Debug.Log(device.Name);
    }
    SetAudioInputDevice(audioDevices.First().Name);
}

public void SetAudioOutputDevice()
{
    var audioDevices = GetAudioOutputDevices().ToList();
    foreach (var device in audioDevices)
    {
        Debug.Log(device.Name);
    }
    SetAudioOutputDevice(audioDevices.First().Name);
}

EasyAudio

public void SetAudioInputDevice()
{
    var audioDevices = _audio.GetAudioInputDevices(EasySession.Client).ToList();
    foreach (var device in audioDevices)
    {
        Debug.Log(device.Name);
    }
    _audio.SetAudioInputDevice(audioDevices.First().Name, EasySession.Client);
}

public void SetAudioOutputDevice()
{
    var audioDevices = _audio.GetAudioOutputDevices(EasySession.Client).ToList();
    foreach (var device in audioDevices)
    {
        Debug.Log(device.Name);
    }
    _audio.SetAudioOutputDevice(audioDevices.First().Name, EasySession.Client);
}

Refresh Audio Devices

Refreshes Vivox's internal list of Audio Devices

Only affects Vivox, your in-game audio/SFX should still use any previous selected or default Audio device

Examples refresh both Input and Output audio devices

EasyManager

public void RefreshAllAudioDevices()
{
    RefreshAudioInputDevices();
    RefreshAudioOutputDevices();
}

EasyAudio

public void RefreshAllAudioDevices()
{
    _audio.RefreshAudioInputDevices(EasySession.Client);
    _audio.RefreshAudioOutputDevices(EasySession.Client);
}

Inject Audio into Channel

Inject audio ".wav" files into a channel on behalf of user if they have transmission (Audio/Voice capabilities and aren't muted in the channel) active in that channel

For more information on what type of files you can inject see Vivox Documentation

  • I am injecting audio on behalf of player "userName"

  • I am getting the current directory of the app/game and then adding the path to the ".wav" file that will be injected

EasyManager

public void StartInjectingAudio()
{
    StartAudioInjection("userName", $"{Directory.GetCurrentDirectory()}/pathToFile.wav");
}

public void StopInjectingAudio()
{
    StopAudioInjection("userName");
}

EasyAudio

public void StartInjectingAudio()
{
    _audio.StartAudioInjection($"{Directory.GetCurrentDirectory()}/pathToFile.wav", EasySession.LoginSessions["userName"]);
}

public void StopInjectingAudio()
{
    _audio.StopAudioInjection(EasySession.LoginSessions["userName"]);
}

Last updated