Hi I am new to multiplayer development and I am using photon voice and wanted to make private voice chat between two player in a room created which has many players. I was directed to https://doc.photonengine.com/en-us/voice/current/getting-started/voice-for-pun?utm_campaign=sendgrid&utm_source=sendgrid.com&utm_medium=email by support of photon but I am not able to get it working. How should I make private voice chat in this multiplayer. please give example for explanation. Thanks
There is a demo scene for Push To Talk which showcases how to do this. Let me try to explain how to implement player to player voice chat using current Photon Voice:
Photon Voice uses voice groups (which is nothing but Photon LoadBalancing's "Interest Groups") to separate voice channels/targets.
Filter incoming sounds (select "what to hear" or "who do you want 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 a single transmission target audio group (select "who do you want to talk to"):
Each actor needs to decide to which voice group it wants to transmit audio. The target audio group can be set using PhotonVoiceRecorder.AudioGroup
.
So depending on the use case what you can do is:
PhotonVoiceNetwork.Client.GlobalAudioGroup
. If you choose to set GlobalAudioGroup
no need to call ChangeAudioGroups
or set PhotonVoiceRecorder.AudioGroup
as it's done internally for you.In the three cases, you always listen to default audio group 0.
The Photon Voice demo offers two options for private (1 to 1) voice chat:
The audio groups in the demo are constructed this way: We have rooms of 4 actors. We need 6 audio groups. For each pair of actors we calculate a unique group code.
Here is how we get the audio group of private voice chat between A and B (if an actor number reaches 24 we have a problem):
if (x < y)
{
AudioGroup = y + x * 10;
}
else if (x > y)
{
AudioGroup = x + y * 10;
}
else
{
// error
}
Example: The audio group for actors 1 and 2 is 12.
Another 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.
The advantage of this approach:
The drawback of this approach: