Voice Chat
To use the voice chat system provided by MPE4S, simply enable SteamManager.UseVoice
. If you are using a different voice system already, disable SteamManager.UseVoice
which will disable all other voice settings included with MPE4S.
Voice audio is sent over a dedicated network channel which you can define with SteamManager.VoiceChannel
that defaults to 1
. You cannot send other non-voice data over the SteamManager.VoiceChannel
, and it is your responsibility to make sure you do not do so.
Enable and disable your microphone with SteamManager.MicEnabled
. Use SteamManager.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.
SteamManager.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 SteamManager.VoiceRate
can be automatically determined in two ways:
- Steam - If
SteamManager.VoiceRate
is lower than11,025
, Steam will automatically get an optimal sample rate for performance but audio quality may be poorer. - Unity - If
SteamManager.VoiceRate
is 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 Steam > Settings
and then click on Voice
and check your Voice Input Device
.
Sending
You can configure which players in the lobby should receive your voice by using SteamManager.VoiceRecipientsAll()
, SteamManager.VoiceRecipientsNobody()
, SteamManager.VoiceRecipientsSet(ulong)
, SteamManager.VoiceRecipientsSet(IEnumerable<ulong>)
, SteamManager.VoiceRecipientsAdd(ulong)
, SteamManager.VoiceRecipientsAdd(IEnumerable<ulong>)
, SteamManager.VoiceRecipientsRemove(ulong)
, and SteamManager.VoiceRecipientsRemove(IEnumerable<ulong>)
. You can see who you are currently sending your voice to with SteamManager.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 SteamManager.VoiceRecipients
is updated, the SteamManager.OnVoiceRecipients
callback is invoked.
Playback
To play back audio for a user, simply assign an AudioSource
to SteamUser.Voice
on a SteamUser
component of that user. The SteamUser
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 SteamUser
component's voice, simply set or unset SteamUser.Voice
, with NULL disabling voice playback.
To reduce the need of manually assigning AudioSource
components to SteamUser.Voice
fields, the SteamManager
component has a helpful property SteamManager.VoiceMode
. Setting this SteamManager.VoiceMode
will automatically configure voice playback for all SteamUser
components based on the desired settings.
Filters
To create a voice filter, create a class which extends from SteamVoiceFilter
. Each SteamVoiceFilter
can be assigned either globally or directly to individual SteamUser
components. When assigned as global filters, the SteamFilter.Order
property configures the order in which voice filters are applied, with lower values being applied first. When assigned directly to SteamUser
components, their order is manually defined.
Instead of immediately trying to create a filter by extending SteamVoiceFilter
, 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 SteamUser
component, implement the ISteamVoice
interface and handle registering, unregistering, and listening to voice setting changes with the SteamManager
component.