Class AudioSource
- Namespace
- LiveKit.Rtc
- Assembly
- LivekitRtc.dll
Represents a real-time audio source with an internal audio queue. The AudioSource class allows you to push audio frames into a real-time audio source, managing an internal queue of audio data.
public class AudioSource : IDisposable
- Inheritance
-
AudioSource
- Implements
- Inherited Members
Constructors
AudioSource(int, int, int)
Initializes a new instance of the audio source.
public AudioSource(int sampleRate, int numChannels, int queueSizeMs = 1000)
Parameters
sampleRateintThe sample rate of the audio source in Hz.
numChannelsintThe number of audio channels.
queueSizeMsintThe buffer size of the audio queue in milliseconds. Defaults to 1000 ms.
Properties
NumChannels
Gets the number of audio channels.
public int NumChannels { get; }
Property Value
QueuedDuration
Gets the current duration (in seconds) of audio data queued for playback.
public double QueuedDuration { get; }
Property Value
SampleRate
Gets the sample rate of the audio source in Hz.
public int SampleRate { get; }
Property Value
Methods
CaptureFrame(AudioFrame)
Captures an AudioFrame and blocks the calling thread until the native source accepts it, which can take a while when the queue is full. Prefer CaptureFrameAsync(AudioFrame, CancellationToken) in asynchronous code.
public void CaptureFrame(AudioFrame frame)
Parameters
frameAudioFrameThe audio frame to capture and queue.
CaptureFrameAsync(AudioFrame, CancellationToken)
Captures an AudioFrame and queues it for playback.
public Task CaptureFrameAsync(AudioFrame frame, CancellationToken cancellationToken = default)
Parameters
frameAudioFrameThe audio frame to capture and queue.
cancellationTokenCancellationTokenOptional cancellation token.
Returns
- Task
A task that completes once the native source has accepted the frame.
ClearQueue()
Clears the internal audio queue, discarding all buffered audio data.
public void ClearQueue()
CreateTrack(string)
Creates a local audio track from this audio source.
public LocalAudioTrack CreateTrack(string name = "audio")
Parameters
namestringThe name of the track.
Returns
- LocalAudioTrack
A new LocalAudioTrack.
Dispose()
Releases the native source. Queued audio is dropped and pending WaitForPlayoutAsync(CancellationToken) calls complete.
public void Dispose()
WaitForPlayoutAsync(CancellationToken)
Waits for the audio source to finish playing out all audio data.
public Task WaitForPlayoutAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenCancels this wait only; the queued audio keeps playing.
Returns
- Task
A task that completes when all queued audio has been played out.