This page is a work in progress and could be pending updates.

Voice For Fusion

Contents

Concept

This integration simplifies using of Photon Voice inside Photon Fusion projects, the main use case is when each player has network-spawned object (character or avatar) where audio could be 3D positioned, but it is possible to have audio sources on other objects, that are not coupled with Fusion-spawned player avatars.

Audio stream should not be transmitted on top of or using Fusion, instead a separate parallel client with a distinct connection makes it easier to decouple the actual application data traffic from the audio traffic. Also, this is the most common way of doing voice chat in games where voice infrastructure is separate from game infrasturctue.

It is also worth mentioning that the Fusion-Voice integration is optional but recommended, Photon Voice with Fusion can be used without this integration, but then a custom integration between Fusion and Photon Voice needs to be in place.

Back To Top

Key Components

FusionVoiceBridge

The FusionVoiceBridge requires Voice's VoiceConnection and Fusion's NetworkRunner. As its name suggests, it works as a bridge between the two. Here is what it does:

  • synchronizes Voice and Fusion client states by making sure:
    • Voice client joins a voice room when Fusion joins a session.
    • Voice client leaves the room then disconnects when Fusion shuts down or disconnects.
  • sets a SpeakerFactory that works best with Fusion.
  • allows Fusion and Voice to share the same AppSettings and AuthenticationValues.

Back To Top

FusionSpeakerFactory

A single audio stream has a pair of components one on each end: the Recorder (input, recording, transmission, emiter) and the Speaker (receiver, playback, output). When using Fusion integration, the pair is linked via Fusion's NetworkObject.Id (of type NetworkId obtained from NetworkBehaviour). The NetworkId is serialized in Photon Voice client as a ulong. FusionVoiceBridge registers the NetworkId as a custom serialization type.

The new factory will try to find the proper Speaker for the audio stream info using the NetworkObject.Id exchanged as custom user data object of the audio stream creation info (meta data).

Back To Top

Use Fusion Settings

A setting to decide if the Voice client will use the same AppSettings from Fusion's PhotonAppSettings. By default this is true (enabled).

Back To Top

Use Fusion Auth Values

A setting to decide if the Voice client will use the same AuthenticationValues as Fusion's networkRunner.AuthenticationValue. By default this is true (enabled). This requires the Voice application to have the same custom authentication dashboard configuration as the Fusion application. However, you should know that some authentication providers require the client to issue a nonce (unique one time secret) per authentication request. So the authentication values cannot be shared between Fusion and Photon Voice and you need to set the AuthenticationValues of the voice client manually (via VoiceConnection.Client.AuthValues) before connecting the voice client.

Back To Top

VoiceNetworkObject

The VoiceNetworkObject is the component responsible for setting up the Recorder and Speaker for the network-instantiated Fusion prefab. It makes sure that RecorderInUse and SpeakerInUse are setup when needed.

Back To Top

Recorder Setup

The following steps are performed in order to set up the Recorder to be used by the VoiceNetworkObject:

  1. check if a Recorder is needed.
  2. try to find a suitable Recorder.
  3. create a Recorder if none found.
  4. set the Recorder's UserData to the NetworkId of the relative NetworkObject.
  5. initialize the Recorder if not already initialized.
  6. restart the Recorder if needed.

Back To Top

Speaker Setup

The following steps are performed in order to set up the Speaker to be used by the VoiceNetworkObject:

  1. check if a Speaker is needed.
  2. try to find a suitable Speaker.
  3. create a Speaker if none found.
  4. check if the AudioSource associated with the Speaker is ready for playback.

Back To Top

Import Instructions

Photon Voice's minimal required Unity version is 2019.4 while Fusion's minimal required Unity version is 2020.3. So the Voice-Fusion integration requires Unity 2020.3.

Back To Top

Import Fusion

This part can be skipped, there already is Fusion in the project.

  1. Download and import Fusion here.
  2. Open the Photon App Settings using the menu item at Fusion > Realtime Settings.
  3. Get AppId of type Fusion and set it in Realtime Settings: "App Id Fusion".

Back To Top

Import Photon Voice

This part can be skipped, if there already is Photon Voice in the project.

Import Photon Voice 2 using Unity Package Manager or from Unity Asset Store or download from SDK Download:

  • Uncheck "Photon\PhotonChat" .
  • Uncheck these folders:
    • "Photon\PhotonUnityNetworking"
    • "Photon\PhotonVoice\Code\Pun"
    • "Photon\PhotonVoice\Demos" contents except "Photon\PhotonVoice\Fusion"

PUN (instructions) or Photon Chat (instructions) still can be removed using menu item shortcuts later.

Back To Top

Update Weaver Settings

  1. Open "Network Project Config" via menu item shortcut: Fusion > Network Project Config
  2. Unfold or open Config
  3. Unfold or open Weaving Settings
  4. Under Assemblies To Weave, add one more item to the list of assembly to weave via "+" button
  5. In the newly created item, from the dropdown list of available assemblies select "PhotonVoice.Fusion"
  6. At the bottom, hit Apply.

Back To Top

Suggested Workflow

The following instructions are the minimal, easiest and fastest recommended steps to integrate Voice into a Fusion project:

Scene Setup (FusionVoiceBridge)

  1. Set a Voice AppId in the AppSettings from Fusion's PhotonAppSettings.
  2. Add a FusionVoiceBridge and a VoiceConnection to the same GameObject as the NetworkRunner.
  3. Add a Recorder and assign it to VoiceConnection.PrimaryRecorder.
  4. Make sure the Recorder can start recording and transmission when needed (AutoStart, RecordOnlyWhenJoined, RecordOnlyWhenEnabled, TransmitEnabled).

Back To Top

Prefab Setup (VoiceNetworkObject)

  1. Add a VoiceNetworkObject to a GameObject of a Fusion prefab that has a NetworkBehaviour attached to it.
  2. Set VoiceNetworkObject.UsePrimaryRecorder to true.
  3. Add a Speaker to the prefab and assign it to the VoiceNetworkObject.SpeakerInUse.
  4. Make sure Fusion is aware of the prefab via shortcut menu item: "Fusion" -> "Rebuild Object Table".

For more information see samples for Fusion or Fusion Impostor sample

To Document Top