twilio / twilio-video.js

Twilio’s Programmable Video JavaScript SDK
https://www.twilio.com/docs/video/javascript
Other
571 stars 217 forks source link

audioLevel issues in stats #526

Closed xanoinc closed 4 years ago

xanoinc commented 5 years ago

Code to reproduce the issue:

We just upgraded from 1.5 to 2.0.0-beta5 and noticed the following issues with the audioLevel values in stats.

1) LocalAudioTrackStats always has a audioLevel of 0. Even though the other side can hear the audio just fine.

2) For the RemoteAudioTrackStats of that same audio stream that is reporting audioLevel=0 on the source, it appears to be a decimal value between 0-1 - the documentation says it should be an int between 0 and 32767, which is what it was doing on the 1.5 version.

// TODO

Expected behavior:

TODO

Actual behavior:

TODO

Software versions:

xanoinc commented 5 years ago

Sorry - I clicked save too early.

This is on Windows10, Chrome 71.0.3578.98

manjeshbhargav commented 5 years ago

Hi @seanmetrix ,

Thanks for writing in with your question. You are seeing this behavior because of this Chromium bug. We had to stop using Chromium's legacy getStats API because it has been deprecated and is scheduled for removal, and will no longer work when Chromium switches to "unified-plan" as the default SDP semantics.

Thanks,

Manjesh Malavalli JSDK Team

tr00st commented 4 years ago

Just checking in on this one, as the linked Chromium bug is marked as resolved. Our application's currently receiving "null" audioLevel and jitter values for local tracks - presuming this is an indication that the issue's still occurring, given I can't find anything in the docs about enabling these stats for local streams?

manjeshbhargav commented 4 years ago

Hi @seanmetrix , @tr00st ,

Since we last chatted, we have released some bug fixes regarding stats. Can you try the latest SDK version (2.7.1) to see if this is fixed? I'll close the issue, but we can continue the discussion here.

Thanks,

Manjesh Malavalli JSDK Team

tr00st commented 4 years ago

Hi Manjesh,

Thanks for the update. Just ran a couple of tests using 2.7.1 and I still appear to be hitting the same behaviour for audioLevel (ie: constantly null) - looks like jitter may be picking up correctly. I'll try and clean up the code I'm using to pull the audio levels out and see if there's anything obvious on my end.


EDIT: Nothing obvious - room.getStats() resolves sensible levels for remote tracks, but audioLevel returns as null for local tracks.

tr00st commented 4 years ago

@manjeshbhargav - any chance of a reopen on this, as it still appears to be occurring?

julien-l commented 4 years ago

This might help getting the audio level on Chromium browsers:

Attach the track to the HTML document:

room.on('trackSubscribed', function(track, publication, participant) {
    if (track.kind === 'audio' && track.name == 'your track') {
        var div = document.getElementById('your HTML element');
        div.appendChild(track.attach());
});

However the returned value is incorrect on Chromium. I log the audio level for debugging:

room.getStats().then(function(value) {
    value[0].remoteAudioTrackStats.forEach(function(track) {
        console.log(`track.trackSid: ${track.trackSid} level ${track.audioLevel}`);
    });
});

On Brave Browser on Mac OS:

// not speaking, room is silent:
track.trackSid: MTfbcf486eef... level 753641
track.trackSid: MTfbcf486eef... level 753641
track.trackSid: MTfbcf486eef... level 819175
track.trackSid: MTfbcf486eef... level 622573

// when speaking:
track.trackSid: MTfbcf486eef... level 243688179
track.trackSid: MTfbcf486eef... level 12746363

Audio levels are clearly out of bound.

On the other hand, Safari does not need to attach the track and audio levels are normal:

[Log] track.trackSid: MT3af13d71... level null
[Log] track.trackSid: MT3af13d71... level 43
[Log] track.trackSid: MT3af13d71... level 28
[Log] track.trackSid: MT3af13d71... level 23
shyamady commented 3 years ago

I tried this, but I can't get the audioLevel in real time and it remains null.

participant.on('trackSubscribed', (track) => {
  handleRemoteSoundCheck()
})

const handleRemoteSoundCheck = (twilioIdentity: string) => {
  twilioRoom.getStats().then(function (value) {
    value[0].remoteAudioTrackStats.forEach(function (track) {
      console.log(
        `track.trackSid: ${track.trackSid} level ${track.audioLevel}`,
      )
    })
  })
}
charliesantos commented 2 years ago

audioLevel should now show in 2.18.3. However, it is not supported in firefox, and in local audio tracks in safari.