Voice - Fusion Integration
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.
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.
Application Settings
FusionVoiceClient.UseFusionAppSettings
: if true,AppSettings
from Fusion'sPhotonAppSettings
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 sameAuthenticationValues
as Fusion'sPhotonNetwork.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 theAuthenticationValues
of the voice client manually (viaFusionVoiceClient.Client.AuthValues
) before connecting the voice client.
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 usingVoiceNetworkObject
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 usingVoiceNetworkObject
prefabs or these prefabs do not have a Speaker component. Must contain a Speaker component.
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
.
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.
- Download and import Fusion here.
- Open the Photon App Settings using the menu item at
Fusion > Realtime Settings
. - Get AppId of type Fusion and set it in Realtime Settings: "App Id Fusion".
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"
Update Weaver Settings
- Open "Network Project Config" via menu item shortcut:
Fusion > Network Project Config
- Unfold or open
Config
- Unfold or open
Weaving Settings
- Under
Assemblies To Weave
, add one more item to the list of assembly to weave via "+" button - In the newly created item, from the dropdown list of available assemblies select "PhotonVoice.Fusion"
- At the bottom, hit
Apply
.
Suggested Workflow
Scene Setup
- Set Voice AppId in the AppSettings from Fusion's
PhotonAppSettings
. - Add a
FusionVoiceClient
to the object with aNetworkRunner
attached to it. - Add an object with a Recorder to the scene and assign it to
FusionVoiceClient.PrimaryRecorder
. - Create a prefab with a Speaker and assign it to
FusionVoiceClient.SpeakerPrefab
.
Prefab Setup
- Add a
VoiceNetworkObject
to the Fusion prefab object that has aNetworkBehaviour
attached to it. - 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.
Back to top