简体   繁体   English

连接耳机时,WebRTC android 应用程序正在创建回声

[英]WebRTC android application is creating echo when earphones are connected

Peer connection is getting established between devices and people on either side are able to have communication.设备之间正在建立对等连接,两边的人都可以进行通信。 No issue is happening when the EARPIECE is used by anyone or both of the devices.当任何人或两个设备都使用EARPIECE时,不会发生任何问题。

Problem is occurring when EARPHONES or INBUILT_SPEAKER is used for audio communication by both devices.当两个设备都使用EARPHONESINBUILT_SPEAKER进行音频通信时,就会出现问题。

Dependency: 'org.webrtc:google-webrtc:1.0.30039'依赖: 'org.webrtc:google-webrtc:1.0.30039'

I have already tried the below options我已经尝试过以下选项

OPTION-1选项1

audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googEchoCancellation", "true"));
audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googEchoCancellation2", "true"));
audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googDAEchoCancellation", "true"));
audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googTypingNoiseDetection", "true"));
audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googAutoGainControl", "true"));
audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googAutoGainControl2", "true"));
audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googNoiseSuppression", "true"));
audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googNoiseSuppression2", "true"));
audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googAudioMirroring", "false"));
audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googHighpassFilter", "true"));

OPTION-2选项 2

JavaAudioDeviceModule.builder ( mContext )
                .setUseHardwareAcousticEchoCanceler(false)
                .setUseHardwareNoiseSuppressor(false)
                .createAudioDeviceModule ();
WebRtcAudioUtils.setWebRtcBasedNoiseSuppressor ( true );
WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler ( true );
WebRtcAudioUtils.setWebRtcBasedAutomaticGainControl ( true );

Kindly help me figure out what is missing.请帮我弄清楚缺少什么。 How can I eliminate or reduce this echo?我怎样才能消除或减少这种回声?

The following two steps solved the issue.以下两个步骤解决了这个问题。

AudioDeviceModule was added to PeerConnectionFactory. AudioDeviceModule 已添加到 PeerConnectionFactory。

private PeerConnectionFactory createPeerConnectionFactory () {
        AudioDeviceModule audioDeviceModule = JavaAudioDeviceModule.builder ( mContext )
                .setUseHardwareAcousticEchoCanceler ( false )
                .setUseHardwareNoiseSuppressor ( false )
                .createAudioDeviceModule ();
        PeerConnectionFactory.InitializationOptions initializationOptions = PeerConnectionFactory.InitializationOptions.builder ( mContext )
                .createInitializationOptions ();
        PeerConnectionFactory.initialize ( initializationOptions );
        peerConnectionFactory = PeerConnectionFactory.builder ()
                .setAudioDeviceModule ( audioDeviceModule )
                .createPeerConnectionFactory ();
        return peerConnectionFactory;
    }

WebRTC based noise suppressor and echo canceller were enabled while creating audio stream创建音频流时启用了基于 WebRTC 的噪声抑制器和回声消除器

private void createLocalStream () {
        WebRtcAudioUtils.setWebRtcBasedNoiseSuppressor ( true );
        WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler ( true );
        WebRtcAudioUtils.setWebRtcBasedAutomaticGainControl ( true );
        MediaConstraints localMediaConstraints = new MediaConstraints ();
        AudioSource localAudioSource = peerConnectionFactory.createAudioSource ( localMediaConstraints );
        localTrack = peerConnectionFactory.createAudioTrack ( LOCAL_AUDIO_TRACK, localAudioSource );
        localTrack.setEnabled ( true );
        localMediaStream = peerConnectionFactory.createLocalMediaStream ( LOCAL_STREAM );
        localMediaStream.addTrack ( localTrack );
        peerConnection.addStream ( localMediaStream );
    }

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

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