S&box Wiki

Revision Difference

Voice#547573

<cat>Code.Misc</cat>⤶ The Voice API allows the developer to change various properties and behaviour of voice chat.⤶ ⤶ # Usage⤶ ## OnVoicePlayed⤶ You can override the OnVoicePlayed() method in Sandbox.Game to control what happens when other clients' voice data is coming through. Note that OnVoicePlayed is not called for your own client - only other clients.⤶ ```csharp⤶ public override void OnVoicePlayed( Client cl )⤶ {⤶ Log.Info( $"{cl.Name} is speaking!" );⤶ VoiceList.Current?.OnVoicePlayed( cl.PlayerId, cl.VoiceLevel );⤶ }⤶ ```⤶ ⤶ By default, OnVoicePlayed populates a base UI component called VoiceList (base/UI/VoiceChat). By overriding OnVoicePlayed(), you could ensure no UI shows, use your own custom UI, and more.⤶ ⤶ ## Client Properties⤶ You can access various properties on a [client](https://asset.party/api/Sandbox.Client.TimeSinceLastVoice) pertaining to voice. These allow you to access the voice properties of any client in your game.⤶ ```csharp⤶ // VoiceStereo determines whether voice chat should be global or proximity-based.⤶ cl.VoiceStereo = false;⤶ ```⤶ ⤶ ## Sandbox.Voice⤶ ⤶ [Sandbox.Voice](https://asset.party/api/Sandbox.Voice) allows you to access additional properties based on the local client's voice.