> ## 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

React Native takes a single options object.

```ts theme={"theme":"css-variables"}
interface VoiceCreateSessionOptions {
  stt: ModelRef;
  llm: ModelRef;
  tts: ModelRef;              // `voice` selects the speaker in a multi-voice model
  vad?: VadOptions;           // omit vad.model to ensure the catalogued default Silero VAD
  turnHandling?: TurnHandlingOptions;
  generation?: LlmOptions;
  downloadIfNeeded?: boolean;
}

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

## 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.

## 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 for a chat interface.

## A complete screen

```tsx theme={"theme":"css-variables"}
import { RunAnywhere } from '@runanywhere/core'
import { useEffect, useRef, useState } from 'react'
import { AppState, Button, View } from 'react-native'

export function VoiceScreen(): React.JSX.Element {
  const session = useRef<Awaited<ReturnType<typeof RunAnywhere.voice.createSession>> | null>(null)
  const [running, setRunning] = useState(false)

  const start = async () => {
    const s = 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,
      },
    })

    session.current = s
    await s.start()
    await s.say('Hello. What can I help with?')
    setRunning(true)
  }

  const stop = async () => {
    await session.current?.close()
    session.current = null
    setRunning(false)
  }

  useEffect(() => {
    const sub = AppState.addEventListener('change', (state) => {
      if (state !== 'active') void stop()
    })

    return () => {
      sub.remove()
      void session.current?.close()
    }
  }, [])

  return (
    <View>
      <Button title={running ? 'Stop' : 'Start'} onPress={running ? stop : start} />
    </View>
  )
}
```

Closing on background and on unmount is what stops the microphone staying live behind a
backgrounded app.

## Permission

Request the microphone permission before `start()`. A denied permission surfaces as
`microphonePermissionDenied`.

## Three models at once

A voice session holds a speech model, a language model, and a synthesis model in memory
together. On a phone that is a real constraint. Prefer the smallest usable model for each.

## 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.