Photon Voice 1 is the original and first major version of Photon Voice. It is now replaced by Photon Voice 2 which is refactored and enhanced. We highly recommend starting new projects with Photon Voice 2 and if possible migrating existing ones from Photon Voice 1 to Photon Voice 2. Photon Voice will be maintained for the coming months. We will fix important bugs and support new Unity versions but new features will be added only to Photon Voice 2.

PUN Voice Push To Talk Demo

The Push To Talk demo scene showcases how to achieve:

  • Push-to-Talk feature.
  • Private Voice Chat.

In this document we will describe each feature and how you can use it.

PUN Voice PTT Demo Screenshot
PUN Voice Push-To-Talk demo running

Push-to-Talk Mode

To transmit voice on demand:

  • set PhotonVoiceSettings.AutoTransmit to false.
  • when you want to start transmission set PhotonVoiceRecorder.Transmit to true.
  • to stop transmission set it back to false.

In the demo we bind keyboard keys ('v' for broadcast and numeric keys corresponding to joined actors' numbers) and UI buttons ("TalkToAll" for broadcast, "TalkToX" per joined actor number 'X') to Push-to-Talk groups and use PushToTalkOn and PushToTalkOff methods.

Audio Groups Demystified

Photon Voice uses audio groups to separate mutually exclusive "voice channels" or "voice targets". Audio groups are based on Photon LoadBalancing's "Interest Groups". Here is how to make use of these voice groups to:

Select "Who To Listen To"

Each actor needs to subscribe to voice groups it's interested in. By default all actors listen to audio group 0 which could be seen as a global audio group for voice broadcast. If you want to listen to voice sent to other groups you need to subscribe to them. You can also unsubscribe from previously subscribed ones. The operation to do all this is:

PhotonVoiceNetwork.Client.ChangeAudioGroups(byte[] groupsToRemove, byte[] groupsToAdd);

Select "Who To Talk To"

Each actor needs to decide to which voice group it wants to transmit audio to. The target audio group can be set using:

photonVoiceRecorder.AudioGroup = targetAudioGroup;

Use Cases

In all cases, you always listen to default audio group 0 and you can transmit voice to a single audio group at the same time. Use cases could be grouped into three different categories:

1. Listen Only To Default Group

A. Speak Only To Default Group

This is the default behaviour. If you want to switch back from another setup:

PhotonVoiceNetwork.Client.GlobalAudioGroup = 0;

In this case no need to call PhotonVoiceNetwork.Client.ChangeAudioGroups or set PhotonVoiceRecorder.AudioGroup as it's done internally for you.

B. Speak To A Custom Group

// unsubscribe from all groups
PhotonVoiceNetwork.Client.ChangeAudioGroups(new byte[0], null);

// set target AudioGroup
photonVoiceRecorder.AudioGroup = targetAudioGroup;

2. Listen To The Same Audio Group You Speak To

For this particular use case, there is a shortcut to switch between this single in/out group using:

PhotonVoiceNetwork.Client.GlobalAudioGroup = targetAudioGroup;

In this case no need to call PhotonVoiceNetwork.Client.ChangeAudioGroups or set PhotonVoiceRecorder.AudioGroup as it's done internally for you.

3. Listen To Multiple Groups

A. Listen To All Available Groups

// subscribe to all groups
PhotonVoiceNetwork.Client.ChangeAudioGroups(null, new byte[0]);

// set target AudioGroup
photonVoiceRecorder.AudioGroup = targetAudioGroup;

Later, you may need to subscribe to groups created after this call.

B. Listen To A List Of Groups

// subscribe to 'groupsToListenTo' only
PhotonVoiceNetwork.Client.ChangeAudioGroups(new byte[0], groupsToListenTo);

// set target AudioGroup
photonVoiceRecorder.AudioGroup = targetAudioGroup;

You can speak to a group other than those you listen to. i.e. groupsToListenTo could not contain targetAudioGroup.

How We Use Audio Groups In The Demo

The Photon Voice Push-to-Talk demo offers two options for voice chat:

  • "MuteOthers" enabled: corresponds to case n°3.A (above). When PushToTalkScript.MuteOthersWhileTalking is equal to true we call PushToTalkScript.KeepOnlyOneGroup((byte)CurrentTargetGroup);.
  • "MuteOthers" disabled: corresponds to case n°2 (above). When PushToTalkScript.MuteOthersWhileTalking is equal to false we call PushToTalkScript.SubscribeToAllPrivateGroups();.

The "MuteOthers" mode could be changed on the fly at any time using a UI toggle.

The audio groups in the demo are designed this way:

  • We have rooms of 4 actors.
  • We use default group 0 as target audio group for broadcast.
  • We need 6 custom private audio groups: for each pair of actors we calculate a unique group code.
  • When the local actor joins the room it subscribes to the audio groups of the previously joined ones.
  • When a new remote actor joins the room the local actor subscribes to the corresponding audio group. See PushToTalkScript.OnPhotonPlayerConnected.
  • When a remote actor leaves the room the local actor unsubscribes from the corresponding audio group. See PushToTalkScript.OnPhotonPlayerDisonnected.
  • Here is how we get the audio group of private voice chat between two players (local and remote):
// snippet from PushToTalkPrivateButton.SetAudioGroup
if (PhotonNetwork.player.ID < TargetActorNr)
    // note: actor numbers should not reach 25
    AudioGroup = (byte) (TargetActorNr + PhotonNetwork.player.ID * 10);
else if (PhotonNetwork.player.ID > TargetActorNr)
    AudioGroup = (byte) (PhotonNetwork.player.ID + TargetActorNr * 10);

Example: The audio group for actors 1 and 2 is 12.

Another Variant

Another possible approach of "calculating" private voice groups is to use the actor number as audio group:

  • Each actor subscribes to a single audio group with a code equal to its actor number.
  • Whenever you want to talk to a remote actor you set the target audio group (using PhotonVoiceRecorder.AudioGroup only) to the target actor number.


  • Less audio groups: we need as many audio groups as actors.
  • Less audio groups switching: single audio group to subscribe to and no unsubscribing.


  • You can't mute any other actor. You will listen to anyone who wants to talk to you privately.

 To Document Top