twilio / voice-quickstart-android

Quickstart app for the Voice Android SDK
https://www.twilio.com/docs/api/voice-sdk/android/getting-started
MIT License
184 stars 140 forks source link

There is no sound in the audio file Android 12 #529

Closed alti-kr closed 2 years ago

alti-kr commented 2 years ago

There is no sound in the audio file Android 12

App uses com.twilio:voice-android:6.1.1, The app needs to record audio when it's in the background or foreground. For this, a background service is used, the context of which is used to initialize the twilio client. When app in foreground it's all ok. When app in background and service started auido recording, there is no sound in the audio file.

Steps to Reproduce

  1. Start call , init Voice.connect from background service
  2. Create sound to record around the device
  3. Stop call
  4. Listen audio record

Code

private fun connect(
        context: Context,
        accessToken: String,
        alarmId: String,
        userId: String
    ) {

        val options = ConnectOptions.Builder(accessToken).params(
            mapOf(
                Pair("alarmId", alarmId),
                Pair("userId", userId)
            )
        ).build()

        val call = Voice.connect(context, options, object : Call.Listener {
            override fun onConnectFailure(call: Call, exception: CallException) {
                li(TAG, "onConnectFailure() called with: call = $call, exception = $exception")
            }

            override fun onRinging(call: Call) {
                li(TAG, "onRinging() called with: call = $call")
            }

            override fun onConnected(call: Call) {
                li(TAG, "onConnected() called with: call = $call")
            }

            override fun onReconnecting(call: Call, exception: CallException) {
                li(TAG, "onReconnecting() called with: call = $call, exception = $exception")
            }

            override fun onReconnected(call: Call) {
                li(TAG, "onReconnected() called with: call = $call")
            }

            override fun onDisconnected(call: Call, exception: CallException?) {
                li(TAG, "onDisconnected() called with: call = $call, exception = $exception")
            }
        })       
    }

Expected Behavior

Hear the recorded conversation etc.

Actual Behavior

Silence

Reproduces How Often

99%

Twilio Call SID(s)

SIDs of the conferences:

CF2495712c75b27b884a3eab1fd6a72d94 CF49e987e19a4a93c4355bd709019ba33b CFf464657ab504d7bb6389fdcad704d259

Good RE4b74074969b20f7be7e0c370871accb2

Logs

From correspondence with support of Twilio

I turned on "Voice.setLogLevel(LogLevel.DEBUG)"
But received little information.

SID 62c2c9ab72ef26f18050b14d

D: [Core](MediaFactoryImpl::signaling 0x0xb400007e6da41200): processReportAndPostEvent
D: Start publishing events to : https://eventgw.twilio.com/v4/EndpointMetrics
    {"name":"metrics-sample","group":"quality-metrics-samples","timestamp":"2022-07-04T11:07:40.285Z","level":"INFO","private":false,"payload_type":"application\/json","publisher":"twilio-voice-android","publisher_metadata":{"client_address":"FE80::7093:18FF:FECE:274","os_name":"android","os_version":"12","device_model":"SM-G780G","device_vendor":"samsung","device_type":"SM-G780G","cpu_architecture":"arm64-v8a","app_name":"S-Dev","app_id":"com.sosafe.app.dev","app_version":"1.4.0.0","app_build_number":"1040000","app_min_os_version":21,"app_target_os_version":31},"payload":[{"timestamp":"2022-07-04T11:07:36.276Z","timestamp_ms":"1656932856276.947998","call_sid":"CA544fe262c85d1a1084356b81ab6d3e3d","sdk_version":"6.1.1","packets_received":47,"total_packets_lost":0,"packets_lost_fraction":0,"packets_lost":0,"total_packets_sent":3744,"total_packets_received":3703,"total_bytes_received":134874,"total_bytes_sent":121680,"jitter":9,"rtt":34,"audio_level_in":0,"audio_level_out":128,"mos":4.411558151245117,"audio_codec":"opus","direction":"OUTGOING"},{"timestamp":"2022-07-04T11:07:40.277Z","timestamp_ms":"1656932860277.787109","call_sid":"CA544fe262c85d1a1084356b81ab6d3e3d","sdk_version":"6.1.1","packets_received":50,"total_packets_lost":0,"packets_lost_fraction":0,"packets_lost":0,"total_packets_sent":3944,"total_packets_received":3906,"total_bytes_received":142182,"total_bytes_sent":128180,"jitter":10,"rtt":33,"audio_level_in":0,"audio_level_out":128,"mos":4.410117149353027,"audio_codec":"opus","direction":"OUTGOING"}]}
D: Response: 200 - OK

SID 62c2cad072ef26c27c50b1d6

I: Logging > isUsaNetwork() / 255, null / false
I: Logging > logProperty()
I: Logging > isDateChanged() > 1day
I: Logging > init()
E: Logging > sendLog() id = 1093 : error (Diagnostic & Pn not agreed)
E: Logging > sendLog() id = 1093 : error (Diagnostic & Pn not agreed)
E: Logging > sendLog() id = 500 : error (Diagnostic & Pn not agreed)
I: Logging > sendLog() id = 136 : success (RestApi)
E: Logging > sendLog() id = 9000 : error (Diagnostic & Pn not agreed)

and 
2022-07-04 13:37:40.184 5880-5928/? I/GMS_MM_Logger: Started.
2022-07-04 13:42:20.138 5880-4471/? I/GMS_MM_Logger: Memory Metric Logging not allowed. Stopping.

I hope you will get more information from your logs

From the calls provided, I noticed that these are coming with bad quality. I'm not confirming that what is causing this issue, however, I would like to check and compare with a good example where the call was recorded with audio.

The following tags are part of the bad calls: tag_silent, tag_missing_rtp_stream, tag_latency. 

Also, could you please open an issue here: https://github.com/twilio/voice-quickstart-android/issues this will receive attention from  our development team via GitHub for future cases exhibiting the same behavior.

Versions

compileVersion = 31 minVersion = 21 targetVersion = 31

Voice Android SDK

com.twilio:voice-android:6.1.1

OS Version

Android 12

Device Model

Samsung S20 FE, Android 12, build 1.3.1.6 Pixel 4, Android 12, build 1.3.1.6

kbagchiGWC commented 2 years ago

Hi @alti-kr

Have you tried using foreground-services? If you want audio to continue recording when the app is in the background or when the screen locks, you should be using the foreground-services. A related issue can be referred here.

alti-kr commented 2 years ago

Hi I checked and corrected. But that didn't solve the problem.
Result: 7/10 files didn't have the sound

kbagchiGWC commented 2 years ago

@alti-kr

Can you share your foreground-services implementation and how you are starting when a call is started or accepted? How are you recording the audio?

alti-kr commented 2 years ago

@kbagchiGWC `In Mahifest

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission
    android:name="android.permission.BLUETOOTH"
    android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />

<service
        android:name=".services.AaaService"
        android:enabled="true"
        android:exported="false"
        android:foregroundServiceType="microphone" />

Strat Service

val intent = Intent(context, AaaService::class.java).also { intent -> intent.putExtra(ExtraKey0, true) context.startForegroundService(intent)

In AaaService

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { this.startForeground( id, ServiceUtils.buildForegroundNotification( channelId, channelName, channelDescription, title, content, icon, service, priority ) ) }` NoSound.txt WithSound.txt

In the attached files you can see the logs of both situations.

alti-kr commented 2 years ago

@kbagchiGWC The problem was localized, if service was started from app, client of twilio has access to microphone on Pixel device and hasn't access to microphone on Samsung device. The main problem is how to run the application without user intervention (Android 12) or access the microphone from the service. I will close the issue, thanks.