Voice Chat
Voice audio is sent over a dedicated network channel which you can define with KaijuMultiplayerManager.VoiceChannel that defaults to 1. You cannot send other non-voice data over the KaijuMultiplayerManager.VoiceChannel, and it is your responsibility to make sure you do not do so.
Enable and disable your microphone with KaijuMultiplayerManager.MicEnabled. Use KaijuMultiplayerManager.ControlSteamFriendsVoice to handle if, when your microphone is enabled in-game, you want to mute any other voice chat you may be doing through your Steam application itself.
KaijuMultiplayerManager.VoiceRate controls your audio decoding rate. You can manually specify a value between 11,025 and 48,000, or let it be automatically determined. Your KaijuMultiplayerManager.VoiceRate can be automatically determined in two ways:
- Steam - If
KaijuMultiplayerManager.VoiceRateis lower than11,025, Steam will automatically get an optimal sample rate for performance but audio quality may be poorer. - Unity - If
KaijuMultiplayerManager.VoiceRateis greater than48,000, the sample rate will be that which the application is currently outputting.
The voice system works based on what microphone is configured in your Steam settings. To see this, open the Steam app and from the top menu go to KaijuSolutions.MultiplayerEngine > Settingsand then click onVoiceand check yourVoice Input Device`.
Sending
You can configure which players in the lobby should receive your voice by using KaijuMultiplayerManager.VoiceRecipientsAll(), KaijuMultiplayerManager.VoiceRecipientsNobody(), KaijuMultiplayerManager.VoiceRecipientsSet(ulong), KaijuMultiplayerManager.VoiceRecipientsSet(IEnumerable<ulong>), KaijuMultiplayerManager.VoiceRecipientsAdd(ulong), KaijuMultiplayerManager.VoiceRecipientsAdd(IEnumerable<ulong>), KaijuMultiplayerManager.VoiceRecipientsRemove(ulong), and KaijuMultiplayerManager.VoiceRecipientsRemove(IEnumerable<ulong>). You can see who you are currently sending your voice to with KaijuMultiplayerManager.VoiceRecipients, with NULL meaning you are sending your voice to everyone in the lobby and will automatically send it to any new players that join the lobby. Whenever KaijuMultiplayerManager.VoiceRecipients is updated, the KaijuMultiplayerManager.OnVoiceRecipients callback is invoked.
Playback
To play back audio for a user, simply assign an AudioSource to KaijuUser.Voice on a KaijuUser component of that user. The KaijuUser component will automatically configure the AudioSource to be set to loop, and ensure you do not manually disable looping on it. At runtime, ensure you do not manually set the audio resource of the AudioSource or stop its playback. All other fields you are free to adjust to tune the voice playback.
At any point, to enable or disable playback of a KaijuUser component's voice, simply set or unset KaijuUser.Voice, with NULL disabling voice playback.
To reduce the need of manually assigning AudioSource components to KaijuUser.Voice fields, the KaijuMultiplayerManager component has a helpful property KaijuMultiplayerManager.VoiceMode. Setting this KaijuMultiplayerManager.VoiceMode will automatically configure voice playback for all KaijuUser components based on the desired settings.
Filters
To create a voice filter, create a class which extends from KaijuVoiceFilter. Each KaijuSolutions.MultiplayerEngineVoiceFilter` can be assigned either globally or directly to individual KaijuUser components. When assigned as global filters, the KaijuSolutions.MultiplayerEngineFilter.Order` property configures the order in which voice filters are applied, with lower values being applied first. When assigned directly to KaijuUser components, their order is manually defined.
Instead of immediately trying to create a filter by extending KaijuSolutions.MultiplayerEngineVoiceFilter`, you may be able to get the desired audio effect by modifying the various properties of the AudioSource component.
Custom
For advanced users interested in custom voice playback outside of the KaijuUser component, implement the IKaijuVoice interface and handle registering, unregistering, and listening to voice setting changes with the KaijuMultiplayerManager component.
Disable Voice Chat
If you are using a different voice chat system in your project, you can disable KMPE's voice chat system by setting the DISABLE_KAIJU_VOICE preprocessor directives in your project. This will strip all code releated to KMPE's voice chat system.