Discussions

Ask a Question
Back to All

[Recurring Issue] How to make the avatar listen but not respond automatically?

I'm trying to make the avatar listen to the user but not respond automatically. I'd like it to speak (repeat back) my custom generated response. How can I achieve this?

I used startVoiceChat() but then the avatar responds back automatically (I guess with its internally generated response). It's not clear what difference the useSilencePrompt flag makes.

When I used startListening() only instead of using startVoiceChat() it wasn't actually listening, so I wasn't able to capture the user's messages.

Sometimes when I send a speak() request I get the error {"code":400006,"message":"Session is not in correct state"}. What does this mean?

I see that multiple users are facing this problem and there doesn't appear to be a clear solution. The documentation doesn't say much either. Please help!

https://docs.heygen.com/discuss/66f2304586e7d6000f973f5b

https://docs.heygen.com/discuss/66fb057e4c77620020e3bd24

https://docs.heygen.com/discuss/66f5b3cc9507a2001fa54020

Here's the code for how I'm starting the avatar:

const startStreamingChat = useCallback(async (token: string) => {
    streamingAvatarRef.current = new StreamingAvatar({
      token,
    });

    // Some event handling code omitted

    await streamingAvatarRef.current!.createStartAvatar({
      quality: AvatarQuality.Low,
      avatarName: 'Anna_public_3_20240108',
      language: 'en',
    });

    // await streamingAvatarRef.current!.startVoiceChat({
    //   useSilencePrompt: true,
    // });
    await streamingAvatarRef.current!.startListening();
  }, []);

In a separate method I'm using speak() like:

streamingAvatarRef.current!.speak({
  text: customResponse.text,
  taskType: TaskType.REPEAT,
});