0

设备之间正在建立对等连接,并且任何一方的人都能够进行通信。任何一个或两个设备都使用EARPIECE时不会出现任何问题。

当两个设备都使用EARPHONESINBUILT_SPEAKER进行音频通信时,就会出现问题。

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

我已经尝试过以下选项

选项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"));

选项-2

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

请帮我弄清楚缺少什么。我怎样才能消除或减少这种回声?

4

1 回答 1

1

以下两个步骤解决了这个问题。

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 的噪声抑制器和回声消除器

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 );
    }
于 2020-10-17T10:12:20.823 回答