Page 1 of 1

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

Posted: Mon Jun 02, 2025 2:06 pm
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?

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

Posted: Mon Jun 02, 2025 2:18 pm
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);
}
}
}

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

Posted: Mon Jun 02, 2025 2:29 pm
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);
}

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

Posted: Tue Jun 03, 2025 8:09 am
by Skermunkel
Awesome! Perfect, thanks Tony. I thought this would be the best solution, just needed confirmation.

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

Posted: Tue Jun 03, 2025 9:49 am
by Tony Li
Glad to help!