Discussions

Ask a Question
Back to All

taskMode SYNC not working properly

So I have this code block:


  const speakGreeting = useCallback(async () => {
    if (!avatarRef.current) {
      console.log("Avatar not initialized, cannot speak greeting")
      return
    }

    console.log("Checking if avatar is ready before speaking...")
    await new Promise((resolve) => setTimeout(resolve, 300))

    console.log("Speaking greeting...")
    try {
      avatarRef.current.on(StreamingEvents.AVATAR_STOP_TALKING, () => {
        console.log("Avatar finished speaking, now starting voice recognition")
        setIsVoiceInputActive(true)
      })
      await avatarRef.current.speak({
        text: "Hello! I'm test avatar from test company, your AI HR interviewer. Are you ready to start the exam?",
        taskType: TaskType.REPEAT,
        taskMode: TaskMode.SYNC,
      })
      console.log("Greeting spoken successfully")
    } catch (error) {
      console.log(`Error in speakGreeting: ${error instanceof Error ? error.message : String(error)}`)
    }
  }, [])

Based on the documentation, taskMode: SYNC blocks further actions until speaking completes which I assume includes the User talking, but on my scenario the avatar gets interrupted when I say something during the greeting.