how to find latency between audio sent and audio arriving on another client | Unity

so iv been doing a massive amount of digging through photon voice's code for the last couple days and i'm trying to find the latency between the audio being sent from player 2, and arriving at player 1 (not when it plays).

i'm thinking something with using server time and calculating the difference between it being sent, and arriving, i think ill put the calculation for when it has arrived on the photon speaker component under "OnAudioFrame" but where do i put the the piece of code that takes the timestamp from when the audio frame was sent?

i hope that's clear enough, anyone have any idea?


  • JohnTubeJohnTube mod
    edited April 12
    Hi @Hawki101,

    Thank you for choosing Photon!

    Photon Voice kind of does this, check out VoiceConnection.VoiceClient.RoundTripTime when DebugEchoMode is enabled.
    Otherwise checkout Photon Realtime (a.k.a. LoadBalancingClient's network stats) via LoadBalancingPeer (you could display those via PhotonVoiceStatsGui component attached to the same GameObject as VoiceConnection/PhotonVoiceNetwork).

    Otherwise you could modify the code a little bit and send the server timestamp (LoadBalancingPeer.ServerTimeInMilliseconds) with each frame and compare it to the server time on the receiving end when the frame is received.

    But is this what you are looking for exactly? it's just the network latency (send-receive).
  • Hawki101Hawki101
    edited April 12
    Yep, i actually found it using something along the lines of sending timestamps and implementing delay based on that data to line up audio tracks, works really well. i have just ran into another road block though, does photon not send frames that contain next to nothing even with transmit turned on? im not using voice detection or anything like that, transmit, is always turned on, but im noticing that if frames are next to empty, they dont get sent at all (i need them to be sent).

    the problem with this was actually that when updating the audio source through code, voice detection enables its self automatically and had to turned off after creation.
Sign In or Register to comment.