How to Detect When NPC Has Fully Finished its Resonse?

Hi everyone,

We’re currently using the Convai plugin in Unity and are trying to determine the exact moment when an NPC has fully completed its response—both in terms of text and voice.

At the moment, we’re using the OnCharacterTalkingChanged event to check if the NPC is done speaking. However, we’ve noticed that since some responses are delivered in multiple parts, isTalking can briefly return false between segments, which causes our logic to falsely assume the conversation is over.

What we need is a reliable way to detect when the full response has been received and spoken, so we can trigger some custom code right afterward.

So the main question is:

Is there a definitive method, callback, or event to know when an NPC has fully completed its entire response (including audio playback)?

Any help or suggestions would be greatly appreciated!

Hi @WM
Currently, we don’t have a dedicated function or callback for this, but we do plan to implement one in a future update. In the meantime, there are two ways to detect the end of a response and achieve the desired behavior:

  1. In the ConvaiGRPCAPI class, the ProcessUserQuery function handles incoming responses. Here, you can use the EndOfResponse field provided by the backend to determine when the response ends.
  2. Within the audio controller, there’s a queue mechanism. When the queue count reaches zero, it indicates that the response has been completed.

We hope this solution helps resolve your issue. Please feel free to reach out if you need any further assistance!

Regards,
Convai Unity Team.

Thanks for the quick response!

We had actually tried using the queue mechanism before, but that’s where some of our issues originated. Occasionally, the second or third AudioResponse arrives with a delay, causing the queue count to reach zero before all response parts have been received. As a result, isTalking gets set to false too early.

That said, your second suggestion pointed us in the right direction. While ProcessUserQuery isn’t suitable for our case—since it deals with user input rather than AI responses—we applied a similar approach to the AudioResponse.

We’re now using the OnResultReceived event from the ConvaiGRPCAPI class, checking for the EndOfResponse flag in the AudioResponse field returned by the callback. At the same time, we monitor the OnCharacterTalkingChanged event from the ConvaiNPCAudioManager, but only set the character to not talking on our side if we’ve already received the EndOfResponse.

This seems to produce the desired behavior so far.

1 Like