Voice - Fusion Integration

Contents

Voice - Fusion Integration

This integration simplifies the use 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 streams are created in the Voice room synchronously with NetworkObject prefab instantiation in the scene. The Recorder attached to the network object produces an audio stream. The Speaker attached to the remote copy of this network object consumes the audio stream. NetworkObject.Id is used to find the correct Speaker for the Recorder.

Back To Top

Key Components

FusionVoiceClient

An implementation of VoiceConnection that maintains connections and synchronizes the states of Fusion and Voice clients. Voice client joins a Voice room when Fusion joins a session. Voice client leaves the room then disconnects when Fusion shuts down or disconnects.

Back To Top

Application Settings

  • FusionVoiceClient.UseFusionAppSettings: if true, AppSettings from Fusion's PhotonAppSettings are used. Otherwise, set the values specific to this FusionVoiceClient component in the "App Settings" foldout.

  • FusionVoiceClient.UseFusionAuthValues: if true, the Voice client will use the same AuthenticationValues as Fusion's PhotonNetwork.AuthValues. 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 FusionVoiceClient.Client.AuthValues) before connecting the voice client.

Back To Top

Streaming

  • FusionVoiceClient.PrimaryRecorder: an object with a Recorder component useful for scenarios where there is only one outgoing stream per client.

  • FusionVoiceClient.UsePrimaryRecorder: if true, the Recorder attached to the Primary Recorder object will be automatically initialized and used for streaming. The Recorder will not be bound to any network object. Uncheck it if you are using VoiceNetworkObject prefabs.

  • FusionVoiceClient.SpeakerPrefab: a prefab that will be used to instantiate a speaker object when a new incoming stream is detected and the object that this stream belongs to does not have a Speaker in its hierarchy. Set it if you are not using VoiceNetworkObject prefabs or these prefabs do not have a Speaker component. Must contain a Speaker component.

Back To Top

VoiceNetworkObject

The component assigned to the VoiceNetworkObject prefab and responsible for setting up the Recorder and Speaker. On the streaming side, it starts the Recorder found in the prefab hierarchy, or if not found, FusionVoiceClient.PrimaryRecorder. On the receiving side, It starts the Speaker found in the prefab hierarchy, or if not found, instantiates it from FusionVoiceClient.SpeakerPrefab.

Back To Top

Import Instructions

Please check the minimal required Unity version of the Fusion SDK used. Currently it is Unity 2020.3.x and at least the same version is required for Voice for Fusion integration.

Import Fusion

This part can be skipped if the project already has Fusion.

  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 the project already has Photon Voice.

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

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

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

Scene Setup

  1. Set Voice AppId in the AppSettings from Fusion's PhotonAppSettings.
  2. Add a FusionVoiceClient to the object with a NetworkRunner attached to it.
  3. Add an object with a Recorder to the scene and assign it to FusionVoiceClient.PrimaryRecorder.
  4. Create a prefab with a Speaker and assign it to FusionVoiceClient.SpeakerPrefab.

Back To Top

Prefab Setup

  1. Add a VoiceNetworkObject to the Fusion prefab object that has a NetworkBehaviour attached to it.
  2. Make sure Fusion is aware of the prefab via the shortcut menu item: "Fusion" -> "Rebuild Object Table".

See samples for Fusion or Fusion Impostor sample for more information.

To Document Top