Photon Voice: Debugging

edited March 2016 in Photon Voice
Last week I added PUN and PUNVoice to my Unity project. The initial implementation was very quick and I had voice comms working fine.

Today however the VoIP functionality element has stopped working and I'm struggling to debug the problem.

I have a simple Voice GameObject prefab which is being instantiated successfully. Testing with two clients I can see the local instance and the remote instance have been cloned.

The objects have a Transform, PhotonView, AudioSource, PhotonVoiceSpeaker and PhotonVoiceRecorder components.

The PhotonVicew's have a sensible ViewID, controlled locally is ticked for one and unticked for the 2nd. Oberve option is off and observed component is empty.

The audio source has nothing set (not clip, no output etc).

PhotonVoiceRecorder has no audio clip.

I have a scene script which has a PhotonVoiceSettings script attached, with AutoConnect,AutoDisconnect,AutoTransmit all ticked. Voice Detection is on with default threshold. I've also tried ticking Debug Info.

When I run it up, my microphone switches on on my PC build, as I can see the light come on.

I get a PUNVoice: Setting recorder's microphone to which means it's selecting default device.

The speaker volume on phone and PC are non-zero.

However, I get no audio on Android Phone nor on PC.

I've tried setting an audio clip into the PhotonVoiceRecorder and ticking loop. I get a warning that about audio source and encoder sampling rates not matching but no audio at either end.

I've also confirmed that I have an audio listener attached to my main camera.

