简体   繁体   English

使用WebRTC Android回音

[英]Echo in sound with WebRTC Android

I am doing live stream between two Android devices with WebRTC. 我正在使用WebRTC在两个Android设备之间进行实时直播。 Sometimes, with some users, there is echo in sound. 有时,对于某些用户,声音中会出现回声。 I use hands-free (speaker) on both end. 我在两端都使用免提(扬声器)。

So how can I remove the echo? 那么如何删除回声? Maybe I did something wrong in my code? 也许我在代码中做错了什么?

I would first try to check if the echo is also there when using WhatsApp. 我首先尝试在使用WhatsApp时检查回声是否也存在。 If it is, the echo is related to the device and probably difficult to fix. 如果是这样,则回声与设备有关,可能很难修复。

If not, it could be related to the audio mode. 如果不是,则可能与音频模式有关。 Make sure to set the audio mode to MODE_IN_COMMUNICATION when the call is established: 建立呼叫后,请确保将音频模式设置为MODE_IN_COMMUNICATION

AudioManager am = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
am.setMode(AudioManager.MODE_IN_COMMUNICATION);

Try to use: 尝试使用:

if (!isSpeakerphoneOn)
{
    audioManager.abandonAudioFocus(null);
    audioManager.setMode(AudioManager.MODE_NORMAL);
    audioManager.setSpeakerphoneOn(false);
} 
else
{
    audioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN);
    audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
    audioManager.setSpeakerphoneOn(true);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM