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

```kotlin theme={"theme":"css-variables"}
val result = RunAnywhere.vad.detect(AudioInput.file(path))
```

## Signatures

```kotlin theme={"theme":"css-variables"}
suspend fun detect(audio: AudioInput, options: VadOptions? = null): VadResult
fun openStream(format: AudioFormatSpec, options: VadOptions? = null): VadStream
fun detectStream(audio: Flow<AudioInput>, options: VadOptions? = null): Flow<VadEvent>
```

## Streaming from a microphone

```kotlin theme={"theme":"css-variables"}
val stream = RunAnywhere.vad.openStream(
    AudioFormatSpec(AudioEncoding.PcmF32Le, 16000, 1)
)

// per buffer
stream.pushFrame(AudioFrame(bytes, count))

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

## Streaming from a Flow

```kotlin theme={"theme":"css-variables"}
RunAnywhere.vad.detectStream(audioFlow).collect { event ->
    when (event) {
        is VadEvent.SpeechStart -> isSpeaking = true
        is VadEvent.SpeechEnd -> isSpeaking = false
        else -> {}
    }
}
```

## Options

```kotlin theme={"theme":"css-variables"}
val options = VadOptions(
    activationThreshold = 0.5f,
    minSpeechMs = 250,
    minSilenceMs = 500,
    prefixPaddingMs = 300
)
```

| Field | Default | Meaning |
| - | - | - |
| `activationThreshold` | model default | How confident before it counts as speech |
| `minSpeechMs` | `DEFAULT_MIN_SPEECH_MS` | Ignore bursts shorter than this |
| `minSilenceMs` | `DEFAULT_MIN_SILENCE_MS` | 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
to think; too long and it feels sluggish.

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

## You may not need this

For a spoken conversation, use the [voice session](https://docs.runanywhere.ai/kotlin/voice-agent.md). It runs VAD,
transcription, generation, and speech together, with turn-taking and interruption already
wired up.


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