#[non_exhaustive]pub enum RtcAudioSource {
Native(NativeAudioSource),
Device,
}Expand description
Audio source type for creating audio tracks.
Choose the appropriate source based on your use case:
| Use Case | Source | Description |
|---|---|---|
| Manual audio (TTS, files) | RtcAudioSource::Native(source) | Push frames manually |
| Microphone capture | RtcAudioSource::Device | Automatic via Platform ADM |
| Both (mic + screen) | Use both types | Multiple tracks supported |
§Combining Sources
You can have multiple audio tracks with different source types:
- Track A:
RtcAudioSource::Devicefor microphone (viaPlatformAudio) - Track B:
RtcAudioSource::Nativefor screen capture or TTS
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Native(NativeAudioSource)
Native audio source for manual audio frame capture.
Use this with Synthetic ADM mode (the default). You push audio frames
manually via NativeAudioSource::capture_frame().
§Example
use livekit::webrtc::audio_source::native::NativeAudioSource;
use livekit::webrtc::audio_source::{AudioSourceOptions, RtcAudioSource};
let source = NativeAudioSource::new(
AudioSourceOptions::default(),
48000, 2, 100,
);
source.capture_frame(&frame).await?;
let track = LocalAudioTrack::create_audio_track(
"audio",
RtcAudioSource::Native(source),
);Device
Device audio source - uses Platform ADM for automatic microphone capture.
WebRTC automatically captures audio from the selected recording device (microphone). You do NOT push frames manually.
§Usage
Use PlatformAudio from the livekit crate, which manages the Platform ADM
lifecycle and provides RtcAudioSource::Device via rtc_source():
use livekit::prelude::*;
// Create PlatformAudio (enables Platform ADM)
let audio = PlatformAudio::new()?;
// Optionally select a specific device
if let Some(device) = audio.recording_devices().next() {
audio.set_recording_device(&device.id)?;
}
// Create track using the device source
let track = LocalAudioTrack::create_audio_track("mic", audio.rtc_source());§Combining with NativeAudioSource
You CAN use NativeAudioSource alongside Platform ADM to have multiple
audio tracks with different sources (e.g., microphone + screen capture).
§Platform Support
- iOS: CoreAudio with VPIO (Voice Processing IO)
- macOS: CoreAudio
- Windows: WASAPI
- Linux: PulseAudio / ALSA
- Android: AAudio / OpenSL ES
Implementations§
Source§impl RtcAudioSource
impl RtcAudioSource
Sourcepub fn set_audio_options(&self, options: AudioSourceOptions)
pub fn set_audio_options(&self, options: AudioSourceOptions)
Set audio processing options.
Note: For Device source, options are controlled by the Platform ADM.
Sourcepub fn audio_options(&self) -> AudioSourceOptions
pub fn audio_options(&self) -> AudioSourceOptions
Get audio processing options.
Note: For Device source, returns default options (actual options are managed by ADM).
Sourcepub fn sample_rate(&self) -> u32
pub fn sample_rate(&self) -> u32
Get the sample rate.
Note: For Device source, returns DEFAULT_SAMPLE_RATE (48kHz).
Sourcepub fn num_channels(&self) -> u32
pub fn num_channels(&self) -> u32
Get the number of channels.
Note: For Device source, returns DEFAULT_NUM_CHANNELS (mono).
Trait Implementations§
Source§impl Clone for RtcAudioSource
impl Clone for RtcAudioSource
Source§fn clone(&self) -> RtcAudioSource
fn clone(&self) -> RtcAudioSource
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more