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

# Voice Agent

> A full spoken conversation

`RunAnywhere.voice` assembles speech-to-text, a language model, and text-to-speech into one
session that listens, thinks, and answers out loud. It owns the microphone while it runs.

```ts theme={"theme":"css-variables"}
const session = await RunAnywhere.voice.createSession({
  stt: { id: 'whisper-base' },
  llm: { id: 'qwen3-0.6b' },
  tts: { id: 'piper-en-amy' },
})

await session.start()
```

## Signature

Web takes a single options object, where Swift and Kotlin take named parameters.

```ts theme={"theme":"css-variables"}
interface VoiceSessionOptions {
  stt: ModelRef;
  llm: ModelRef;
  tts: ModelRef;
  vad?: VadOptions;
  turnHandling?: TurnHandlingOptions;
  generation?: LlmOptions;
  downloadIfNeeded?: boolean;   // default true
}

createSession(options: VoiceSessionOptions): Promise<VoiceSession>
```

Leaving `vad` unset ensures the catalogued default Silero VAD.

## VoiceSession

```ts theme={"theme":"css-variables"}
session.start(): Promise<void>
session.say(text: string): Promise<SpeechHandle>
session.interrupt(): Promise<void>
session.close(): Promise<void>
```

`say` speaks a line without waiting for the user, which is how you greet someone.
`interrupt` cuts off whatever is being spoken.

Always `close()` the session. It holds the microphone, and the browser keeps the recording
indicator lit until you do.

## Turn handling

```ts theme={"theme":"css-variables"}
const session = await RunAnywhere.voice.createSession({
  stt: { id: 'whisper-base' },
  llm: { id: 'qwen3-0.6b' },
  tts: { id: 'piper-en-amy' },
  turnHandling: {
    endpointing: { minDelayMs: 500, maxDelayMs: 3000 },
    interruption: { enabled: true, minDurationMs: 500 },
  },
})
```

| Setting | Default | Meaning |
| - | - | - |
| `endpointing.minDelayMs` | `500` | Shortest silence that ends a turn |
| `endpointing.maxDelayMs` | `3000` | Longest wait before ending it anyway |
| `interruption.enabled` | `true` | A person talking over the model stops it |
| `interruption.minDurationMs` | `500` | Speech this long counts as an interruption |

Raise `interruption.minDurationMs` in a noisy room, or a cough cuts the model off.

## Steering the replies

```ts theme={"theme":"css-variables"}
generation: {
  systemPrompt: 'You are a voice assistant. Answer in one or two sentences.',
  maxOutputTokens: 100,
}
```

Spoken replies want to be short. Cap `maxOutputTokens` lower than you would for a chat
interface.

## A complete session

```ts theme={"theme":"css-variables"}
import { RunAnywhere } from '@runanywhere/web'

let session: Awaited<ReturnType<typeof RunAnywhere.voice.createSession>> | null = null

startButton.addEventListener('click', async () => {
  session = await RunAnywhere.voice.createSession({
    stt: { id: 'whisper-base' },
    llm: { id: 'qwen3-0.6b' },
    tts: { id: 'piper-en-amy' },
    generation: {
      systemPrompt: 'Answer in one or two sentences.',
      maxOutputTokens: 100,
    },
  })

  await session.start()
  await session.say('Hello. What can I help with?')
})

stopButton.addEventListener('click', async () => {
  await session?.close()
  session = null
})

window.addEventListener('pagehide', () => {
  void session?.close()
})
```

Starting from a click is required: the browser will not grant the microphone, or start audio
output, without a user gesture. Closing on `pagehide` is what stops the session surviving a
navigation.

## Three models at once

A voice session holds a speech model, a language model, and a synthesis model in memory
together. In a browser tab that is a real constraint. Prefer the smallest usable model for
each, and check the total download size before offering the feature.

## Diarization

To answer "who spoke when" over a recording rather than run a live conversation:

```ts theme={"theme":"css-variables"}
const result = await RunAnywhere.diarization.diarize(audio)
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.