Can anyone make any suggestions about how I can debug this? I'd like to know if the recorder is picking up anything from the microphone, whether it is trying to transmit, whether audio is being received by the speaker etc.



  • I've found a way to make voice work again, but it leaves me more confused.

    I made a new Photon Voice object, exactly the same as the one in my resources folder, and placed this object in the scene

    With this scene object present I get voice comms once the build has established a network connection.

    The other voice objects are still instantiated as expected but these don't appear to be added to the voice system.

    This appears to directly contradict the documentation:
    The prefab should be instantiated only at runtime and after joining a room using PUN. Scene object instances are not supported. So you should not have any PhotonVoiceRecorder instances in the scene.
    The other difference is that when the I'm not talking, so volume is below threshold, I get a steady stream of underrun warnings.
    PUNVoice: PhotonVoiceSpeaker: player underrun: 189376/194160(192069) = 4784
    PhotonVoiceSpeaker:Update() (at Assets/PUNVoice/Scripts/PhotonVoiceSpeaker.cs:166)
    Any help would be very welcome.

  • JohnTube
    JohnTube mod
    edited March 2016
    Hi @jules43,

    So you're saying you managed to make an object "compiled" in the scene to work with Photon Voice but other prefabs instantiated at runtime do not work? (the opposite of what you quoted from the docs?)

    First things first, did you try voice demo project? did it work well for you?
    Last week [...] I had voice comms working fine.
    Today however the VoIP functionality element has stopped working.
    What did you change between last week and today?

    Why make a new object when you have a prefab in resources folder? try these 2 tests:
    - add the same prefab to the scene instead of the new object. Check if it works without runtime instantiation.
    - the opposite: try making that object a prefab and instantiate it at runtime. Check if it works when instantiated at runtime.

    We are aware of the 'player underrun' warnings, let's leave that aside for now and go step by step.
  • The problem appears to be with when the PhotonVoiceNetwork singleton is created. If I access the PhotonVoiceNetwork object prior to calling CreateOrJoinRoom then everything works just fine.

    If the first time the singleton is accessed is during OnJoinedRoom() when I instantiate the object with voice script components then it fails, and the system never connects to the EU regional voice server.

    My work around is before I start the network I access a member of PhotonVoiceNetwork (like the object name) and all is well.

    It appears to be a bug, but I'd be happy to find out how it is intended to work if not.
  • JohnTube
    JohnTube mod
    edited March 2016
    Do you have an instance of PhotonVoiceNetwork in the scene? If so please try removing it and test.
  • Hi @JohnTube mod

    Thanks for your questions. What happened was I create the voice game object in my scene and then dragged it into the Resources folder. Then I forgot to delete the copy in the scene. With this setup everything appeared to work.

    Later when I saw the voice object still in the scene, I just deleted it, without testing whether it still worked.

    So, when I came to test it again later I had the inexplicable failure.

    I then thought I'd recreate the object again and drag it into the Resources folder to make sure I hadn't changed something to break it. Whereupon all seemed to be fine.

    I turned out I'd made the same mistake, leaving the original object in my scene after copying into the resources folder.

    This showed me that I the thing that switched it from working to not working was the existence of the scene level voice object.

    Further investigation has shown me that the reason this makes things work, is actually due to the fact that the PhotonVoiceNetwork singleton is being brought into existence by this scene object. So the act of forcing the singleton into existence early enough also fixes the problem, allowing me to delete the scene object.

  • Hi @JohnTube mod

    Regarding presence of PhotonVoiceNetwork object within scene. The answer is not as far as I can tell, and I have searched for a reference to the script in my scene, as well as checking my objects and prefabs to ensure I haven't mistakenly added it somewhere.

    I do have a scene object with a PhotonVoiceSettings object attached to it.


  • Hi @JohnTube mod

    Further comment. I placed a break point on the "instance" member of PhotonVoiceNetwork and can see the when the PhotonVoiceNetworkSingleton gets created. As that code does a search for a previously existing PhotonVoiceNetwork object, I'm pretty confident that there is no previous PhotonVoiceNetwork object.

    Having removed the scene level voice object, I have a very simple sequence.

    When my app starts up, it creates sets logLevel and then calls ConnectUsingSettings(). The in OnJoinedLobby I call JoinOrCreateRoom. Finally in OnJoinedRoom I call Instantiate on my voice object.

    If I add the line:


    in my start function, or in OnJoinedLobby before calling JoinOrCreateRoom then VoIP works perfectly.

    If I place the line in OnJoinedRoom before I instantiate the voice object (or don't place it in at all), then VoIP does not work and I'm never connected to the voice server.

    I have logs of the the working and non-working version if that's useful.

    I believe that the line I'm adding is forcing the timing of the singleton creation, and that needs to occur before OnJoinedRoom.

    Any thoughts?


  • Hi @JohnTube mod

    Further information. I just tried the opposite.

    I removed the line I added to force singleton creation, and attached the PhotonVoiceNetwork script to my scene level scripts object.

    This also fixed the problem, as PhotonVoiceNetwork.instance searches for any instances of the script before it creates the singleton.

    I'm not sure which is the better solution, but it confirms my view that this may be a bug.

    Could it be that it isn't commonly come across as it is uncommon to have to accesses to the PhotonVoiceNetwork object prior to joining a room?

  • JohnTube
    JohnTube mod
    edited March 2016
    I have logs of the the working and non-working version if that's useful.
    Could you please give us the non-working version of the logs so my colleagues can have a better look. Thanks.
  • I ran a functional instance of the app on Android phone, then ran the same version of PC, with PhotonLogLevel.Full set. In this version I have the line:

    GameObject pvns = PhotonVoiceNetwork.singleton

    Before I call ConnectUsingSettings.

    I get good voice comms, and this is the log:

    I then commented out the line on the PC version, and re-ran it. Voice did not work and I got this log output from Unity.

    Please note that as a debugging aid I have log messages in all of the Photon.PunBehaviour callbacks, I can remove these is needed.

    Please let me know if there's any other way I can help.

  • @jules43 thank you very much for your efforts. We will take a look.
  • Hi Jules,

    Voice server autoconnection relies on OnJoinedRoom() method of script attached to PhotonVoiceNetwork which does not exist at PUN room joining time in your case. Thanks for report and helpful logs. Will be fixed soon.
  • This problem still isn't fixed in the 1.3 version of the SDK, though my workaround above no longer works. I'm now using:
    PhotonVoiceNetwork pvni = PhotonVoiceNetwork.instance;
  • Hi,

    We reworked PhotonVoiceNetwork singleton creation in version 1.1 (released about 12.04.2016).
    No need to put PhotonVoiceNetwork in scene now. Optionally you can add PhotonVoiceSettings if settings other than default required.
    Please give short instruction on how we can reproduce the problem with latest Photon Voice version.
  • jules43
    edited July 2016
    I have a PUNManager script attached to a scene object:

    in Start() this does:
    PhotonVoiceNetwork pvni = PhotonVoiceNetwork.instance;   <-- workaround for bug
    Note: PhotonServerSettings has "Auto-Join Lobby" enabled in Resources directory.

    in OnJoinedLobby() it does:
    RoomOptions roomOptions = new RoomOptions() { isVisible = false, maxPlayers = 4 };
    PhotonNetwork.JoinOrCreateRoom("MyRoom", roomOptions, TypedLobby.Default);
    In OnJoinedRoom() it does:

    PhotonNetwork.Instantiate("VoiceObject",, Quaternion.identity, 0);

    VoiceObject is a prefab in Resources which has a PhotonView, AudioSource, PhotonVoiceSpeaker and PhotonVoiceRecorder attached to it.

    That's pretty much it. If I remove the workaround then I get no VoIP between Android clients, if I add my line back in then it works fine.

    Hope that helps.

  • mxweas
    edited July 2016
    Signing in to confirm that I am having this issue as well. I am not using the lobby features of Photon. I spent the afternoon tracing it to the exact same place. The following check in OnJoinedRoom fails and then Connect() is never called:
    void OnJoinedRoom()
            if (this != _instance)
    If I get rid of my instance of PhotonVoiceNetwork, then OnJoinedRoom is never called at all. (Possibly the singleton that is created by Photon gets created after the event fires?) If I leave it in, this check fails because _instance is null at this point. Only later does someone call PhotonVoiceNetwork.instance which actually instantiates the singleton.

    Thanks for posting the workaround. Although not ideal, it'll keep me from pulling my hair out until there is an update :)

  • Currently accessing PhotonVoiceNetwork from user code to initialize singleton before joining PUN room required.
    Does this cause any real problems besides extra line in initialization code?
  • jules43
    edited July 2016
    Not for me. Workaround is fine.