I’m sure it’s possible but can’t work it out how to get the final input from the user (as a string) in Unity webGL.
Any clues?
Hello @Nick_Clarke,
Yes, it’s definitely possible.
You can access it through the ConvaiGRPCWebAPI
script using the following methods:
OnUserResponseReceived
OnTextResponseReceived
Hi There @K3 ,
Thanks so much for your reply I had noticed the OnUserResponseReceived
but there is no OnTextResponseReceived
in my ConvaiGRPCWebAPI
maybe I need an update?
Also, when testing OnUserResponseReceived
with the following:
public void OnUserResponseReceived(string text)
{
if (_convaiChatUIHandler == null) return;
if (!string.IsNullOrWhiteSpace(text))
{
_convaiChatUIHandler.SendPlayerText(text);
}
Debug.Log("OnUserResponseReceived Text: " + text);
}
I get the phrase as it it constructed with output to the debug log of lots of words as the phrase is spoken. What I need is the final phrase that is sent so I can analyse that. Does that make sense?
Which version of the WebGL SDK are you using?
I don’t have the package download on my PC anymore and I can’t see the package in the manifest.json or packages-lock.json.
How can I find out?
When did you download it? If it is a new project, I recommend using our latest version.
It was downloaded some time ago.
it is OK to overwrite with the latest package or will I need to create a new project to test?
Since it contains major changes, overwrite is not the right choice.
Assets/Convai/Plugins/WebGL/ConvaiUnityWebGL.jslib
can you share this file with me?
ConvaiUnityWebGL.txt (9.5 KB)
Here you go… (as a text file so I can upload it)
Ok update the JSLIB file like this.
if (response.hasUserQuery()) {
var transcript = response.getUserQuery();
var isFinal = transcript.getIsFinal();
var transcriptText = transcript.getTextData();
if (isFinal) {
this.userTextStream += transcriptText;
SendMessage("ConvaiGRPCWebAPI", "OnUserResponseReceived", this.userTextStream);
}
if (transcript.getEndOfResponse()) { // Added
SendMessage("ConvaiGRPCWebAPI", "OnUserFinalResponseReceived", transcriptText); // Added
} // Added
this.userTextStream = transcriptText;
SendMessage("ConvaiGRPCWebAPI", "OnUserResponseReceived", this.userTextStream);
}
In the ConvaiGRPCWebAPI.cs
add this method
public void OnUserFinalResponseReceived(string text)
{
if (!string.IsNullOrWhiteSpace(text))
{
// Your Code
}
}
For Character response,
In the ConvaiGRPCWebAPI.cs, please check the OnAudioResponseReceived
if (!string.IsNullOrEmpty(audioData.resText))
{
_convaiChatUIHandler.SendCharacterText(activeConvaiNPC.characterName, audioData.resText);
_lastReceivedText = audioData.resText;
// Debug.Log(audioData.resText);
}
Thanks for the update but unfortunately, I’m still getting parts of the phrase when sending the OnUserFinalResponseReceived
to the debug log.
Thanks for following up. If the OnUserFinalResponseReceived
event isn’t giving you the full finalized phrase as expected in your use case, the best alternative is to retrieve the completed text directly from the Chatbox UI, which displays the final version of the user’s input.
We recommend reviewing the ChatBox UI script in your project. It contains the logic for capturing and displaying finalized input, and you can adapt or extend it to suit your needs.
@K3 Thanks for the reply.
I’ll take a look.
Hello @Nick_Clarke,
I updated the code, could you please try again?