S&box Wiki

Revision Difference

Voice#560508

<cat>Code.Player</cat>⤶ The Voice API allows the developer to change various properties and behaviour of voice chat.⤶ <deprecated>This page needs a rewrite for the scene system due to mentions of client / server and entities</deprecated>⤶ ⤶ # 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( IClient cl )⤶ {⤶ Log.Info( $"{cl.Name} is speaking!" );⤶ VoiceList.Current?.OnVoicePlayed( cl.SteamId, cl.VoiceLevel );⤶ }⤶ ```⤶ ⤶ ⤶ ⤶ ## Voice UI⤶ ### Voice List⤶ By default, OnVoicePlayed populates a base UI component called VoiceList (base/UI/VoiceChat) as long as it exists in your game's UI (i.e adding `<VoiceList />` in a template or adding the class as a child in C#). By overriding OnVoicePlayed, you could customize what happens when a client hears voice however you choose.⤶ <upload src="ae247/8da967cb4a55ce0.png" size="160281" name="image.png" />⤶ ⤶ ### Voice Speaker⤶ VoiceSpeaker is another base UI component that shows when you are speaking instead of others.⤶ <upload src="ae247/8da967d59e05d0c.png" size="27376" name="image.png" />⤶ ⤶ ## 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.