This document is about: VOICE 1
SWITCH TO

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 Demo

The PUN Voice Demo is a simple four-player mobile friendly game where players can talk to each other. Other than matchmaking, the game has 4 different playable characters and 3 different camera views. The demo is based on Unity's tutorial "Survival Shooter" and is available in the Photon Voice package.

pun voice demo screenshot
PUN Voice demo running

Setup

To try out the PUN Voice demo:

  1. Download the package from the Asset Store.
  2. Open the project in Unity and load DemoPunScene.
  3. Open PhotonServerSettings in Unity Inspector (Menu: "Window" -> "Photon Unity Networking" -> "Highlight Server Settings"):
  4. Build, run and enjoy!
pun voice demo settings
PUN Voice Demo Settings

Features

In this section we will talk about the features exposed in the demo.

Multiple Characters

When trying the demo with your friends you will notice that every player will have his own unique character and will be spawned in a random position. This is handled using CharacterInstantiation class. In OnJoinedRoom callback we choose a prefab based on actor number and randmize spawn position.

Connection and Calibration

pun voice demo - control buttons
PUN Voice Demo - Control Buttons

On the bottom right corner, you can find calibration and connection buttons. The calibration button works only when joined to a voice room and is useful to tune loudness level. Read more about "calibration".

The other two buttons "connects to" or "disconnects from" PUN or Photon Voice respectively.

Settings

By making some settings easily accesible from the UI, we want to give you a shortcut to tune up your Photon Voice applications.

In-Game Settings

pun voice demo in-game settings
PUN Voice Demo In-Game Settings

The most important runtime settings for Photon Voice applications are grouped in a single ToggleGroup:

  • Transmit: When disabled voice transmission will be switched off. Otherwise sound will be recorded locally and transmitted.
  • Mute Speaker: This setting does what it says, it mutes speakers by setting volume to zero.
  • VoiceDetection: This setting enables or disables Voice Detection feature.
  • DebugEcho: This setting is useful when testing Voice applications using a single client. If on, audio stream sent to server will be returned back to original sender. To be used for debug only.

Global Settings

pun voice demo global settings
PUN Voice Demo Global Settings
  • AutoConnect: Automatically joins Photon Voice client to a "voice room" when PUN client is joined to a "PUN room".
  • AutoDisconnect: Automatically disconnects Photon Voice client when PUN client is disconnected.
  • AutoTransmit: Starts transmitting audio as soon as Photon Voice client is joined to a "voice room".
  • DebugVoice: Toggles debug mode. Debug text will appear on top left corner of the screen containing: PUN and Voice applications ClientState, Microphone device used and some Voice stats. If on, it also shows Voice speaker lag on top of every "speaking" character.

Highlighting Voice Components

In order to illustrate how the two main Voice components work we used an isometric view that is shown on top of every player. This view is based on Unity's new UI system in "World Space" mode. It contains 2 icons:

"Speaker" icon

pun voice demo - highlighting speaker
PUN Voice Demo - Highlighting Speaker

The purpose of this icon is to show when a player's voice is being played. It is binded to PhotonVoiceSpeaker component. The image is shown or hidden based on this code:

C#

speakerSprite.enabled = speaker != null && speaker.IsPlaying &&
                    PhotonVoiceNetwork.ClientState == ExitGames.Client.Photon.LoadBalancing.ClientState.Joined;

Also, when DebugVoice global setting is toggled, a text will start showing up in the same view containing a constantly updated number. It should inform about the lag in the speaker component. It is enabled or disabled as follows:

C#

bufferLagText.enabled = showSpeakerLag && speaker.IsPlaying && speaker.IsVoiceLinked;
bufferLagText.text = string.Format("{0}", speaker.CurrentBufferLag);

"Bubble speech" icon

pun voice demo - highlighting recorder
PUN Voice Demo - Highlighting Recorder

The purpose of this icon is to show when a player's voice is being recorded and transmitted. It is binded to PhotonVoiceRecorder component. The image is shown or hidden based on this code:

C#

recorderSprite.enabled = recorder != null && recorder.IsTransmitting &&
                    PhotonVoiceNetwork.ClientState == ExitGames.Client.Photon.LoadBalancing.ClientState.Joined;

You can take a look at the "Highlight.cs" file and class with the same name to know more about this.

Different Cameras

Since Photon Voice can be used in any type of games, AR and VR included, it would help to have a working example showing how good is the 3D sound experience. For this purpose, we have prepared 3 camera modes:

  • "First Person"
pun voice demo - first person view
PUN Voice Demo - First Person View
  • "Third Person"
pun voice demo - third person view
PUN Voice Demo - Third Person View
  • "Orthographic" (Default)
pun voice demo - orthographic view
PUN Voice Demo - Orthographic View

You switch between them freely and seamlessly at any time once you're joined to a room. Three respective buttons are available on the top right corner of the screen once the player's character is instantiated.

Mobile Joystick

The demo includes support for mobile touch input. On smartphones or tablets, you can use the joystick UI that comes with the demo which is based on Unity's Standard Assets. To be able to use this feature you need to enable "Mobile Input" from Unity's menu and switch to a compatible platform in Unity's build settings.

pun voice demo - android screenshot
PUN Voice Demo - Android Screenshot

Debug Mode

When the DebugVoice toggle is on, the Debug Mode is enabled. During this mode, extra information is displayed on the top left corner of the screen which contains:

  • State of PUN Client
  • State of Voice Client
  • Average and peak voice amplitudes
  • List of microphone devices available or a warning if none. Generally, most devices contain one microphone.
pun voice demo - debug mode
PUN Voice Demo - Debug Mode

Sounds

The demo also includes some nice sound effects. They should inform of room join and leave events. We hope you like them!

Back to top