I want to add noise cancellation for background no...
# ask-ai
r
I want to add noise cancellation for background noise in our voice ai agent which is in gemini v2v how we can do this
t
Thanks for reaching out, Abhisek. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m happy to help you add noise cancellation to your Gemini V2V voice agent. To give the right steps, I want to confirm one thing first: Do your users connect to your agent via WebRTC (browser or app) or via SIP/telephony (PSTN, softphone)? Or do you have a mix of both? Why I ask: LiveKit provides two noise-cancellation plugins and the recommended one depends on participant type: • Use BVC for WebRTC (full-bandwidth audio). • Use BVCTelephony for SIP/telephony (narrowband/telephony audio). If you’re using WebRTC (short answer): 1. Install the noise cancellation plugin: ◦
uv add "livekit-plugins-noise-cancellation~=0.2"
1. In your agent session, set the audio input noise filter to
BVC()
when starting the room/session so audio is cleaned before STT -> Gemini ingestion. 2. Ensure you do not also enable other upstream noise suppression (e.g., krisp on the SIP trunk) to avoid double processing. If you’re using SIP/telephony (short answer): 1. Install the same plugin as above. 2. Use
BVCTelephony()
for audio input options so the filter is appropriate for telephony audio. 3. Disable any telephony-side noise suppression (krisp) to avoid double suppression. If you have a mixed environment: • Dynamically choose the filter per participant: use
BVC()
for WebRTC participants and
BVCTelephony()
for SIP participants when you configure `room_options`/`audio_input` for each session. What I can provide next once you confirm: • A short copy-paste code snippet in your language (Python/Node) showing exactly where to set
BVC()
or
BVCTelephony()
in the agent start flow. • Guidance on testing/validation (how to verify the noise cancellation is improving STT quality for Gemini). • Troubleshooting tips if you notice artifacts or doubled suppression. Which connection type are you using (WebRTC, SIP, or both)? Also tell me which language/runtime your agent runs in (Python or Node) and I’ll give the exact snippet you can drop into your code. Sources: Choosing the right noise cancellation for your agent | LiveKit | Google AI and LiveKit | LiveKit Documentation | sip | livekit/livekit_composite | DeepWiki | Turns overview | LiveKit Documentation
r
i want for both
t
Great — since you want noise cancellation for both WebRTC and SIP participants, here’s a concise, practical plan plus ready-to-use code snippets (Python and Node) to apply the correct filter per participant and avoid double-processing. Summary of what to do • Install the noise cancellation plugin: it includes BVC (for WebRTC) and BVCTelephony (for SIP). • When a participant joins, detect whether they’re WebRTC or SIP and apply: ◦
BVC()
for WebRTC participants (full-bandwidth). ◦
BVCTelephony()
for SIP/telephony participants (narrowband). • Disable any other noise-suppression on the SIP trunk (e.g., krisp) to avoid double suppression artifacts. • Test and tune on representative calls to verify STT/Gemini quality. Installation • Add the plugin package: ◦ uv (uVenv) command:
Copy code
uv add "livekit-plugins-noise-cancellation~=0.2"
Python example • This shows dynamically selecting the right filter per participant when starting the agent session:
Copy code
from livekit import rtc
from livekit.agents import AgentSession, room_io
from livekit.plugins import noise_cancellation

# inside your session setup / participant join handler
participant = await ctx.wait_for_participant()  # wait for participant to join

# choose filter by participant kind
filter = (
    noise_cancellation.BVCTelephony()
    if participant.kind == rtc.ParticipantKind.PARTICIPANT_KIND_SIP
    else noise_cancellation.BVC()
)

await session.start(
    room=ctx.room,
    agent=Assistant(),
    room_options=room_io.RoomOptions(
        audio_input=room_io.AudioInputOptions(noise_cancellation=filter)
    ),
)
Node (JavaScript / TypeScript) example • Equivalent logic for Node agents:
Copy code
const { rtc } = require("livekit");
const { AgentSession, room_io } = require("livekit/agents");
const { noise_cancellation } = require("livekit-plugins-noise-cancellation");

// inside your participant join handler
const participant = await ctx.waitForParticipant();

const filter =
  participant.kind === rtc.ParticipantKind.PARTICIPANT_KIND_SIP
    ? new noise_cancellation.BVCTelephony()
    : new noise_cancellation.BVC();

await session.start({
  room: ctx.room,
  agent: new Assistant(),
  roomOptions: new room_io.RoomOptions({
    audioInput: new room_io.AudioInputOptions({ noiseCancellation: filter }),
  }),
});
Key tuning & testing tips • Test with noisy backgrounds representative of your users: music, café noise, overlapping voices. • Verify STT input to Gemini: confirm lower error rates, fewer false triggers, and clearer transcription. • If you hear artifacts (pumping/warbling), ensure SIP trunk-side noise suppression (krisp) is disabled — double suppression causes artifacts. • If you still see issues on specific devices or networks, capture short audio samples from those cases and compare processed vs unprocessed audio to identify problems. What I can provide next • A drop-in example for your exact agent repo or framework if you paste the relevant start/session code. • A short checklist for validating STT/Gemini quality after enabling the filters. • Troubleshooting steps and logs to collect if you see artifacts after enabling filters. Would you like the drop-in snippet adapted to a specific file in your codebase or the validation checklist next?
r
give me for pyhton
t
Thanks — below is a focused, ready-to-drop-in Python example that applies the correct noise cancellation filter for both WebRTC and SIP participants, plus install steps and quick testing tips. Installation 1. Add the noise cancellation plugin:
Copy code
uv add "livekit-plugins-noise-cancellation~=0.2"
Drop-in Python example • Place this in your agent session/participant handler where you start the agent session. It chooses
BVC()
for WebRTC participants and
BVCTelephony()
for SIP participants, then starts the session with the selected filter.
Copy code
from livekit import rtc
from livekit.agents import AgentSession, room_io
from livekit.plugins import noise_cancellation

class Assistant:
    # Your assistant implementation here
    pass

async def handle_participant(ctx, session: AgentSession):
    """
    ctx: context provided by your agent runtime that includes the room and participant events
    session: your AgentSession instance
    """
    # Wait for a participant to join (example API - adapt to your runtime)
    participant = await ctx.wait_for_participant()

    # Select the appropriate noise cancellation filter
    nc_filter = (
        noise_cancellation.BVCTelephony()
        if participant.kind == rtc.ParticipantKind.PARTICIPANT_KIND_SIP
        else noise_cancellation.BVC()
    )

    # Start the agent session with the chosen noise cancellation filter applied to audio input
    await session.start(
        room=ctx.room,
        agent=Assistant(),
        room_options=room_io.RoomOptions(
            audio_input=room_io.AudioInputOptions(noise_cancellation=nc_filter)
        ),
    )
Notes and best practices • Use
BVC()
for WebRTC (full-band audio) and
BVCTelephony()
for SIP (narrowband telephony). • Disable upstream SIP/trunk-side noise suppression (e.g., krisp) to avoid double-processing and artifacts. • Noise cancellation runs with very low latency (<10ms) and filters audio before STT/Gemini ingestion to improve transcription quality. • If you hear artifacts (warbling or pumping), check for double suppression and test with different background noises. Quick validation checklist • Record short samples of noisy inputs (café noise, music, overlapping voices) with and without the filter enabled. • Compare STT/transcription accuracy and error rates sent to Gemini. • Confirm no audible artifacts; if artifacts appear, ensure SIP-side suppression is disabled and re-test. If you want, I can adapt this snippet to the exact file structure of your project — paste the relevant start/session code or the function where you handle participants and I’ll give a drop-in edit.