4#include "CoreMinimal.h"
5#include "Subsystems/GameInstanceSubsystem.h"
9#include "VoxtaClient.generated.h"
16class UVoxtaAudioPlayback;
48UCLASS(DisplayName =
"Voxta Client", Category =
"Voxta")
53#pragma region delegate declarations
89 UPROPERTY(BlueprintAssignable, Category =
"Voxta", meta = (IsBindableEvent =
"True"))
95 UPROPERTY(BlueprintAssignable, Category =
"Voxta", meta = (IsBindableEvent =
"True"))
105 UPROPERTY(BlueprintAssignable, Category =
"Voxta", meta = (IsBindableEvent =
"True"))
111 UPROPERTY(BlueprintAssignable, Category =
"Voxta", meta = (IsBindableEvent =
"True"))
117 UPROPERTY(BlueprintAssignable, Category =
"Voxta", meta = (IsBindableEvent =
"True"))
123 UPROPERTY(BlueprintAssignable, Category =
"Voxta", meta = (IsBindableEvent =
"True"))
129 UPROPERTY(BlueprintAssignable, Category =
"Voxta", meta = (IsBindableEvent =
"True"))
139 UPROPERTY(BlueprintAssignable, Category =
"Voxta", meta = (IsBindableEvent =
"True"))
149 UPROPERTY(BlueprintAssignable, Category =
"Voxta", meta = (IsBindableEvent =
"True"))
155 UPROPERTY(BlueprintAssignable, Category =
"Voxta", meta = (IsBindableEvent =
"True"))
161#pragma region UGameInstanceSubsystem overrides
164 virtual void Initialize(FSubsystemCollectionBase& collection)
override;
169#pragma region public API
178 UFUNCTION(BlueprintCallable, Category =
"Voxta")
187 UFUNCTION(BlueprintCallable, Category =
"Voxta")
198 UFUNCTION(BlueprintCallable, Category =
"Voxta")
205 UFUNCTION(BlueprintCallable, Category =
"Voxta")
209 UFUNCTION(BlueprintPure, Category =
"Voxta")
215 UFUNCTION(BlueprintCallable, Category =
"Voxta")
222 UFUNCTION(BlueprintCallable, Category =
"Voxta")
233 UFUNCTION(BlueprintCallable, Category =
"Voxta")
234 void SendUserInput(const FString& inputText,
bool generateReply = true,
bool characterActionInference = false);
237 UFUNCTION(BlueprintPure, Category =
"Voxta")
241 UFUNCTION(BlueprintPure, Category =
"Voxta")
245 UFUNCTION(BlueprintPure, Category =
"Voxta")
249 UFUNCTION(BlueprintPure, Category =
"Voxta")
253 UFUNCTION(BlueprintPure, Category =
"Voxta")
261 UFUNCTION(BlueprintPure, Category =
"Voxta")
265 UFUNCTION(BlueprintPure, Category =
"Voxta")
282 UFUNCTION(BlueprintPure, Category =
"Voxta")
292 UFUNCTION(BlueprintPure, Category =
"Voxta")
296 UFUNCTION(BlueprintPure, Category =
"Voxta")
320 UFUNCTION(BlueprintPure, Category =
"Voxta")
324 UFUNCTION(BlueprintPure, Category =
"Voxta")
328 UFUNCTION(BlueprintPure, Category =
"Voxta")
341 UFUNCTION(BlueprintCallable, Category =
"Voxta")
345 UFUNCTION(BlueprintPure, Category =
"Voxta")
351 const FString SEND_MESSAGE_EVENT_NAME = TEXT(
"SendMessage");
352 const FString RECEIVE_MESSAGE_EVENT_NAME = TEXT(
"ReceiveMessage");
359 FDelegateHandle globalAudioPlaybackHandle;
360 bool m_enableGlobalAudioFallback = true;
369 FGuid m_mainAssistantId;
370 FString m_hostAddress;
375 TArray<TUniquePtr<const
FAiCharData>> m_characterList;
376 TMap<FGuid, TWeakObjectPtr<UVoxtaAudioPlayback>> m_registeredCharacterAudioPlaybackComps;
377 TMap<FGuid, FDelegateHandle> m_audioPlaybackHandles;
380#pragma region private API
383 void StartListeningToServer();
385#pragma region IHubConnection listeners
388 void OnReceivedMessage(
const TArray<FSignalRValue>& arguments);
392 void OnConnectionError(
const FString& error);
428 bool HandleResponseHelper(
const ServerResponseBase* response,
const FString& logMessage,
429 bool (
UVoxtaClient::* handler)(
const T&),
bool isSensitive);
431#pragma region VoxtaServer response handlers
434 bool HandleResponse(
const TMap<FString, FSignalRValue>& responseData);
459 void StopChatInternal();
467 void NotifyAudioPlaybackComplete(
const FGuid& messageId);
485 const TUniquePtr<const FAiCharData>* GetAiCharacterDataById(
const FGuid& charId)
const;
VoxtaClientState
VoxtaClientState Contains the possible states that can be reported by the VoxtaClient when polled.
Definition VoxtaClientState.h:16
Definition VoxtaGlobalAudioPlaybackHolder.h:11
Audio2FaceRESTHandler Manages the HTTP REST API for A2F_headless mode.
Definition Audio2FaceRESTHandler.h:18
Represents the result of a SignalR method invocation, containing either a value or error information.
Definition IHubConnection.h:34
Represents a value that can be sent to or received from a SignalR hub.
Definition SignalRValue.h:34
Interface for a SignalR hub connection that enables real-time communication with a SignalR server.
Definition IHubConnection.h:110
TexturesCacheHandler Internal class which handles asynchronous fetching, decoding,...
Definition TexturesCacheHandler.h:19
UVoxtaClient Main public-facing subsystem for Voxta integration.
Definition VoxtaClient.h:50
FVoxtaClientChatContextUpdated VoxtaClientChatContextUpdatedEvent
Event fired when the server has finished transcribing speech, it contains the final version of whatev...
Definition VoxtaClient.h:130
UVoxtaAudioInput * GetVoiceInputHandler() const
Definition VoxtaClient.cpp:361
FVoxtaClientCharMessageRemovedNative VoxtaClientCharMessageRemovedEventNative
Static Event variation of VoxtaClientCharMessageRemovedEvent.
Definition VoxtaClient.h:114
virtual void Initialize(FSubsystemCollectionBase &collection) override
Initialization of the instance of the system.
Definition VoxtaClient.cpp:23
void StartConnection(const FString &ipv4Address, int port)
Start the VoxtaClient and connect to the Voxta SignalR hub.
Definition VoxtaClient.cpp:56
bool IsLogCensorActive() const
Definition VoxtaClient.cpp:455
void UpdateChatContext(const FString &newContext)
Update the context of the current chat session.
Definition VoxtaClient.cpp:173
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FVoxtaClientStateChanged, VoxtaClientState, newState)
Delegate fired when the VoxtaClient state changes.
bool TryRegisterPlaybackHandler(const FGuid &characterId, TWeakObjectPtr< UVoxtaAudioPlayback > playbackHandler)
Register the playback handler for this specific character, this is needed as we need to know if we wa...
Definition VoxtaClient.cpp:283
DECLARE_MULTICAST_DELEGATE_OneParam(FVoxtaClientChatSessionStoppedNative, const FChatSession &)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FVoxtaClientChatContextUpdated, const FString &, newContext)
Delegate fired when the context of a chatsession is updated.
FVoxtaClientSpeechTranscribed VoxtaClientSpeechTranscribedCompleteEvent
Event fired when the server has finished transcribing speech, it contains the final version of whatev...
Definition VoxtaClient.h:124
void SetCensoredLogs(bool isCensorActive)
Enable or disable log censoring for sensitive logs.
Definition VoxtaClient.cpp:450
void SendUserInput(const FString &inputText, bool generateReply=true, bool characterActionInference=false)
Send user input text to the server as part of the current chat session.
Definition VoxtaClient.cpp:186
FVoxtaClientChatContextUpdatedNative VoxtaClientChatContextUpdatedEventNative
Static Event variation of VoxtaClientSpeechTranscribedCompleteEvent.
Definition VoxtaClient.h:132
FGuid GetMainAssistantId() const
Definition VoxtaClient.cpp:390
FVoxtaClientAudioPlaybackRegistered VoxtaClientAudioPlaybackRegisteredEvent
Event fired when a playbackHandler has registered itself & claimed audioplayback for that character.
Definition VoxtaClient.h:156
DECLARE_MULTICAST_DELEGATE_OneParam(FVoxtaClientStateChangedNative, VoxtaClientState)
Native C++ delegates for the above events.
FVoxtaClientCharacterRegisteredNative VoxtaClientCharacterRegisteredEventNative
Static Event variation of VoxtaClientCharacterRegisteredEvent.
Definition VoxtaClient.h:98
FVoxtaClientSpeechTranscribedNative VoxtaClientSpeechTranscribedCompleteEventNative
Static Event variation of VoxtaClientSpeechTranscribedCompleteEvent.
Definition VoxtaClient.h:126
FVoxtaClientCharMessageAddedNative VoxtaClientCharMessageAddedEventNative
Static Event variation of VoxtaClientCharMessageAddedEvent.
Definition VoxtaClient.h:108
FVoxtaClientChatSessionStarted VoxtaClientChatSessionStartedEvent
Event fired when the chat session has begun.
Definition VoxtaClient.h:140
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FVoxtaClientCharMessageAdded, const FBaseCharData &, sender, const FChatMessage &, message)
Delegate fired when a chat message is added.
int GetServerPort() const
Definition VoxtaClient.cpp:356
FVoxtaClientStateChangedNative VoxtaClientStateChangedEventNative
Static Event variation of VoxtaClientStateChangedEvent.
Definition VoxtaClient.h:92
FVoxtaClientChatSessionStoppedNative VoxtaClientChatSessionStoppedEventNative
Static Event variation of VoxtaClientChatSessionStoppedEvent.
Definition VoxtaClient.h:152
void StartChatWithCharacter(const FGuid &charId, const FString &context=TEXT(""))
Tell the server to initiate a chat session with the character of the provided ID.
Definition VoxtaClient.cpp:121
bool IsGlobalAudioFallbackActive() const
Definition VoxtaClient.cpp:460
const UVoxtaAudioPlayback * GetRegisteredAudioPlaybackHandlerForID(const FGuid &characterId) const
Try to retrieve a pointer to the UVoxtaAudioPlayback that has claimed playback for the provided chara...
Definition VoxtaClient.cpp:395
FVoxtaClientSpeechTranscribed VoxtaClientSpeechTranscribedPartialEvent
Event fired when the server is in progress of transcribing speech, it contains the current version of...
Definition VoxtaClient.h:118
FVoxtaClientChatSessionStopped VoxtaClientChatSessionStoppedEvent
Event fired when the chat session has ended.
Definition VoxtaClient.h:150
TWeakPtr< Audio2FaceRESTHandler > GetA2FHandler() const
Definition VoxtaClient.cpp:445
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FVoxtaClientSpeechTranscribed, const FString &, message)
Delegate fired when speech is transcribed.
void SetGlobalAudioFallbackEnabled(bool newState)
Enable or disable the global audio fallback handler (for characters without a specific handler).
Definition VoxtaClient.cpp:149
FVoxtaClientCharMessageAdded VoxtaClientCharMessageAddedEvent
Event fired when the VoxtaClient is notified by the server that a message is added.
Definition VoxtaClient.h:106
TArray< FAiCharData > GetAvailableAiCharactersCopy() const
Definition VoxtaClient.cpp:493
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FVoxtaClientChatSessionStarted, const FChatSession &, chatSession)
Delegate fired when a chat session starts.
FVoxtaClientCharacterRegistered VoxtaClientCharacterRegisteredEvent
Event fired when the internal VoxtaClient has loaded the metadata of an AiCharData.
Definition VoxtaClient.h:96
DECLARE_MULTICAST_DELEGATE_OneParam(FVoxtaClientCharMessageRemovedNative, const FChatMessage &)
void TryFetchAndCacheCharacterThumbnail(const FGuid &baseCharacterId, FDownloadedTextureDelegateNative onThumbnailFetched)
Asynchronously fetch and cache the thumbnail for a character.
Definition VoxtaClient.cpp:234
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FVoxtaClientCharacterRegistered, const FAiCharData &, charData)
Delegate fired when a character is registered.
DECLARE_MULTICAST_DELEGATE_OneParam(FVoxtaClientChatSessionStartedNative, const FChatSession &)
FVoxtaVersionData GetServerVersionCopy() const
Definition VoxtaClient.cpp:418
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FVoxtaClientChatSessionStopped, const FChatSession &, chatSession)
Delegate fired when a chat session stops.
const FString & GetServerAddress() const
Definition VoxtaClient.cpp:351
FAiCharData GetAiCharacterDataCopyById(const FGuid &characterId) const
Try to retrieve a copy of the characterData for the provided characterId.
Definition VoxtaClient.cpp:478
FChatSession GetChatSessionCopy() const
Definition VoxtaClient.cpp:408
DECLARE_MULTICAST_DELEGATE_TwoParams(FVoxtaClientCharMessageAddedNative, const FBaseCharData &, const FChatMessage &)
void Disconnect(bool silent=false)
Disconnect from the VoxtaServer and clean up all resources.
Definition VoxtaClient.cpp:94
FVoxtaClientSpeechTranscribedNative VoxtaClientSpeechTranscribedPartialEventNative
Static Event variation of VoxtaClientSpeechTranscribedPartialEvent.
Definition VoxtaClient.h:120
DECLARE_MULTICAST_DELEGATE_TwoParams(FVoxtaClientAudioPlaybackRegisteredNative, const UVoxtaAudioPlayback *, const FGuid &)
FString GetBrowserUrlForCharacter(const FGuid &aiCharacterId) const
Get the browser URL for a given AI character.
Definition VoxtaClient.cpp:380
FVoxtaClientStateChanged VoxtaClientStateChangedEvent
Event fired when the internal VoxtaClient has finished transitioning to a different state.
Definition VoxtaClient.h:90
bool IsMatchingAPIVersion() const
Definition VoxtaClient.cpp:427
DECLARE_MULTICAST_DELEGATE_OneParam(FVoxtaClientCharacterRegisteredNative, const FAiCharData &)
FGuid GetUserId() const
Definition VoxtaClient.cpp:371
VoxtaClientState GetCurrentState() const
Definition VoxtaClient.cpp:366
FVoxtaClientChatSessionStartedNative VoxtaClientChatSessionStartedEventNative
Static Event variation of VoxtaClientChatSessionStartedEvent.
Definition VoxtaClient.h:142
void StopActiveChat()
Tell the server to stop the ongoing chat session and clean up the relevant dependencies.
Definition VoxtaClient.cpp:168
DECLARE_MULTICAST_DELEGATE_OneParam(FVoxtaClientSpeechTranscribedNative, const FString &)
FVoxtaClientAudioPlaybackRegisteredNative VoxtaClientAudioPlaybackRegisteredEventNative
Static Event variation of VoxtaClientAudioPlaybackRegisteredEvent.
Definition VoxtaClient.h:158
DECLARE_MULTICAST_DELEGATE_OneParam(FVoxtaClientChatContextUpdatedNative, const FString &)
FVoxtaClientCharMessageRemoved VoxtaClientCharMessageRemovedEvent
Event fired when the server has notified the client that a message has been removed.
Definition VoxtaClient.h:112
bool TryUnregisterPlaybackHandler(const FGuid &characterId)
Unregister the audio playback handler for a character.
Definition VoxtaClient.cpp:328
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FVoxtaClientCharMessageRemoved, const FChatMessage &, message)
Delegate fired when a chat message is removed.
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FVoxtaClientAudioPlaybackRegistered, const UVoxtaAudioPlayback *, playbackHandler, const FGuid &, characterId)
Delegate fired when an audio playback handler is registered.
const FChatSession * GetChatSession() const
Definition VoxtaClient.cpp:436
virtual void Deinitialize() override
Deinitialization of the instance of the system.
Definition VoxtaClient.cpp:35
VoxtaApiRequestHandler Internal helper class to serialize request data which then can be sent to Voxt...
Definition VoxtaApiRequestHandler.h:17
VoxtaApiResponseHandler Stateless utility class for deserializing and mapping raw SignalR responses f...
Definition VoxtaApiResponseHandler.h:33
VoxtaLogger Internal class that enables the automatic printing of warnings and errors in the VoxtaLog...
Definition VoxtaLogger.h:15
FAiCharData Read-only data struct containing all the relevant information for an AI character.
Definition AiCharData.h:21
FBaseCharData Read-only data struct containing all the universal information fields for a character.
Definition BaseCharData.h:17
FChatMessage Represents a single message in a chat conversation, containing both text and audio data.
Definition ChatMessage.h:16
FChatSession Data struct containing all the relevant information regarding a chat session between the...
Definition ChatSession.h:20
FUserCharData Read-only data struct containing all the relevant information for the character represe...
Definition UserCharData.h:20
FVoxtaVersionData Data struct for managing version compatibility between the UnrealVoxta client and V...
Definition VoxtaVersionData.h:17
ServerResponseBase Abstract read-only data struct that all responses from the VoxtaServer derive from...
Definition ServerResponseBase.h:15
ServerResponseCharacterList Read-only data struct containing the relevant data of the 'charactersList...
Definition ServerResponseCharacterList.h:15
ServerResponseChatClosed Read-only data struct containing the relevant data of the 'chatClosed' respo...
Definition ServerResponseChatClosed.h:14
ServerResponseChatMessageBase Abstract read-only data struct containing the shared relevant data for ...
Definition ServerResponseChatMessageBase.h:15
ServerResponseChatSessionError Read-only data struct containing the relevant data of the 'chatSession...
Definition ServerResponseChatSessionError.h:14
ServerResponseChatStarted Read-only data struct containing the relevant data of the 'chatStarted' res...
Definition ServerResponseChatStarted.h:15
ServerResponseChatUpdate Read-only data struct containing the relevant data of the 'update' response ...
Definition ServerResponseChatUpdate.h:14
ServerResponseConfiguration Read-only data struct containing the relevant data of the 'configuration'...
Definition ServerResponseConfiguration.h:15
ServerResponseContextUpdated Read-only data struct containing the relevant data of the 'ContextUpdate...
Definition ServerResponseContextUpdated.h:14
ServerResponseError Read-only data struct containing the relevant data of the 'error' response from t...
Definition ServerResponseError.h:14
ServerResponseSpeechTranscription Read-only data struct containing the relevant data of the 'SpeechTr...
Definition ServerResponseSpeechTranscription.h:14
ServerResponseWelcome Read-only data struct containing the relevant data of the 'welcome' response fr...
Definition ServerResponseWelcome.h:15