diff --git a/Unreal/PS_AI_Agent/Plugins/PS_AI_Agent_ElevenLabs/Source/PS_AI_Agent_ElevenLabs/Private/ElevenLabsConversationalAgentComponent.cpp b/Unreal/PS_AI_Agent/Plugins/PS_AI_Agent_ElevenLabs/Source/PS_AI_Agent_ElevenLabs/Private/ElevenLabsConversationalAgentComponent.cpp index 3148608..5276d6a 100644 --- a/Unreal/PS_AI_Agent/Plugins/PS_AI_Agent_ElevenLabs/Source/PS_AI_Agent_ElevenLabs/Private/ElevenLabsConversationalAgentComponent.cpp +++ b/Unreal/PS_AI_Agent/Plugins/PS_AI_Agent_ElevenLabs/Source/PS_AI_Agent_ElevenLabs/Private/ElevenLabsConversationalAgentComponent.cpp @@ -155,6 +155,16 @@ void UElevenLabsConversationalAgentComponent::StopListening() UE_LOG(LogElevenLabsAgent, Log, TEXT("Microphone capture stopped.")); } +void UElevenLabsConversationalAgentComponent::SendTextMessage(const FString& Text) +{ + if (!IsConnected()) + { + UE_LOG(LogElevenLabsAgent, Warning, TEXT("SendTextMessage: not connected. Call StartConversation() first.")); + return; + } + WebSocketProxy->SendTextMessage(Text); +} + void UElevenLabsConversationalAgentComponent::InterruptAgent() { if (WebSocketProxy) WebSocketProxy->SendInterrupt(); diff --git a/Unreal/PS_AI_Agent/Plugins/PS_AI_Agent_ElevenLabs/Source/PS_AI_Agent_ElevenLabs/Private/ElevenLabsWebSocketProxy.cpp b/Unreal/PS_AI_Agent/Plugins/PS_AI_Agent_ElevenLabs/Source/PS_AI_Agent_ElevenLabs/Private/ElevenLabsWebSocketProxy.cpp index 268e9e2..67e9541 100644 --- a/Unreal/PS_AI_Agent/Plugins/PS_AI_Agent_ElevenLabs/Source/PS_AI_Agent_ElevenLabs/Private/ElevenLabsWebSocketProxy.cpp +++ b/Unreal/PS_AI_Agent/Plugins/PS_AI_Agent_ElevenLabs/Source/PS_AI_Agent_ElevenLabs/Private/ElevenLabsWebSocketProxy.cpp @@ -126,6 +126,22 @@ void UElevenLabsWebSocketProxy::SendUserTurnEnd() UE_LOG(LogElevenLabsWS, Log, TEXT("User turn ended (client mode) — stopped sending user_activity.")); } +void UElevenLabsWebSocketProxy::SendTextMessage(const FString& Text) +{ + if (!IsConnected()) + { + UE_LOG(LogElevenLabsWS, Warning, TEXT("SendTextMessage: not connected.")); + return; + } + if (Text.IsEmpty()) return; + + // API: { "type": "user_message", "text": "Hello agent" } + TSharedPtr Msg = MakeShareable(new FJsonObject()); + Msg->SetStringField(TEXT("type"), ElevenLabsMessageType::UserMessage); + Msg->SetStringField(TEXT("text"), Text); + SendJsonMessage(Msg); +} + void UElevenLabsWebSocketProxy::SendInterrupt() { if (!IsConnected()) return; diff --git a/Unreal/PS_AI_Agent/Plugins/PS_AI_Agent_ElevenLabs/Source/PS_AI_Agent_ElevenLabs/Public/ElevenLabsConversationalAgentComponent.h b/Unreal/PS_AI_Agent/Plugins/PS_AI_Agent_ElevenLabs/Source/PS_AI_Agent_ElevenLabs/Public/ElevenLabsConversationalAgentComponent.h index d3f5b0a..759e1d9 100644 --- a/Unreal/PS_AI_Agent/Plugins/PS_AI_Agent_ElevenLabs/Source/PS_AI_Agent_ElevenLabs/Public/ElevenLabsConversationalAgentComponent.h +++ b/Unreal/PS_AI_Agent/Plugins/PS_AI_Agent_ElevenLabs/Source/PS_AI_Agent_ElevenLabs/Public/ElevenLabsConversationalAgentComponent.h @@ -135,6 +135,14 @@ public: UFUNCTION(BlueprintCallable, Category = "ElevenLabs") void StopListening(); + /** + * Send a plain text message to the agent without using the microphone. + * The agent will respond with audio and text just as if it heard you speak. + * Useful for testing in the Editor or for text-based interaction. + */ + UFUNCTION(BlueprintCallable, Category = "ElevenLabs") + void SendTextMessage(const FString& Text); + /** Interrupt the agent's current utterance. */ UFUNCTION(BlueprintCallable, Category = "ElevenLabs") void InterruptAgent(); diff --git a/Unreal/PS_AI_Agent/Plugins/PS_AI_Agent_ElevenLabs/Source/PS_AI_Agent_ElevenLabs/Public/ElevenLabsWebSocketProxy.h b/Unreal/PS_AI_Agent/Plugins/PS_AI_Agent_ElevenLabs/Source/PS_AI_Agent_ElevenLabs/Public/ElevenLabsWebSocketProxy.h index f9d545a..f03a54d 100644 --- a/Unreal/PS_AI_Agent/Plugins/PS_AI_Agent_ElevenLabs/Source/PS_AI_Agent_ElevenLabs/Public/ElevenLabsWebSocketProxy.h +++ b/Unreal/PS_AI_Agent/Plugins/PS_AI_Agent_ElevenLabs/Source/PS_AI_Agent_ElevenLabs/Public/ElevenLabsWebSocketProxy.h @@ -136,6 +136,14 @@ public: UFUNCTION(BlueprintCallable, Category = "ElevenLabs") void SendUserTurnEnd(); + /** + * Send a text message to the agent (no microphone needed). + * Useful for testing or text-only interaction. + * Sends: { "type": "user_message", "text": "..." } + */ + UFUNCTION(BlueprintCallable, Category = "ElevenLabs") + void SendTextMessage(const FString& Text); + /** Ask the agent to stop the current utterance. */ UFUNCTION(BlueprintCallable, Category = "ElevenLabs") void SendInterrupt();