flat-diamond-66151
08/14/2025, 3:18 PM@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!tall-airline-16756
08/14/2025, 3:18 PMtall-airline-16756
08/14/2025, 3:18 PM@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:
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:
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 Docsflat-diamond-66151
08/14/2025, 3:20 PMflat-diamond-66151
08/14/2025, 3:20 PMuseEffect(() => {
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
tall-airline-16756
08/14/2025, 3:22 PMAndroidAudioTypePresets.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.ktflat-diamond-66151
08/14/2025, 3:31 PMtall-airline-16756
08/14/2025, 3:32 PMLiveKitProvider
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:
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!flat-diamond-66151
08/14/2025, 3:39 PMtall-airline-16756
08/14/2025, 3:39 PMawait 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