twilio / video-quickstart-android

Twilio Video Quickstart for Android
MIT License
213 stars 160 forks source link

Echo on some devices #512

Closed bataemperor closed 2 years ago

bataemperor commented 4 years ago

Description

Helo, I'm using Twilio video in my android app. The type of room is peer-to-peer. The version that I'm using is video-android:5.6.0. I have problem with echo on some devices, but not on all of them. I experienced it on Xiaomi MI 8 that I'm using, but other users also reported the same problem on couple of other devices. I previosly had problem with noise and I solved it by following #troubleshooting-audio on your github docs. [Description of the issue]

Steps to Reproduce

Users connect to peer-to-peer room.

Code

I used // Use software AEC WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler(true);

    // Use sofware NS
    WebRtcAudioUtils.setWebRtcBasedNoiseSuppressor(true);

    // Use software AGC
    WebRtcAudioUtils.setWebRtcBasedAutomaticGainControl(true);

It solved the problem with noise, but echo remains on some devices.

Expected Behavior

Not to hear the echo.

Actual Behavior

Can hear echo

Reproduces how Often

Reproduced on some devices

Logs

I attached logs here : https://pastebin.com/WeghcYVy

Versions

All relevant version information for issue.

Video Android SDK

5.6.0

Android API

29

Android Device

Xiaomi MI 8, and couple of other, don't have exact info

aaalaniz commented 4 years ago

Hey @bataemperor

I have a couple follow up questions.

  1. Does the echo occur with specific audio devices? For example, do you only experience echo when using speakerphone, earpiece, or both?
  2. Have you tried using a different audio codec? Your use case calls for P2P rooms. In this topology, you can prefer a specific audio codec. Can you try preferring the iSAC codec? Our Quickstart provides an example of how to prefer specific audio/video codecs.

Thanks

bataemperor commented 4 years ago

Hi @aaalaniz I will answer your questions :

1) I'm experiencing echo with the speaker. I haven't tried with earpiece since it not usable in our app. 2) I tried to change codec as you suggested (iSAC) but heard echo again.

I'm using audioSink from your examples to record both local and remote audio tracks and afterward I'm mixing it together with local video that I record using MediaRecorder. I'm aware of recording API that you provide. I used it but it didn't work for me because video quality wasn't good enough so I had to switch to recording it locally.

aaalaniz commented 4 years ago

Hey @bataemperor

Thanks for the confirmation and additional details. I don't think the audio sink usage should impact the echo cancellation performance. I have a couple of follow ups.

  1. Can you provide a Room SID where you observe the echo? I'd like to investigate the WebRTC stats on our side.
  2. This may be a bit tedious but using the device can you run tests and fill out this table? For simplicity sake, let's say Echo scores are 1 (no echo) and 2 (echo).
WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler WebRtcAudioUtils.setWebRtcBasedNoiseSuppressor WebRtcAudioUtils.setWebRtcBasedAutomaticGainControl Echo Score (1-2)
false false false
false false true
false true false
false true true
true false false
true false true
true true false
true true true
bataemperor commented 4 years ago
  1. I'm sending you room where echo is observed.

    roomName = CCqKgob85tYbMk5nWJR6YdjBB4l2H76fQrdmgGRrdmf8lNKJkZUFfPk1Rec1590278846054 roomSID = RM0d2ba18c81a90da29eabc00adb30691a

  2. I will run this tests and let you know the results.

Thanks

himanshu-my commented 4 years ago

Hey @aaalaniz I am facing the same echo issue. I have execute the above test and is all the cases I am getting echo. My last roomsid is RMe4a90c7d62df5af4b425ece3d4eeebec. I am getting echo on Samsung A20s and participant phone is Pixel 2 XL. Its clear that pixel 2 xl is creating echo for its participants. I have tried every thing which is written here https://github.com/twilio/video-quickstart-android#troubleshooting-audio. Echo is affecting call quality of our customers. Please suggest me something to get rid of this echo issue.

bataemperor commented 4 years ago

HI @aaalaniz . I've run test cases and I'm getting echo in all cases as well. Please let me know if you have some conclusions about WebRTC stats that you mentioned.

aaalaniz commented 4 years ago

Hey everyone,

@himanshu-my if you are experiencing echo on a pixel device, then it is most likely due to OpenSLES. We now disable OpenSLES by default in Video Android 5.6.0, so please sure to use this version or explicitly disable it as stated in the trouble shooting audio guide.

@bataemperor Unfortunately, I think I'm out of leads here. I checked the WebRTC stats and the only thing I found was confirming the echo. I see large spike in audio levels on the server but not a lot of evidence to explain why.

I'll have to order a Xiaomi MI 8 and see what I can do locally. In general, I have seen that the Xiaomi does find interesting corner cases so it will be good to have this device in our inventory.

In the meantime, the only thing I can suggest is to encourage your users to use a headset speaker or wired/bluetooth headset. We now have a convenient library AudioSwitch that helps set up managing these audio devices in a few lines of code for real-time communication applications.

Thank you.

himanshu-my commented 4 years ago

