Voice For PUN2



The Voice for PUN2 layer logic is inherited from the original Photon Voice 1 or PUNVoice: Voice client state can be automatically synchronized with PUN's client state.

The main use case in mind is that each player has network-instantiated PUN prefab (character or avatar) where audio is 3D positioned. A single voice stream has a pair of components one on each endpoint: the Recorder and the Speaker. When using PUN the pair is linked via Photon View ID.

Key Components


The PhotonVoiceNetwork extends VoiceConnection and adds PUN related features: The default SpeakerFactory is overridden and you can tweak how much you want the PUN and Voice clients' states to be in sync. Also PUN and Voice can optionally share the same AppSettings from the PhotonServerSettings.

Default SpeakerFactory

The new factory will try to find the proper Speaker for the voice stream info using the Photon View ID exchanged as custom user data object.

Auto Connect And Join

If PUN joins a room, the Voice client can connect and join a corresponding voice room as well.

Auto Leave And Disconnect

If PUN leaves the room the Voice client can disconnect automatically.


The PhotonVoiceView is the component responsible for setting up the Recorder and Speaker for the network-instantiated PUN prefab.

Suggested Workflow

Scene Setup (PhotonVoiceNetwork)

  1. Add a PhotonVoiceNetwork to the scene.
  2. Choose if you want to use AppSettings from PUN's PhotonServerSettings or separate ones:
    a. If you tick/check "Use PUN Settings": go to PUN's PhotonServerSettings and update them with Voice info if needed.
    b. If you untick/uncheck "Use PUN Settings": update the Settings in the same component.
  3. Optionally set PhotonVoiceNetwork.AutoConnectAndJoin to true.
  4. Optionally set PhotonVoiceNetwork.AutoLeaveAndDisconnect to true.
  5. Optionally add a Recorder to the scene, update its properties and assign it to PhotonVoiceNetwork.PrimaryRecorder.
  6. Optionally decide if (6.a.) and how (6.b.) Speaker instances should be created when we can't find one for the incoming voice stream:
    a. Optionally set PhotonVoiceNetwork.AutoCreateSpeakerIfNotFound to true.
    b. Optionally add a Speaker prefab (a prefab that has a Speaker component) and assign it PhotonVoiceNetwork.SpeakerPrefab.

Prefab Setup (PhotonVoiceView)

  1. Add a PhotonVoiceView to a GameObject of a PUN prefab that has a PhotonView attached to it.
  2. Recorder setup (a or b or c):
    a. Set PhotonVoiceView.UsePrimaryRecorder to true (requires PhotonVoiceNetwork.PrimaryRecorder to be set).
    b. Set PhotonVoiceView.AutoCreateRecorderIfNotFound to true.
    c. Add a Recorder to the prefab, update its properties and assign it to the PhotonVoiceView.RecorderInUse.
  3. Optionally add a Speaker to the prefab and assign it to the PhotonVoiceView.SpeakerInUse.

 To Document Top