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

> Find speech in audio

`RunAnywhere.vad` answers "is someone talking right now". It is what a voice interface uses to
decide when a turn has ended.

```ts theme={null}
const result = await RunAnywhere.vad.detect(RunAnywhere.audio.wav(bytes))
```

## Signatures

```ts theme={null}
detect(input: AudioInput, options?: VadOptions): Promise<VadResult>
openStream(format: AudioFormatSpec, options?: VadOptions): Promise<VadStream>
detectStream(audio: AsyncIterable<AudioInput>, options?: VadOptions): AsyncIterableIterator<VadEvent>
reset(): Promise<void>
```

Electron and Swift are the only SDKs with `vad.reset()`.

## Streaming from a microphone

```ts theme={null}
const stream = await RunAnywhere.vad.openStream({
  encoding: 'pcmF32Le',
  sampleRate: 16000,
  channels: 1,
})

// per buffer
stream.pushFrame({ samples, sampleCount })

// when done
stream.flush()
stream.finish()
await stream.close()
```

## Options

```ts theme={null}
const options = {
  activationThreshold: 0.5,
  minSpeechMs: 250,
  minSilenceMs: 500,
  prefixPaddingMs: 300,
}
```

| Field                 | Default       | Meaning                                  |
| --------------------- | ------------- | ---------------------------------------- |
| `activationThreshold` | model default | How confident before it counts as speech |
| `minSpeechMs`         | proto default | Ignore bursts shorter than this          |
| `minSilenceMs`        | proto default | Silence before a turn is over            |
| `prefixPaddingMs`     | proto default | Audio kept from before speech started    |

`minSilenceMs` is the one to tune. Too short and the assistant interrupts someone who paused;
too long and it feels sluggish.

`prefixPaddingMs` matters because detection lags the first syllable. Without padding, "hello"
reaches the transcriber as "ello".

A desktop microphone in a quiet room needs a lower `activationThreshold` than a laptop's
built-in mic near a fan. If you support both, make it configurable rather than guessing.

## Resetting

Detection carries state across frames. Reset between unrelated recordings:

```ts theme={null}
await RunAnywhere.vad.reset()
```

## You may not need this

For a spoken conversation, use the [voice session](/electron/voice-agent). It runs VAD,
transcription, generation, and speech together, with turn-taking and interruption wired up.