@aaalaniz I am already using latest version which is 5.6.0 in which your have already disabled OpenSLES by default. We are not getting echo only on Pixel but our customers reported that they are getting echo on Samsung devices also and this echo issue is affecting our app quality. Can you please provide any concrete resolution for it?

aaalaniz commented 4 years ago

Hey @himanshu-my

Unfortunately the only thing I can offer is similar to what I recommended to @bataemperor

I suggest you encourage your users to use a headset speaker or wired/bluetooth headset. We now have a convenient library AudioSwitch that helps set up managing these audio devices in a few lines of code for real-time communication applications.

I ordered the Xiaomi device to try to see what we can do locally. I will provide an update when I have had a change to experiment locally.

Thanks

bataemperor commented 4 years ago

Hi @aaalaniz, we did encourage our users to use a headset but some of them reported that echo is still there on some devices. Do you have some resolution for this problem?

aaalaniz commented 4 years ago

Hey @bataemperor

Unfortunately, I have no resolution at this time. We now have the Xiaomi MI 8 device and will be performing some experiments with echo cancellation.

Thank you

diegomichell commented 4 years ago

Any update on this?

JJChill commented 4 years ago

@aaalaniz any update? I'm also experiencing echo when calling to a Pixel 2 device.

metalelf0 commented 4 years ago

Hi @aaalaniz , do you have any update on this issue? I'm facing some very tedious echo when joining video rooms from a Xiaomi MI9 device (with stock MIUI 12).

CaptainJeff commented 4 years ago

Anyone have an update on this? Tried everything with a Pixel 2 and can't seem to get the echo to stop

Saceone commented 4 years ago

Same problem here, Xiaomi Redmi Note 8, no updates yet?

alanbucknum commented 3 years ago

Same issue here with browser, video-quickstart-android, and twilio-video-app-android. When we have two tablets connected, they combine to produce an insane echo, see video here. WeChat did not have the same problem; I can't seem to figure out why.

Code - Tried the WebRTC options to no avail. Otherwise we did not tweak the source code. Reproduces How Often - Tablet to laptop produces mild echo, tablet to tablet calls produce extreme echo. Both occur 100% of the time. Logs - None Video Android SDK - 6.0.0 Android Version - 8.1 Android Device - Hopestar WA1012T. We are happy to ship a tablet for testing if it would help.

timusus commented 3 years ago

@alanbucknum did you make any headway here? We have a similar situation. We're considering implementing custom Acoustic Echo Cancellation / Noise Suppression

alanbucknum commented 3 years ago

@timusus Sorry, we did not. Would love to hear if you have success with the custom method. We tested on some mainstream tablets (e.g. Samsung), which worked great, but ours did not.

Shoshin23 commented 3 years ago

Hello Everyone,

This was also happening to our video calling app on some Samsung devices. After a lot of troubleshooting I realised what the problem is, it something to do with a property that determined which audio settings the app will use. To set this in the VOIP mode, I set the mode property for my AudioManager object to 3(in_call_communication). This fixed the issue.

Here's my snippet of code:

audioManager = applicationContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager
audioManager.isSpeakerphoneOn = true
audioManager.mode = 3;

Hope this helps folks out there struggling with the same issue.

Alton09 commented 3 years ago

Thanks for sharing @Shoshin23 !

Alton09 commented 3 years ago

Also, the AudioSwitch library sets the AudioManager mode to this same value (MODE_IN_COMMUNICATION = 3) when it is activated. We highly recommend using AudioSwitch to provide a better audio device management experience during a real time communication call.

Shoshin23 commented 3 years ago

Thanks @Alton09! I'm taking a look at it so we can implement it within our app. Didn't know this existed. 👍

vismay11 commented 3 years ago

@Shoshin23 @Alton09 by using audioManager.mode = 3 there is no more echo on Samsung devices but it leads to another problem where if the user is using Bluetooth headphones then they aren't able to hear anyone from the Bluetooth earpiece instead the audio is routed to the device's Earpiece. UPDATE: Tested this again on the same device though the in-call echo disappeared the person who is speaking is able to hear the echo.

vismay11 commented 3 years ago

@aaalaniz any update on the echo issue? Facing heavy echo on few Samsung devices.

Device name: Samsung Galaxy F41 & Samsung Galaxy M30s Android version: 11 Twilio Video SDK: 5.12.0

meSmashsta commented 3 years ago

Hey guys! For June 2021, I was able to remove the insane echo sound by setting the mode of the audio like so:

        (getSystemService(Context.AUDIO_SERVICE) as AudioManager).apply {
            isSpeakerphoneOn = true
            mode = AudioManager.MODE_IN_COMMUNICATION
        }

via Java

final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
audioManager.setSpeakerphoneOn(true);
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION)
Alton09 commented 3 years ago

Hi @meSmashsta . As mentioned in the comment above, if you use the AudioSwitch library it sets this up for you as well as other audio management benefits.

meSmashsta commented 3 years ago

@Alton09 yes thank you for that, for the moment my solution is good enough for my use case, but yeah will surely use it in the future for sure