steep-balloon-41261
11/01/2025, 6:56 PMtall-airline-16756
11/01/2025, 6:56 PMtall-airline-16756
11/01/2025, 6:57 PMRoomInputOptions with audio_num_channels=2 to enable stereo input. Here’s a quick example:
from livekit.agents.voice.room_io import RoomInputOptions
input_options = RoomInputOptions(
audio_num_channels=2, # Enable stereo input
audio_sample_rate=24000
)
1. Configure Output Options: Next, set up RoomOutputOptions for dual-channel output in a similar way. Here’s how you can do it:
from livekit.agents.voice.room_io import RoomOutputOptions
output_options = RoomOutputOptions(
audio_num_channels=2, # Enable stereo output
audio_sample_rate=24000
)
1. Audio Mixing: Finally, use the AudioMixing enum to manage how dual-channel audio behaves. For instance, the DualChannelAgent setting separates agent audio into the left channel and other audio into the right channel, which can be really handy.
If you have any questions or need a bit more guidance, please don’t hesitate to reach out—I’m here to help!
Sources: examples/local_audio/src/main.rs | livekit-agents/livekit/agents/voice/recorder_io/recorder_io.py | lib/src/preconnect/pre_connect_audio_buffer.dart | Real-time AI Models & Streaming | livekit/livekit_composite | DeepWikitall-airline-16756
11/01/2025, 7:07 PMValueError: Channel count mismatch: expected 1, got 2 because the system is expecting mono (1-channel) audio, but it's receiving stereo (2-channel) audio instead. No worries—let’s walk through how you can fix this together:
1. Resample Stereo to Mono: You can use the AudioResampler to convert your stereo audio into mono before processing it. Here’s a simple example to guide you:
from livekit.rtc import AudioResampler
resampler = AudioResampler(
input_rate=48000,
output_rate=16000,
num_channels=1 # Downmix to mono
)
resampled_frames = resampler.push(stereo_audio_frame)
1. Normalize Audio Frames: It’s important to make sure all your audio data is normalized to mono before you combine frames or send them to AI services. Here’s how you might do that:
from livekit.agents.voice.audio_utils import AudioByteStream
bstream = AudioByteStream(
sample_rate=16000, # 16kHz
num_channels=1, # Mono
samples_per_channel=800 # 50ms at 16kHz
)
1. Validate Channel Count: A quick check on the channel count of incoming audio frames can save you from surprises. If needed, downmix them before moving forward with processing.
If you’d like, I’m here to help you implement these steps or answer any other questions you might have. Just let me know!
Sources: livekit-rtc/livekit/rtc/utils.py | livekit-plugins/livekit-plugins-google/livekit/plugins/google/realtime/real... | livekit-protocol/src/livekit.rs | AI Agents Framework | livekit/livekit_composite | DeepWiki