Is it possible to stream stereo audio in the swift...
# ask-ai
j
Is it possible to stream stereo audio in the swift sdk from a macos app to a reciever in a chrome browser
t
Thanks for reaching out, Scott. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Yes — you can stream stereo audio from a macOS app using the Swift SDK to a receiver in Chrome. What to do: 1. Create/publish an audio track with two channels, for example:
Copy code
let audioTrack = try LocalAudioTrack.createTrack(
    options: AudioCaptureOptions(channelCount: 2)
)
1. The SDK uses Opus (WebRTC) which supports stereo; Chrome (WebRTC) will decode and play the stereo stream. If you want, tell me how you’re capturing audio on macOS (AVAudioEngine, external device, file) and I’ll suggest the exact capture/output settings to ensure true stereo is preserved. Sources: client-sdk-js | livekit/livekit_composite | DeepWiki | client-sdk-swift | livekit/livekit_composite | DeepWiki
j
AVAudioEngine
t
Great — since you’re using AVAudioEngine, here's a concise plan to capture and publish true stereo to Chrome. 1) Configure AVAudioEngine for stereo input • Ensure the input node provides a 2-channel format at 48 kHz (Opus-friendly):
Copy code
let engine = AVAudioEngine()
let inputNode = engine.inputNode
let bus = 0
let stereoFormat = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: 48000, channels: 2, interleaved: false)!
inputNode.installTap(onBus: bus, bufferSize: 512, format: stereoFormat) { buffer, when in
    // handle buffer
}
try engine.start()
2) Supply that stereo PCM into the LiveKit track • Create a LocalAudioTrack from your custom source / audio stream capture and feed the stereo PCM buffers. Ensure the track is created without forcing mono and uses 48 kHz channels=2. 3) Ensure system/session settings allow stereo • Verify your macOS audio device supports 2 channels and, if applicable, set preferred channels:
Copy code
let session = AVAudioSession.sharedInstance()
try session.setPreferredInputNumberOfChannels(2)
(Note: AVAudioSession applies to iOS/tvOS; for macOS use AVAudioEngine/AVAudioDevice I/O configurations.) 4) Verify on the receiver (Chrome) • Chrome/WebRTC will decode Opus stereo and should present a stereo MediaStreamTrack if the publisher preserved two channels. Test with a stereo-capable output device and inspect the received track in the Chrome Web Audio API or devtools. If you’d like, I can: • Provide a sample that converts the tapped AVAudioEngine buffers into the exact API call for creating a custom LiveKit audio source, or • Help debug if your current capture ends up mono (share a short snippet of your capture/publish code). Sources: Codecs and more | LiveKit docs | Camera & microphone | LiveKit docs