> ## Documentation Index
> Fetch the complete documentation index at: https://anam.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Interrupt Command

> Stop the persona from speaking mid-response

## Overview

The `interruptPersona()` method allows you to programmatically stop the persona while it's speaking.

<Note>Requires SDK version 3.4.0 or higher</Note>

## Method Signature

```typescript theme={"system"}
interruptPersona(): void
```

## Basic Usage

Stop the persona from speaking immediately:

```javascript theme={"system"}
anamClient.interruptPersona();
```

The persona will stop its current speech and be ready to receive new input.

## Prerequisites

Before calling `interruptPersona()`, you must:

1. Have an active streaming session (call `stream()` or `streamToVideoElement()` first)
2. Have successfully connected to the Anam Engine

## Error Handling

The method throws errors in the following cases:

```javascript theme={"system"}
try {
  anamClient.interruptPersona();
} catch (error) {
  // Handle the error
  console.error(error.message);
}
```

| Error Message                                               | Cause                                             |
| ----------------------------------------------------------- | ------------------------------------------------- |
| `Failed to send interrupt command: not currently streaming` | Called before starting a stream or after stopping |
| `Failed to send interrupt command: no active session`       | No session ID available                           |

## Behavior

The `interruptPersona()` method:

* Immediately stops any ongoing speech from the persona
* The persona remains ready to receive new input after being interrupted
* Has no effect if the persona is not currently speaking (no error thrown in this case)

## Use Cases

### User-Initiated Interruption

Allow users to interrupt the persona when they want to ask a different question or change topics:

```javascript theme={"system"}
document.getElementById("interrupt-btn").addEventListener("click", () => {
  try {
    anamClient.interruptPersona();
  } catch (error) {
    console.error("Could not interrupt:", error.message);
  }
});
```

<Note>
  Voice activity detection automatically interrupts the persona when the user starts speaking. Use this method for programmatic interruption or when you need immediate response to UI actions.
</Note>

### Topic Change Handling

Stop the persona when users navigate to a different section or topic:

```javascript theme={"system"}
function handleNavigationChange(newSection) {
  // Stop any ongoing explanation
  try {
    anamClient.interruptPersona();
  } catch (error) {
    // May fail if not streaming - that's fine for navigation
  }

  // Send context about the new topic
  anamClient.sendUserMessage(
    `Note to AI: User navigated to ${newSection}`
  );
}
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Events" icon="webhook" href="/javascript-sdk/reference/events">
    Learn about speech events to track when the persona is speaking
  </Card>

  <Card title="User Messages" icon="message" href="/javascript-sdk/reference/user-messages">
    Send messages programmatically after interrupting
  </Card>
</CardGroup>
