nice-coat-4178
08/22/2025, 6:49 PMsource = rtc.AudioSource(SAMPLE_RATE, NUM_CHANNELS)
track = rtc.LocalAudioTrack.create_audio_track("example-track", source)
what is the equivalent of this in the swift sdk? can a stream be written to from a file in swift?tall-airline-16756
08/22/2025, 6:49 PMtall-airline-16756
08/22/2025, 6:50 PMLocalAudioTrack.createTrack() method:
let localMicTrack = LocalAudioTrack.createTrack()
If you’re looking to stream audio from a file, the SDK has a couple of great options for you:
• Using `AudioMixRecorder`: This lets you schedule audio files for playback and streaming easily:
// Create an audio mix recorder
let recorder = try AudioMixRecorder(filePath: outputURL, audioSettings: audioSettings)
// Add a source that can schedule files
let fileSource = recorder.addSource()
// Schedule an audio file to be played/streamed
let audioFile = try AVAudioFile(forReading: inputFileURL)
fileSource.scheduleFile(audioFile)
// Start recording/streaming
try recorder.start()
• Manual Rendering Mode: This is perfect if you want to process audio files without needing device access:
// Set manual rendering mode
try AudioManager.shared.setManualRenderingMode(true)
// Create a player node hook for file playback
let playerNodeHook = PlayerNodeHook(playerNodeFormat: audioFileFormat)
AudioManager.shared.set(engineObservers: [playerNodeHook])
// Schedule and play the audio file
let audioFile = try AVAudioFile(forReading: fileURL)
await playerNodeHook.playerNode.scheduleFile(audioFile, at: nil)
playerNodeHook.playerNode.play()
These approaches should help you stream audio from files smoothly using the Swift SDK. If you want me to walk you through any part or have more questions, just let me know—I’m here to help!
Sources: Tests/LiveKitTests/AudioMixRecorderTests.swift | Camera & microphone | LiveKit Docs