big-controller-60015
10/07/2025, 7:46 AMtall-airline-16756
10/07/2025, 7:47 AMtall-airline-16756
10/07/2025, 7:47 AMRoomInputOptions like this:
room_input_options=RoomInputOptions(
noise_cancellation=noise_cancellation.BVC(),
)
Agent-Side Echo Cancellation: This one’s really important too! It stops the agent from picking up its own audio output, which can cause echo. Even if you’re using BVC, echo cancellation is still essential. It’s built right into WebRTC through the echoCancellation setting in AudioCaptureOptions, and some SDKs have it enabled by default. For example, in the Rust SDK, you can set it up like this:
let apm = AudioProcessingModule::new(
echo_cancellation, // enabled via args
auto_gain_control,
false,
noise_suppression,
);
For the best audio experience, I recommend turning on both BVC and echo cancellation. This combination really helps keep your audio clean and free from any unwanted noise or interference.
Sources: Operational Guidance & Best Practices | livekit/livekit_composite | DeepWik... | Noise & echo cancellation | LiveKit Docs | Sources/LiveKit/Types/Options/AudioCaptureOptions.swift | examples/local_audio/src/main.rs | SIP troubleshooting guide | LiveKit Docsbig-controller-60015
10/07/2025, 7:55 AMtall-airline-16756
10/07/2025, 7:56 AMAudioProcessingModule for custom audio processing or simply relying on LiveKit's built-in client-side echo cancellation. Let me walk you through both!
1. Using `AudioProcessingModule`:
from livekit.rtc import AudioProcessingModule
# Enable echo cancellation
apm = AudioProcessingModule(echo_cancellation=True)
# Process far-end audio (reverse stream)
apm.process_reverse_stream(far_end_audio_frame)
# Process near-end audio (forward stream)
apm.process_stream(microphone_audio_frame)
# Set delay between reverse and forward stream processing
apm.set_stream_delay_ms(delay_ms=50) # Adjust based on your system
Just a quick tip: make sure your audio frames are exactly 10ms long for the best results.
2. Client-Side Echo Cancellation:
LiveKit’s default audio processing already includes echo cancellation using WebRTC’s echoCancellation setting. This is turned on by default and continues to work even if you’re using Background Voice Cancellation (BVC).
For most situations, the built-in client-side echo cancellation should do the trick. But if you have any questions or need a hand setting things up, I’m here to help — just let me know!
Sources: examples/local_audio/src/main.rs | Operational Guidance & Best Practices | livekit/livekit_composite | DeepWik... | rag/main.py | livekit-agents/livekit/agents/voice/chat_cli.py | livekit-rtc/livekit/rtc/_proto/audio_frame_pb2.pyibillowy-lawyer-17667
10/30/2025, 8:45 AMtall-airline-16756
10/30/2025, 8:47 AMAgentSession in LiveKit, you have two great options to choose from:
1. Enhanced Noise Cancellation (Recommended):
I suggest using LiveKit's enhanced noise cancellation with Background Voice Cancellation (BVC), which also includes echo cancellation:
from livekit.rtc import BackgroundVoiceCancellation
await session.start({
agent,
room: ctx.room,
inputOptions: {
noiseCancellation: BackgroundVoiceCancellation(),
},
});
This method applies enhanced noise and echo cancellation to inbound audio processing and is especially optimized for voice AI applications. It’s straightforward and effective!
2. Direct AudioProcessingModule Integration (Advanced):
If you’re working on more advanced scenarios, you can integrate AudioProcessingModule directly at the audio frame level like this:
from livekit.rtc import apm, AudioFrame
# Initialize APM with echo cancellation
audio_processor = apm.AudioProcessingModule(
echo_cancellation=True,
noise_suppression=True,
high_pass_filter=True,
auto_gain_control=True
)
# Process reverse stream (far-end audio played to user)
audio_processor.process_reverse_stream(render_frame)
# Process forward stream (mic input from user)
audio_processor.process_stream(capture_frame)
# Set delay in milliseconds for accurate echo cancellation
audio_processor.set_stream_delay_ms(delay_ms)
Just a quick tip: make sure your audio frames are exactly 10ms long and that you process the reverse stream before the forward stream for the best results.
Recommendation: For most situations, I’d recommend going with the enhanced noise cancellation using inputOptions because it’s simpler and delivers great performance. If you have any questions or need a hand with this, please don’t hesitate to reach out—I’m here to help!
Sources: Noise & echo cancellation | LiveKit docs | examples/src/basic_agent.ts | livekit-rtc/tests/test_apm.py | stream_audio.py | Enhanced noise cancellation | LiveKit docsbillowy-lawyer-17667
10/30/2025, 8:47 AMtall-airline-16756
10/30/2025, 8:48 AMAudioProcessingModule isn’t directly built to plug into an AgentSession in LiveKit. The AgentSession actually handles the whole audio processing pipeline for you, including STT, TTS, and VAD, and even supports noise cancellation through inputOptions like BackgroundVoiceCancellation.
If you’re looking for more advanced audio processing with AudioProcessingModule, it would need to be applied to the raw audio data outside of the AgentSession pipeline. I’m here to help if you’d like some guidance on how to use AudioProcessingModule on its own or explore other options that might fit your needs better. Just let me know!
Sources: webrtc-sys/include/livekit/apm.h | examples/src/basic_agent.ts | livekit-agents/livekit/agents/voice/agent_session.py | Node.js Agents Architecture | livekit/livekit_composite | DeepWiki | krisp-minimal/README.mdbillowy-lawyer-17667
10/30/2025, 8:49 AMtall-airline-16756
10/30/2025, 8:51 AMAudioProcessingModule, and then send it back to the AgentSession. Let me walk you through two friendly approaches:
1. Using `AudioProcessingModule`:
You can process audio frames before sending them to the session like this:
from livekit.rtc import AudioProcessingModule
# Initialize APM with echo cancellation
audio_processor = AudioProcessingModule(
echo_cancellation=True,
noise_suppression=True,
high_pass_filter=True,
auto_gain_control=True
)
# Process audio frames
processed_frame = audio_processor.process_stream(input_frame)
Just a quick tip: make sure your audio frames are exactly 10ms long. Also, if you want full-duplex echo cancellation, remember to use process_reverse_stream() for the far-end audio.
2. Overriding `realtime_audio_output_node`:
This approach lets you intercept and process audio output directly in the agent pipeline:
async def realtime_audio_output_node(self, audio, model_settings):
async for frame in audio:
processed_frame = self._process_audio(frame)
yield processed_frame
def _process_audio(self, frame):
# Apply custom processing to the frame
return frame
This way, you can apply any custom transformations you need before sending the audio back to the session.
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 | examples/voice_agents/speedup_output_audio.py | realtime/openai-realtime-pitch-shift.py | Capturing the First Few Seconds of a Call for Processingbillowy-lawyer-17667
10/30/2025, 8:54 AMtall-airline-16756
10/30/2025, 8:54 AM