Hi team I’m running the official `@livekit/react-...
# ask-ai
f
Hi team I’m running the official
@livekit/react-native
example app on two physical Android devices (Pixel 6a and Pixel 7 Pro). Issue: When using speaker mode, I’m getting audio echo/feedback — the remote participant can hear their own voice played back. In earpiece mode, there’s no echo — works perfectly. Things I’ve done: - Using
AudioSession.configureAudio()
with
AndroidAudioTypePresets.communication
- Using default settings from the SDK example app - Not modifying or managing audio focus manually What I need: How can I avoid or cancel echo when in speaker mode on Android? Any advice for handling echo on Pixel devices using the React Native SDK would be appreciated. Thanks!
t
Thanks for reaching out, Rahul. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To help reduce audio echo or feedback when using speaker mode with the
@livekit/react-native
SDK on Android devices, here are some friendly steps you can follow: 1. Set Up the Audio Session: Try using
AudioSession.configureAudio
with the right settings for speaker mode. For example:
Copy code
await AudioSession.configureAudio({
  android: {
    preferredOutputList: ['speaker'],
    audioTypeOptions: {
      manageAudioFocus: true,
      audioMode: 'inCommunication',
      audioFocusMode: 'gain',
      audioStreamType: 'voiceCall',
      audioAttributesUsageType: 'voiceCommunication',
      audioAttributesContentType: 'speech'
    }
  }
});
2. Turn On Echo Cancellation: Make sure the audio mode is set to `inCommunication`—this helps use the built-in echo cancellation features. 3. Take Care of Audio Focus: Setting
manageAudioFocus
to
true
helps manage interruptions smoothly. 4. Choose the Speaker Output: Explicitly switch to the speaker like this:
Copy code
const availableOutputs = await AudioSession.getAudioOutputs();
if (availableOutputs.includes('speaker')) {
  await AudioSession.selectAudioOutput('speaker');
}
5. Start Your Audio Session: Don’t forget to start the audio session before joining the room:
await AudioSession.startAudioSession();
6. Handle Background Noise: If you can, enable background noise cancellation—it really helps cut down on echo. And when you’re done, it’s a good idea to stop the audio session to free up resources:
await AudioSession.stopAudioSession();
Hopefully, these tips make your audio clearer and echo-free! If you run into any issues or want to chat more about this, just let me know—I’m here to help. Sources: docs/types/AndroidAudioTypeOptions.html | SIP troubleshooting guide | LiveKit Docs
f
await startCallService(); // Use the recommended LiveKit preset for voice communication. // This is simpler and ensures all correct settings for AEC are applied. await AudioSession.configureAudio({ android: { preferredOutputList: ['speaker', 'earpiece', 'bluetooth'], audioTypeOptions: AndroidAudioTypePresets.communication, }, }); await AudioSession.startAudioSession(); await AudioSession.selectAudioOutput('speaker'); // Only set isAudioSessionReady to true after everything is configured. setAudioSessionReady(true); }; setupAudio();
Copy code
useEffect(() => {
    const setupAudio = async () => {
      await startCallService();

      // Use the recommended LiveKit preset for voice communication.
      // This is simpler and ensures all correct settings for AEC are applied.
      await AudioSession.configureAudio({
        android: {
          preferredOutputList: ['speaker', 'earpiece', 'bluetooth'],
          audioTypeOptions: AndroidAudioTypePresets.communication,
        },
      });

      await AudioSession.startAudioSession();
      await AudioSession.selectAudioOutput('speaker');

      // Only set isAudioSessionReady to true after everything is configured.
      setAudioSessionReady(true);
    };

    setupAudio();

    // Cleanup function
    return () => {
      stopCallService();
      AudioSession.stopAudioSession();
    };
  }, []); 

this is what i was doing
t
Using
AndroidAudioTypePresets.communication
is a great way to make sure echo cancellation is turned on by default. It sets up the audio session specifically for two-way communication with voice-friendly settings. Here’s what it does: • Sets
audioMode
to
inCommunication
, which helps enable echo cancellation. • Uses
MediaRecorder.AudioSource.VOICE_COMMUNICATION
, designed to capture audio with echo cancellation in mind. That said, while this setup is meant to handle echo cancellation, the docs don’t clearly say if echo cancellation stays active when using speaker mode. If you still notice echo, it might be due to the specific device or the environment you’re in. Trying it out on other devices or tweaking things like lowering the speaker volume could make a difference. Feel free to reach out if you want more help or some extra troubleshooting tips—I’m here to help! Sources: android/src/main/java/com/livekit/reactnative/audio/AudioSwitchManager.java | livekit-android-sdk/src/main/java/io/livekit/android/dagger/RTCModule.kt
f
still facing issue and this is happening when second speaker is unmuting that causes Crackling sound when remote participant unmutes
t
Hey there! If you’re hearing crackling when a remote participant unmutes, here are some friendly tips to help smooth things out: 1. Enable Noise Cancellation: Try using the Krisp noise filter package for React Native. You can add it easily with: `npm install @livekit/react-native-krisp-noise-filter`or `yarn add @livekit/react-native-krisp-noise-filter`Then, just enable it in your
LiveKitProvider
like this:
<LiveKitProvider token="your-token" serverUrl="wss://your-livekit-server" krisp={true}>
2. Handle Mute/Unmute Events: It’s helpful to listen for
TrackMuted
and
TrackUnmuted
events so your UI and audio stay in sync:
Copy code
const microphoneTracks = useTracks([Track.Source.Microphone], {
  updateOnlyOn: [
    RoomEvent.TrackSubscribed,
    RoomEvent.TrackUnsubscribed,
    RoomEvent.TrackMuted,
    RoomEvent.TrackUnmuted,
  ],
  onlySubscribed: true,
});
3. Check Audio Configuration: Make sure your audio session is set up with the right modes and presets for communication — that can really help clear things up. 4. Enable Redundant Encoding (RED): Keep RED enabled (it’s on by default) to boost audio quality, especially if the network gets a bit shaky. Give these a try, and hopefully that crackling will calm down. If you hit any bumps or want to chat more about it, just let me know—I’m here to help!
f
but audio feedback not solvable by livekit sdk ?
t
Hey there! The LiveKit SDK does a great job minimizing audio feedback by setting up the audio session for communication mode and using a built-in workaround to keep the audio mode just right. That said, it doesn’t have a specific feature dedicated solely to fixing audio feedback when you’re in speaker mode. Here’s what you can do to tackle this: 1. Configure the Audio Session: Try using the communication preset to get the best audio settings:
Copy code
await AudioSession.configureAudio({
  android: {
    audioTypeOptions: AndroidAudioTypePresets.communication
  }
});
await AudioSession.startAudioSession();
2. Enable Speakerphone: If you need to, you can explicitly turn on the speakerphone output like this:
Hardware.instance.setSpeakerphoneOn(true);
Just a heads-up—the SDK plays a silent audio track behind the scenes to keep communication mode active and help prevent feedback. This is on by default, but you can turn it off if it’s not needed. If you’re still running into feedback issues, it might be due to specific quirks with your device or the environment you’re in. Feel free to reach out if you want to dig deeper or need a hand! Sources: livekit-android-sdk/src/main/java/io/livekit/android/dagger/RTCModule.kt