Overview

The interruptPersona() method allows you to programmatically stop the persona while it’s speaking.
Requires SDK version 3.4.0 or higher

Basic Usage

Stop the persona from speaking immediately:
anamClient.interruptPersona();
The persona will stop its current speech and be ready to receive new input.

Important Considerations

The interruptPersona() method only works while the persona is actively speaking. Calling it when the persona is not speaking will have no effect but won’t throw an error.
The interruptPersona() method behavior:
  • Immediately stops any ongoing speech from the persona
  • The persona remains ready to receive new input after being interrupted

Use Cases

User-Initiated Interruption

Allow users to interrupt the persona when they want to ask a different question or change topics:
// When user clicks a button or starts speaking
document.getElementById("interrupt-btn").addEventListener("click", async () => {
  await anamClient.interruptPersona();
});
Anam’s Voice Activity Detection also automatically interrupts the persona when the user starts speaking. However, you can use this function to interrupt the persona at any time or for a more immediate response.

Topic Change Handling

Stop the persona when users navigate to a different section or topic:
// When user navigates to a new page or section
async function handleNavigationChange(newSection) {
  // Stop any ongoing explanation
  await anamClient.interruptPersona();
  
  // Send context about the new topic
  await anamClient.sendUserMessage(
    `Note to AI: User navigated to ${newSection}`
  );
}

Next Steps