UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VoiceConfig.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "Engine/Engine.h"
14#include "VoiceConfig.generated.h"
15
16#if PLATFORM_WINDOWS
17#define USE_DEFAULT_VOICE_SAMPLE_RATE 0
18#else
19#define USE_DEFAULT_VOICE_SAMPLE_RATE 1
20#endif
21
23#define VOICE_CONFIG_LEAK_WARNING_THRESHOLD 48
24
25
34
36{
37 static const Audio::EPeakMode::Type LevelDetectionMode = Audio::EPeakMode::Type::Peak;
38 static const bool IsAnalog = false;
39
40 static const int32 PacketBufferSlack = 20;
41}
42
44
45USTRUCT(BlueprintType)
47{
49
50 // Optionally attach the voice source to a Scene Component to give the appearance
51 // that the voice is coming from that scene component.
52 // If this is not set, the voice will not be spatialized.
53 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Audio|Voice|Spatialization")
54 TObjectPtr<USceneComponent> ComponentToAttachTo;
55
56 // Optional attenuation settings to attach to this player's voice.
57 // This should only be used when ComponentToAttachTo is set.
58 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Audio|Voice|Spatialization")
59 TObjectPtr<USoundAttenuation> AttenuationSettings;
60
61 // Optional audio effects to apply to this player's voice.
62 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Audio|Voice|Effects")
64
66 : ComponentToAttachTo(nullptr)
67 , AttenuationSettings(nullptr)
68 , SourceEffectChain(nullptr)
69 {
70 }
71};
72
73
74UCLASS(Blueprintable, BlueprintType, ClassGroup = VOIP, meta = (BlueprintSpawnableComponent, ShortTooltip = "A VOIPTalker is a component that can be used to control the audio characteristics of a player's voice."), MinimalAPI)
76{
78
79public:
80 // Constructor and destructor.
82 ENGINE_API virtual ~UVOIPTalker();
83
84 // function for creating and registering a UVOIPTalker.
85 UFUNCTION(BlueprintCallable, Category = "Audio|Voice|Notification")
86 static ENGINE_API UVOIPTalker* CreateTalkerForPlayer(APlayerState* OwningState);
87
88 // This function sets up this talker with a specific player.
89 // It is necessary to use this to properly control a specific player's voice
90 // and receive events.
91 UFUNCTION(BlueprintCallable, Category = "Audio|Voice|Notification")
92 ENGINE_API void RegisterWithPlayerState(APlayerState* OwningState);
93
94 // Get the current level of how loud this player is speaking. Will return 0.0
95 // if player is not talking.
96 UFUNCTION(BlueprintCallable, Category = "Audio|Voice|Notification")
97 ENGINE_API float GetVoiceLevel();
98
99 // Override this function to implement custom functionality when this player begins talking.
100 virtual void OnTalkingBegin(UAudioComponent* AudioComponent) { BPOnTalkingBegin(AudioComponent); };
101
102 // Override this function to implement custom functionality when this player stops talking.
103 virtual void OnTalkingEnd() { BPOnTalkingEnd(); };
104
105 // This is used by the VoiceEngineImpl to notify this VOIPTalker what the voice audio component's current level is.
106 // This should not be called outside of the voice engine.
107 ENGINE_API void OnAudioComponentEnvelopeValue(const UAudioComponent* InAudioComponent, const float EnvelopeValue);
108
109 // Overridden to ensure that instances of UVOIPTalker unregister themselves from the static VoiceTalkerMap.
110 ENGINE_API virtual void OnComponentDestroyed(bool bDestroyingHierarchy) override;
111
112protected:
113 // Blueprint native event for when this player starts speaking.
114 UFUNCTION(BlueprintNativeEvent, meta = (DisplayName = "Begin Talking"), Category = "Audio|Voice|Notification")
115 ENGINE_API void BPOnTalkingBegin(UAudioComponent* AudioComponent);
116
117 // Blueprint native event for when this player stops speaking.
118 UFUNCTION(BlueprintNativeEvent, meta = (DisplayName = "End Talking"), Category = "Audio|Voice|Notification")
119 ENGINE_API void BPOnTalkingEnd();
120
121private:
122 // This function removes this player component from the VoiceTalkerMap.
123 ENGINE_API void UnregisterFromVoiceTalkerMap();
124
125public:
126 // Configurable settings for this player's voice. When set, this will update the next time the player speaks.
127 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Voice")
129
130private:
131 // Cached player ID from the APlayerController.
132 FUniqueNetIdWrapper PlayerId;
133
134 // This volume level is set by the Audio Component's OnEnvelopeValueSet delegate.
135 float CachedVolumeLevel;
136
137 // whether this component has been registered.
138 uint8 bIsRegistered : 1;
139};
140
141
142
143UCLASS(MinimalAPI)
145{
147
148public:
149 // Returns the voice sample rate specified in Audio Settings.
150 static ENGINE_API int32 GetVoiceSampleRate();
151 static ENGINE_API int32 GetVoiceNumChannels();
152
153 // Returns the max voice data size per packet, uncompressed, and compressed based on the voice sample rate specified in Audio Settings.
154 static ENGINE_API uint32 GetMaxVoiceDataSize();
155 static ENGINE_API uint32 GetMaxUncompressedVoiceDataSizePerChannel();
156 static ENGINE_API uint32 GetMaxCompressedVoiceDataSize();
157
158 // Returns the amount of time that must pass since a VOIP talker has been updated before it's queued data is reset.
159 static ENGINE_API float GetRemoteTalkerTimeoutDuration();
160
161 // Returns the desired encoding type. Currently not exposed as a configured settings.
162 static ENGINE_API EAudioEncodeHint GetAudioEncodingHint();
163
164 // Returns the amount of seconds to spend buffering specified by AudioSettings.
165 static ENGINE_API float GetBufferingDelay();
166
167 // Returns the noise gate threshold we use for incoming audio.
168 static ENGINE_API float GetVoiceNoiseGateLevel();
169
170 // returns the amount of packets to allocate memory for based on the buffering delay.
171 static ENGINE_API int32 GetNumBufferedPackets();
172
173 // returns pointer to a player state
174 static ENGINE_API APlayerState* GetPlayerStateFromUniqueNetId(UWorld* InWorld, const FUniqueNetIdWrapper& InPlayerId);
175
176 // This function sets the Mic threshold for VOIP chat.
177 UFUNCTION(BlueprintCallable, Category = "Audio|Voice|Mic")
178 static ENGINE_API void SetMicThreshold(float InThreshold);
179
180 // Sets up a VOIP talker to be accessed for a specific player when they are talking.
181 static ENGINE_API void SetVOIPTalkerForPlayer(const FUniqueNetIdWrapper& InPlayerId, UVOIPTalker* InTalker);
182
183 // These functions retrieve a pointer to a VOIPTalker associated with a specific player, if there is one available.
184 static ENGINE_API UVOIPTalker* GetVOIPTalkerForPlayer(const FUniqueNetIdWrapper& InUniqueId, FVoiceSettings& OutSettings, UWorld* InWorld = nullptr, APlayerState** OutPlayerState = nullptr);
185 static ENGINE_API UVOIPTalker* GetVOIPTalkerForPlayer(const FUniqueNetIdWrapper& InPlayerId);
186
187 // This is used to check whether a VOIPTalker has been removed from the TalkerMap before using it.
188 static ENGINE_API bool IsVOIPTalkerStillAlive(UVOIPTalker* InTalker);
189
190 // Removes a player's voice talker. This is done by a UVOIPTalker on destruction.
191 static ENGINE_API void ResetPlayerVoiceTalker(APlayerState* InPlayerState);
192 static ENGINE_API void ResetPlayerVoiceTalker(const FUniqueNetIdWrapper& InPlayerId);
193
194 //Clear all pointers to VOIPTalkers.
195 static ENGINE_API void ClearAllSettings();
196
197private:
198
199 static TMap<FUniqueNetIdWrapper, UVOIPTalker*> VoiceTalkerMap;
200
201};
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define UFUNCTION(...)
Definition ObjectMacros.h:745
#define UCLASS(...)
Definition ObjectMacros.h:776
#define USTRUCT(...)
Definition ObjectMacros.h:746
EAudioEncodeHint
Definition VoiceConfig.h:28
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition PlayerState.h:42
Definition UObjectGlobals.h:1292
Definition UnrealString.h.inl:34
Definition ActorComponent.h:152
Definition BlueprintFunctionLibrary.h:16
Definition SoundAttenuation.h:444
Definition SoundEffectSource.h:49
Definition VoiceConfig.h:145
Definition VoiceConfig.h:76
virtual void OnTalkingEnd()
Definition VoiceConfig.h:103
virtual void OnTalkingBegin(UAudioComponent *AudioComponent)
Definition VoiceConfig.h:100
Definition World.h:918
Definition Voice.Build.cs:7
Type
Definition EnvelopeFollower.h:17
@ Peak
Definition EnvelopeFollower.h:20
NO_LOGGING.
Definition AudioMixerPlatformAndroid.cpp:53
Definition VoiceConfig.h:36
Definition CoreOnline.h:504
Definition VoiceConfig.h:47
Definition ObjectPtr.h:488