Access audio data

For some use cases, analyzing the raw audio data provided by the Audio Taps might be useful. You can create MonoBehaviour C# scripts that implement the OnAudioFilterRead method and add them to the Audio Source GameObject. When added to the Audio Source component chain that contains the Audio Tap, your C# script receives all of the audio provided by the Audio Tap. The following is an example of a class called AudioAnalyzer that is set to receive audio data:

using UnityEngine;
public class AudioAnalyzer : MonoBehaviour
{
    private void OnAudioFilterRead(float[] data, int channels)
    {
        // Do something with the audio contained in the data array
    }
}

In the following image, you can find the AudioAnalyzer class after the Vivox Channel Audio in the Audio Source component chain, making the Vivox Channel Audio Tap audio available in the Audio Analyzer script:

A screenshot of the Unity Editor Inspector window showing the audio tap components.

Note that the order in which components are added to the Audio Source Game Object matters. If you were to have two OnAudioFilterRead implementations in different classes added to the GameObject, they would each get called sequentially, from top to bottom. This does not apply to the Audio Taps, as their audio is provided at the very beginning of the chain, no matter their position in the chain.

To access raw audio data from native code, see Unity’s Native Audio Plug-In SDK documentation.

Co-existing audio systems

Unity and Vivox have co-existing audio systems.

When you add Audio Taps to your game, tap audio is played through Unity’s audio engine rather than through Vivox’s independent audio system. In this case, the device you set to render audio in Vivox may not be the same that Unity is set to use. Since Unity takes over tap audio rendering, you need to make sure that the device Unity uses for rendering is what you expect it to be.

When only using participant taps, Channel Audio output is still played from Vivox’s audio system, while participant taps playing through audio sources are using Unity’s audio system.

Note: Vivox always uses its own selected capture audio device regardless of Audio Tap usage or Unity microphone settings.