in JS SDK.. where should be noise cancellation app...
# ask-ai
c
in JS SDK.. where should be noise cancellation apply.. before publishing the track or after ?
t
Thanks for reaching out, shahi. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! When you're using the LiveKit JS SDK, it's best to apply noise cancellation before you publish the track. More specifically, you want to do this on the
LocalAudioTrack
either just before or right as you publish it. Here’s a handy example: you can set up the noise cancellation filter when you catch the
RoomEvent.LocalTrackPublished
event, which happens right after the track is published:
Copy code
room.on(RoomEvent.LocalTrackPublished, async (trackPublication) => {
  if (trackPublication.source === Track.Source.Microphone && 
      trackPublication.track instanceof LocalAudioTrack) {
    
    const krispProcessor = KrispNoiseFilter();
    await trackPublication.track.setProcessor(krispProcessor);
    await krispProcessor.setEnabled(true);
  }
});
This way, your noise cancellation will be up and running for the entire time the track is being used in your session. Pretty neat, right? Sources: components/room.tsx | Enhanced noise cancellation | LiveKit Docs
c
but its not working
t
Hey there! If you’re having trouble with noise cancellation not working in the LiveKit JS SDK, let’s walk through a few things together: 1. Browser Support: First, double-check if your browser supports the Krisp noise filter. You can use
isKrispNoiseFilterSupported()
to see if it’s compatible. Here’s a quick example:
Copy code
import { isKrispNoiseFilterSupported } from '@livekit/krisp-noise-filter';

if (!isKrispNoiseFilterSupported()) {
  console.warn('Krisp noise filter is not supported in this browser');
}
1. Proper Initialization: Make sure the
KrispNoiseFilter
is set up correctly and applied to your
LocalAudioTrack
right after it’s published. Check out this snippet:
Copy code
room.on(RoomEvent.LocalTrackPublished, async (trackPublication) => {
  if (trackPublication.track instanceof LocalAudioTrack) {
    const krispProcessor = KrispNoiseFilter();
    await trackPublication.track.setProcessor(krispProcessor);
    await krispProcessor.setEnabled(true);
  }
});
1. Deployment: Just a heads-up, enhanced noise cancellation with Krisp is available only on LiveKit Cloud, not on self-hosted setups. 2. Conflicts: Try to avoid turning on both client-side and server-side noise cancellation at the same time to prevent issues. 3. Track Status: You can check if noise cancellation is active by keeping an eye on the
enhancedNoiseCancellation
property of your
LocalAudioTrack
. If any of this feels unclear or you want me to help you step-by-step, just let me know—I’m here to help! Sources: Enhanced noise cancellation | LiveKit Docs | AI noise cancellation | LiveKit Docs | src/room/track/LocalAudioTrack.ts | Speech & Audio Processing | livekit/livekit_composite | DeepWiki | Understanding "silence detected on local audio track" warning
c
Can custom denoise processors also works in the same way?
t
Hey there! You can definitely use custom denoise processors just like the
KrispNoiseFilter
in the LiveKit JS SDK. The SDK lets you plug in your own audio processors using the
setProcessor
method on
LocalAudioTrack
, so you have full control to add your own audio processing magic. Here’s a quick example to show you how to apply a custom processor:
Copy code
room.on(RoomEvent.LocalTrackPublished, async (trackPublication) => {
  if (trackPublication.track instanceof LocalAudioTrack) {
    // Apply your custom processor
    await trackPublication.track.setProcessor(customProcessor);
  }
});
Just a heads up: while the way you integrate is the same, custom processors can’t fully replicate the proprietary Krisp models or some of the advanced features like Background Voice Cancellation (BVC) — those are only available server-side in Python or Node.js. If you have any specific ideas or features you want to build with your custom processor, feel free to share! I’d be happy to help you figure out the best way to make it happen. Sources: Enhanced noise cancellation | LiveKit Docs | src/room/track/LocalAudioTrack.ts | components/room.tsx | components/room.tsx | Sources/LiveKit/Protocols/AudioCustomProcessingDelegate.swift