LocalAudioTrack represents a local audio track that captures audio from the device’s microphone. It provides methods for muting/unmuting and managing audio capture with configurable audio processing options.
Creating a Track
Create a local audio track using the static factory method:createTrack
Static factory method to create a newLocalAudioTrack instance.
The name of the audio track
Audio capture configuration options. If
nil, default options are used.See AudioCaptureOptions for available settings:echoCancellation: Software echo cancellationautoGainControl: Automatic gain controlnoiseSuppression: Noise suppressiontypingNoiseDetection: Typing noise detectionhighpassFilter: High-pass filter
Whether to collect and report statistics for this track
LocalAudioTrack instance configured with the specified options.
Properties
captureOptions
AudioCaptureOptions used to create this track. This is a read-only property that reflects the audio processing settings configured during track creation.
publishOptions
nil if not yet published.
publishState
.unpublished: Track has not been published.published: Track is currently published
Inherited Properties
From the baseTrack class:
name: The track namesid: The server-assigned track ID (available after publishing)kind: Always.audiofor audio trackssource: Always.microphonefor local audio tracksisMuted: Whether the track is currently mutedtrackState: Current state (.startedor.stopped)statistics: Real-time statistics ifreportStatisticsis enabled
Methods
mute()
Mutes the audio track by disabling audio capture.unmute()
Unmutes the audio track by enabling audio capture.add(audioRenderer:)
Adds anAudioRenderer to receive audio buffers from this track.
An object conforming to the
AudioRenderer protocol that will receive PCM audio buffersremove(audioRenderer:)
Removes a previously addedAudioRenderer.
The renderer to remove
start()
Starts audio capture. Inherited fromTrack.
stop() calls.
stop()
Stops audio capture. Inherited fromTrack.
set(reportStatistics:)
Enables or disables statistics reporting at runtime.true to enable statistics collection, false to disableTrack Lifecycle
- Creation: Create track using
createTrack() - Publishing: Publish track via
LocalParticipant.publish(track:options:) - Capturing: Track automatically starts capturing when published
- Muting/Unmuting: Use
mute()andunmute()to control audio transmission - Unpublishing: Unpublish via
LocalParticipant.unpublish(track:) - Cleanup: Track is automatically cleaned up when deallocated
Thread Safety
LocalAudioTrack is @unchecked Sendable and thread-safe. All public methods can be called from any thread, though delegate callbacks are delivered on background threads.
Example Usage
See Also
- RemoteAudioTrack - Receiving remote audio
- AudioCaptureOptions - Audio capture configuration
- AudioManager - System audio management
- Publishing - Publishing tracks to the room