Invoke Speech and missing .cs

Dear support,
I’m trying to make the character speak indipendently from user input, I’ve read that there should be an Invoke Speech function in NarrativeDesignTrigger.cs but I don’t have this script in my ConvAI unity project.
What solution is possible? Thanks in advance

Hi, maybe you don’t need Narrative Design for this? If you mean you want to get the character to say something, you can use this :

convaiNPC.SendTextDataAsync("<speak>Hello Massimo how are you today?</speak>");

The speak tags instruct the character to say exactly what is between them.

If you want there to be some variation in the characters speech each time this method is invoked, you can use this :

convaiNPC.SendTextDataAsync("Greet the Player who's name is " + playerName);

The character will say something like “Hi Massimo, how is it going?”, they say something broadly similar to what is in the quotation marks and it varies each time the method is invoked.

EDIT : what you say without the < speak > tags is more like an instruction, so I’ve edited this bit.

Hello @Massimo_De_Antonis,

Yes, you can follow Tyke’s instructions. You are probably using the old version of Convai SDK, so you don’t have this method.

Thanks for the infos, I’ve managed to use the method but I have 2 major issues with it.

1- the speak tags have no effect, the string is always considered like a general instruction and I can’t instruct the character to say exactly what is between them.

2 - 95% of the times the phrase doesn’t show up in the chat UI even tough the character is speaking.

Is there a suggested solution? this is an important subject.
Thanks for helping

Hi Massimo, about point 1, double check you have used the speak tags correctly, they must be exactly like this :

convaiNPC.SendTextDataAsync("<speak>Hello Massimo how are you today?</speak>");

With no spaces in the speak tags, and be sure to include the enclosing / in the second speak tag.

About point 2, I cannot help with that sorry.

@Massimo_De_Antonis Please share the code.

It looks like restarting the Unity editor each time solves the issue with the chat not appearing. I’m still getting the issue with the speak tags

This is the code:

 private void Update()
        {
            if (sessionID != "-1" && conv_Started == false) {
                Debug.Log("SessionID = " + sessionID);
                SendTextDataAsync("<speak>Hello there! I'm Lexi, are you already registered to our platform?</speak>");
                conv_Started = true;
                Debug.Log("The AI greeted the player!!!");

            }
            // Handle text input focus and submission
            if (isCharacterActive)
                HandleTextInput();

            HandlePlayerInputs();
        }

This is what I’m getting:
image

Thank you very much for the assistance.

There is a race condition. Do not use it in the update. Create a new script and call it in Start().

Hi K thanks for the tip, I tried that first but I can’t make the character say anything unless the sessionID has been successfully initialized, which is never on start (that’s why my condition includes sessionID != “-1”).

Also I need to be able to say specific things at any moment given certain conditions are met.

When you send this request it should be initialized, you are doing something wrong.
-1 so the session is not initialized.

I’m setting != “-1” , which waits for the variable to be NOT -1 , which is only after initialization.
I’m just asking why the speak tags are not working…
Thanks for trying to help

Please share all your code modifications. I need to review them. It looks like you have changed the core scripts.