Table of Contents

Class AudioFrame

Namespace
LiveKit.Rtc
Assembly
LivekitRtc.dll

Represents a frame of audio data with specific properties such as sample rate, number of channels, and samples per channel. The format of the audio data is 16-bit signed integers (Int16) interleaved by channel.

public class AudioFrame
Inheritance
AudioFrame
Inherited Members

Constructors

AudioFrame(byte[], int, int, int, Dictionary<string, object>?)

Initialize an AudioFrame instance from raw bytes.

public AudioFrame(byte[] data, int sampleRate, int numChannels, int samplesPerChannel, Dictionary<string, object>? userdata = null)

Parameters

data byte[]

The raw audio data as bytes (must be Int16 samples).

sampleRate int

The sample rate of the audio in Hz.

numChannels int

The number of audio channels.

samplesPerChannel int

The number of samples per channel.

userdata Dictionary<string, object>

Optional user data dictionary.

AudioFrame(short[], int, int, int, Dictionary<string, object>?)

Initialize an AudioFrame instance.

public AudioFrame(short[] data, int sampleRate, int numChannels, int samplesPerChannel, Dictionary<string, object>? userdata = null)

Parameters

data short[]

The raw audio data as Int16 samples.

sampleRate int

The sample rate of the audio in Hz.

numChannels int

The number of audio channels (e.g., 1 for mono, 2 for stereo).

samplesPerChannel int

The number of samples per channel.

userdata Dictionary<string, object>

Optional user data dictionary.

Properties

Data

Gets the raw audio data as Int16 samples.

public ReadOnlySpan<short> Data { get; }

Property Value

ReadOnlySpan<short>

DataArray

Gets the raw audio data as an array (for async operations).

public short[] DataArray { get; }

Property Value

short[]

DataBytes

Gets the raw audio data as bytes.

public byte[] DataBytes { get; }

Property Value

byte[]

DataMutable

Gets the raw audio data as a mutable span.

public Span<short> DataMutable { get; }

Property Value

Span<short>

Duration

Gets the duration of the audio frame in seconds.

public double Duration { get; }

Property Value

double

NumChannels

Gets the number of channels in the audio frame.

public int NumChannels { get; }

Property Value

int

SampleRate

Gets the sample rate of the audio frame in Hz.

public int SampleRate { get; }

Property Value

int

SamplesPerChannel

Gets the number of samples per channel.

public int SamplesPerChannel { get; }

Property Value

int

TotalSamples

Gets the total number of samples (all channels).

public int TotalSamples { get; }

Property Value

int

Userdata

Gets the user data associated with the audio frame.

public Dictionary<string, object> Userdata { get; }

Property Value

Dictionary<string, object>

Methods

Clone()

Creates a copy of this audio frame.

public AudioFrame Clone()

Returns

AudioFrame

A deep copy of the frame, with its own sample buffer.

Create(int, int, int)

Create a new empty AudioFrame instance with specified parameters.

public static AudioFrame Create(int sampleRate, int numChannels, int samplesPerChannel)

Parameters

sampleRate int

The sample rate of the audio in Hz.

numChannels int

The number of audio channels.

samplesPerChannel int

The number of samples per channel.

Returns

AudioFrame

A new AudioFrame instance with zeroed data.

GetSample(int, int)

Gets a sample at a specific index.

public short GetSample(int channel, int sampleIndex)

Parameters

channel int

The channel index (0-based).

sampleIndex int

The sample index within the channel.

Returns

short

The sample value.

SetSample(int, int, short)

Sets a sample at a specific index.

public void SetSample(int channel, int sampleIndex, short value)

Parameters

channel int

The channel index (0-based).

sampleIndex int

The sample index within the channel.

value short

The sample value to set.

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

ToWavBytes()

Converts the audio frame to a WAV file byte array.

public byte[] ToWavBytes()

Returns

byte[]

The audio data encoded in WAV format.