[AI-Addon] - How to extract Player's converted text response, add extra context and then send through to AI Chat NPC?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Skermunkel
Posts: 7
Joined: Mon Jun 02, 2025 1:56 pm

[AI-Addon] - How to extract Player's converted text response, add extra context and then send through to AI Chat NPC?

Post by Skermunkel »

Hi,

In the AI Add-on, using Realtime NPC Chat AI, I'm trying to find a way to intercept the converted text response created from the Player's voice input and then add extra context to it before I send it through as a response to the NPC Chat AI Actor.

What would be the best way to go about this?
Skermunkel
Posts: 7
Joined: Mon Jun 02, 2025 1:56 pm

Re: [AI-Addon] - How to extract Player's converted text response, add extra context and then send through to AI Chat NP

Post by Skermunkel »

From what I can tell the best way is gonna be through the followinf function in RuntimeAIConversation.cs, but not sure if that's correct:

protected virtual void OnReceivedLine(string line)
{
if (DialogueDebug.logInfo) Debug.Log($"Dialogue System: Received from {ServiceName}: {line}", this);

if (string.IsNullOrEmpty(line))
{
OnClickedGoodbye();
}
else
{
approximateTokenCount += line.Length / ApproximateCharactersPerToken;
line = RemoveConversant(line);
messages.Add(new ChatMessage("user", $"{conversant} says: {line}"));
if (IsVoiceEnabled)
{
GenerateVoice(line);
}
else
{
ShowSubtitle(line, null);
}
}
}
User avatar
Tony Li
Posts: 23252
Joined: Thu Jul 18, 2013 1:27 pm

Re: [AI-Addon] - How to extract Player's converted text response, add extra context and then send through to AI Chat NP

Post by Tony Li »

Hi,

Make and use a subclass of RuntimeAIConversation. (You can replace RuntimeAIConversation with the subclass in-place on a GameObject to retain inspector assignments. See here.)

Override the OnReceivedTranscription(string) method, such as:

Code: Select all

protected override void OnReceivedTranscription(string s)
{
    s += "Your additional context.";
    base.OnReceivedTranscription(s);
}
Skermunkel
Posts: 7
Joined: Mon Jun 02, 2025 1:56 pm

Re: [AI-Addon] - How to extract Player's converted text response, add extra context and then send through to AI Chat NP

Post by Skermunkel »

Awesome! Perfect, thanks Tony. I thought this would be the best solution, just needed confirmation.
Post Reply