I’m running into an issue with echo cancellation i...
# ask-ai
h
I’m running into an issue with echo cancellation in a chat app built on LiveKit’s WebRTC stack. When AEC is enabled and users are not wearing headphones, the microphone input gets heavily suppressed whenever it overlaps with AI-generated audio output from the speakers. At lower playback volumes, some overlap remains audible, but as volume increases, the mic signal is almost completely muted. Is there a way to adjust AEC parameters or configure LiveKit/WebRTC to reduce this over-suppression while still maintaining effective echo cancellation?
t
Thanks for reaching out, Nivedha. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I understand how tricky microphone suppression caused by speaker output can be when using echo cancellation (AEC) in LiveKit. Let’s walk through some adjustments that might help improve your experience: • Stream Delay: It’s really important to set the delay between speaker output and microphone input accurately using
set_stream_delay_ms()
. This helps the echo cancellation work well without suppressing your microphone too much. • Noise Suppression: Sometimes, reducing or even disabling noise suppression can make a big difference if it’s causing too much suppression of your microphone signal. • Audio Processing Module (APM): The APM is a great tool to configure echo cancellation, noise suppression, auto gain control, and high-pass filtering. For example:
Copy code
apm = rtc.AudioProcessingModule(
    echo_cancellation=True,
    noise_suppression=False,  # Disable if causing suppression
    high_pass_filter=True,
    auto_gain_control=True
)
• Frame Processing: Make sure audio frames are processed properly, with the reverse stream (speaker output) handled before the forward stream (microphone input). Trying out different combinations of these settings and making sure the delay is estimated correctly can really help reduce suppression while keeping echo cancellation effective. If you’d like, I’m here to provide more details or examples to guide you through the implementation. Just let me know! Sources: webrtc-sys/include/livekit/audio_device.h | SIP troubleshooting guide | LiveKit Docs | README.md | Noise & echo cancellation | LiveKit docs | livekit-rtc/livekit/rtc/apm.py
h
May I know if this is different from the browser level AEC?
t
Thanks for reaching out! Let me help clarify the difference between browser-level AEC and LiveKit/WebRTC AEC for you. Browser-level AEC is the echo cancellation handled by your browser or operating system, often using hardware acceleration or system-level features (like Apple’s Voice-Processing I/O on iOS). This usually comes enabled by default and works independently of WebRTC. On the other hand, LiveKit/WebRTC AEC is a software-based solution that gives you more detailed control through SDK settings. For instance, you can turn WebRTC’s AEC on or off using options such as
AudioCaptureOptions
or media constraints like
googEchoCancellation
. The main thing to keep in mind is that browser-level AEC depends on your platform’s built-in settings, while LiveKit/WebRTC AEC lets you customize echo cancellation within the WebRTC framework. If you'd like, I’m here to guide you through setting up either option to best fit your needs—just let me know! Sources: Sources/LiveKit/Types/Options/AudioCaptureOptions.swift | lib/src/track/options.dart | webrtc-sys/include/livekit/audio_device.h | components/esp_capture/include/esp_capture_defaults.h
h
what is the difference in AudioProcessingModule, AudioCaptureOptions and browser AEC
t
Thank you for reaching out! Let me walk you through the differences between AudioProcessingModule, AudioCaptureOptions, and browser-level AEC so it’s a bit clearer: • AudioProcessingModule (APM): Think of this as the heart of WebRTC’s software-based audio processing. It offers detailed control over features like echo cancellation and noise suppression. It does require some careful setup, like configuring stream delays, because it works directly with audio frames to give you complete control. • AudioCaptureOptions: This is a handy configuration tool within LiveKit SDKs. It lets you easily turn WebRTC’s software audio processing features on or off, such as echo cancellation and noise suppression, acting like a simple switch when you’re publishing tracks. • Browser-Level AEC: This is the echo cancellation built right into your browser or operating system, like Apple’s Voice-Processing I/O. It’s optimized for your hardware, usually turned on by default, and works separately from WebRTC’s software-based AEC unless you decide to override it. To sum it up, AudioCaptureOptions is what you use to configure WebRTC’s software echo cancellation through APM, while browser-level AEC is the automatic, platform-specific echo cancellation your system provides. If you’d like, I’m here to help with more details or examples—just let me know! Sources: livekit-rtc/livekit/rtc/apm.py | livekit-ffi/src/server/requests.rs | stream_audio.py | Tests/LiveKitAudioTests/AudioProcessingTests.swift | Noise & echo cancellation | LiveKit docs
h
Which is recommended? Can I use both browser AEC and AudioProcessingModule at the same time
t
I totally understand how managing audio settings can feel a bit tricky! It’s generally best not to use both browser-level AEC and the AudioProcessingModule at the same time, as they might interfere with each other and affect your audio quality. Usually, the browser-level AEC is on by default and tailored to work well with your platform, while the AudioProcessingModule gives you more detailed control over WebRTC’s audio processing. If you decide to go with the AudioProcessingModule, it’s a good idea to turn off the browser-level AEC to prevent any overlap. You can usually do this by setting media constraints like
echoCancellation: false
when you access the microphone with
getUserMedia()
. Here’s a quick guide to help you choose what might work best for you: • Browser-level AEC: Great if you want a simple setup and the built-in platform processing meets your needs. • AudioProcessingModule: Perfect if you need more advanced control over how audio is processed. If you’d like, I’m here to help you set up either option or answer any questions you have! Sources: livekit-ffi/src/server/requests.rs | livekit-rtc/livekit/rtc/apm.py | stream_audio.py