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
databyte[]The raw audio data as bytes (must be Int16 samples).
sampleRateintThe sample rate of the audio in Hz.
numChannelsintThe number of audio channels.
samplesPerChannelintThe number of samples per channel.
userdataDictionary<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
datashort[]The raw audio data as Int16 samples.
sampleRateintThe sample rate of the audio in Hz.
numChannelsintThe number of audio channels (e.g., 1 for mono, 2 for stereo).
samplesPerChannelintThe number of samples per channel.
userdataDictionary<string, object>Optional user data dictionary.
Properties
Data
Gets the raw audio data as Int16 samples.
public ReadOnlySpan<short> Data { get; }
Property Value
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
Duration
Gets the duration of the audio frame in seconds.
public double Duration { get; }
Property Value
NumChannels
Gets the number of channels in the audio frame.
public int NumChannels { get; }
Property Value
SampleRate
Gets the sample rate of the audio frame in Hz.
public int SampleRate { get; }
Property Value
SamplesPerChannel
Gets the number of samples per channel.
public int SamplesPerChannel { get; }
Property Value
TotalSamples
Gets the total number of samples (all channels).
public int TotalSamples { get; }
Property Value
Userdata
Gets the user data associated with the audio frame.
public Dictionary<string, object> Userdata { get; }
Property Value
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
sampleRateintThe sample rate of the audio in Hz.
numChannelsintThe number of audio channels.
samplesPerChannelintThe 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
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
channelintThe channel index (0-based).
sampleIndexintThe sample index within the channel.
valueshortThe 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.