Add SendTextMessage to agent component and WebSocket proxy
Sends {"type":"user_message","text":"..."} to the ElevenLabs API.
Agent responds with audio + text exactly as if it heard spoken input.
Useful for testing without a microphone and for text-only NPC interactions.
Available in Blueprint on UElevenLabsConversationalAgentComponent.
Compiles cleanly on UE 5.5 Win64.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
ae2c9b92e8
commit
b489d1174c
@ -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();
|
||||
|
||||
@ -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<FJsonObject> Msg = MakeShareable(new FJsonObject());
|
||||
Msg->SetStringField(TEXT("type"), ElevenLabsMessageType::UserMessage);
|
||||
Msg->SetStringField(TEXT("text"), Text);
|
||||
SendJsonMessage(Msg);
|
||||
}
|
||||
|
||||
void UElevenLabsWebSocketProxy::SendInterrupt()
|
||||
{
|
||||
if (!IsConnected()) return;
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user