Talk to character through script (Unity)

Original Discord Post by hiimabiel | 2024-09-19 15:18:23

Hello, I was wondering how I could send a message to my Convai character through script. I’m using voice and I created an additional module to determine emotion, so I need to send the message to Convai with this information. For example:

If I say: “Hello, John. Is everything okay?”.

I will have my system to determine emotion and automatically add to the sentence the emotion so it looks like the following:

“Hello, John. Is everything okay? (asterisk) Asks in a concerned and empathetic way (asterisk).”.

How can I modify through script the message that is being sent to Convai? Thank you!

Reply by k3kalinix | 2024-09-19 20:23:37

Hello <@328311427980984322>,

Reply by hiimabiel | 2024-09-19 20:24:27

Hello <@1023671043287699568>

Reply by k3kalinix | 2024-09-19 20:25:07

You can review the Start LIstening method in the ConvaiNPC.cs

Reply by hiimabiel | 2024-09-19 20:27:23

Yeah, I’ve been looking at it and also the StopRecordAudio() and ProcessAudioChunk() methods, and it seems like the audio gets converted to a bit stream and sent to the server. Does it get sent like this or as a String? Is there any way to append any information to that stream?

Reply by k3kalinix | 2024-09-19 20:28:25

Let me tag my teammate.

<@433610960725344267>

Reply by raghuvanshagarwal | 2024-09-21 09:22:02

I am assuming you want to send a text request only, and if that is what you want then you can get a reference of the active NPC and use that to call a function called SendTextData and you can pass the data to it

Reply by raghuvanshagarwal | 2024-09-21 09:23:25

  1. Make the NPC you want to say the stuff the active NPC by calling
    ConvaiNPCManager.Instance.SetActiveConvaiNPC([Your-NPC-reference], false)
  2. Send the text to convai server using speak tag method
    [Your-NPC-reference].SendTextDataAsync([Your Text])

Replying to raghuvanshagarwal’s Message

Reply by raghuvanshagarwal | 2024-09-21 09:23:25

  1. Make the NPC you want to say the stuff the active NPC by calling
    ConvaiNPCManager.Instance.SetActiveConvaiNPC([Your-NPC-reference], false)
  1. Send the text to convai server using speak tag method
    [Your-NPC-reference].SendTextDataAsync([Your Text])

Reply by petroslouca | 2024-09-21 19:19:32

Hello <@433610960725344267> and <@1023671043287699568> , I am using Unity and I want to make the character speak a specific text that I provide in a script, I managed to have it displayed inside the chatbox UI but I need also the character to say it, to speak it. Could you please provide the steps to accomplish this?

Reply by k3kalinix | 2024-09-21 19:51:08

Hello <@606256062613684224>,

Reply by k3kalinix | 2024-09-21 19:53:16

Images:

Reply by k3kalinix | 2024-09-21 19:53:34

You can use message

Reply by k3kalinix | 2024-09-21 19:54:18

Just try to get your NPC reference and call SendTextDataAsync

Reply by k3kalinix | 2024-09-21 19:54:41

Or you can use Narrative Design Trigger

Images:

Reply by petroslouca | 2024-09-22 22:30:48

Yes! The speak tags did the work, could you please point me to the specific documentation part for more information about this? Please note that I am using Unity.

Reply by k3kalinix | 2024-09-22 22:32:26

Hello <@606256062613684224> :wave:t2:,

There isn’t extra step.

** Syntax Instructions **

Embedded Content:
Narrative Design | API Docs
Master narrative design with Convai’s character creator tool. Create engaging AI-driven stories.
Link: Narrative Design | Documentation

This conversation happened on the Convai Discord Server, so this post will be closed.