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

# Rust voice activity detection

> Vad, VadAsync, prediction control and parameters in aic-sdk 0.24.0.

**Crate:** `aic-sdk = "=0.24.0"`. **Core SDK:** `0.24.0`. Source: [released crate](https://docs.rs/crate/aic-sdk/0.24.0/source/). Signatures are declarations; import the named types from `aic_sdk`. See the [Rust guide](/reference/sdk/language-bindings/rust) for a complete runnable program.

<a id="rust-aic_sdk-Vad" />

## Vad

```rust theme={null}
pub struct Vad<'a> { /* private fields */ }
```

Stateful dedicated VAD. Feed original mono audio, independently of enhancement; processing leaves input unchanged. Use one instance per stream and read predictions from its context. Implements `Drop`, `Send` and `Sync`; borrowed model bytes must outlive the detector. Mutable access serializes processing and initialization.

<a id="rust-aic_sdk-Vad-new" />

### Vad::new

```rust theme={null}
pub fn new(model: &Model<'a>, license_key: &str) -> Result<Self, AicError>
```

Creates an uninitialized detector. The model must be a dedicated VAD model; an enhancement model returns `ModelTypeUnsupported`. Credentials are an SDK key or JWT.

<a id="rust-aic_sdk-Vad-with_otel_config" />

### Vad::with\_otel\_config

```rust theme={null}
pub fn with_otel_config(
    model: &Model<'a>,
    license_key: &str,
    otel_config: &OtelConfig,
) -> Result<Self, AicError>
```

Creates an uninitialized detector with explicit copied telemetry settings. Invalid credentials return license errors; a NUL-containing session ID returns `Internal`.

<a id="rust-aic_sdk-Vad-with_config" />

### Vad::with\_config

```rust theme={null}
pub fn with_config(self, config: &ProcessorConfig) -> Result<Self, AicError>
```

Consumes the detector, initializes it and returns it on success. A failure drops the consumed detector.

<a id="rust-aic_sdk-Vad-initialize" />

### Vad::initialize

```rust theme={null}
pub fn initialize(&mut self, config: &ProcessorConfig) -> Result<(), AicError>
```

Copies and validates the audio configuration. Unsupported settings return `AudioConfigUnsupported`. This allocates; run it outside the audio callback. Reinitialize successfully after any failed reconfiguration.

<a id="rust-aic_sdk-Vad-process" />

### Vad::process

```rust theme={null}
pub fn process(&mut self, audio: &[f32]) -> Result<(), AicError>
```

Reads normalized mono samples and updates detector state; returns no audio. Use exactly the configured block length, or a slice up to that length when variable blocks are enabled. Errors include `NotInitialized`, `AudioConfigMismatch` and `ProcessingNotAllowed`. Read predictions after successful processing.

<a id="rust-aic_sdk-Vad-context" />

### Vad::context

```rust theme={null}
pub fn context(&self) -> VadContext
```

Creates a shared prediction/control handle. Multiple handles refer to the same detector. Native failure is asserted and can panic.

<a id="rust-aic_sdk-Vad-terminate_session" />

### Vad::terminate\_session

```rust theme={null}
pub fn terminate_session(&mut self) -> Result<(), AicError>
```

Requests permanent session termination for this detector. Stop processing first and use a new object for another session. This may block and is unsuitable for the audio callback. Native work becomes disallowed when the lifecycle task handles the signal; with other sessions alive that can occur after return.

<a id="rust-aic_sdk-VadContext" />

## VadContext

```rust theme={null}
pub struct VadContext { /* private fields */ }
```

Created by `Vad::context` or awaited `VadAsync::context`. Implements `Drop`, `Send` and `Sync`; no public constructor. It permits cross-thread prediction reads and parameter control while the detector processes elsewhere. Predictions stop updating when audio is no longer processed.

<a id="rust-aic_sdk-VadContext-is_speech_detected" />

### VadContext::is\_speech\_detected

```rust theme={null}
pub fn is_speech_detected(&self) -> bool
```

Returns the latest post-processed decision. It lags the input by `prediction_delay()` samples; do not treat a stale decision as a new inference.

<a id="rust-aic_sdk-VadContext-raw_vad_probability" />

### VadContext::raw\_vad\_probability

```rust theme={null}
pub fn raw_vad_probability(&self) -> f32
```

Returns the latest model probability without SDK hold/threshold post-processing. It has the same input alignment delay.

<a id="rust-aic_sdk-VadContext-set_parameter" />

### VadContext::set\_parameter

```rust theme={null}
pub fn set_parameter(&self, parameter: VadParameter, value: f32) -> Result<(), AicError>
```

Stores a parameter for the detector. Out-of-range or NaN values return `ParameterOutOfRange`. Effective transitions are quantized to model frames.

<a id="rust-aic_sdk-VadContext-parameter" />

### VadContext::parameter

```rust theme={null}
pub fn parameter(&self, parameter: VadParameter) -> Result<f32, AicError>
```

Returns the stored parameter value. Duration readback is the requested value; it is not a promise of exact transition timing. Defaults are model-specific.

<a id="rust-aic_sdk-VadContext-prediction_delay" />

### VadContext::prediction\_delay

```rust theme={null}
pub fn prediction_delay(&self) -> usize
```

Returns prediction lag in samples at the configured input rate, including reblocking and model buffering. This delay is not applied to the input audio and is independent of enhancement audio delay. Value-returning native queries assert success and can panic on internal failures.

<a id="rust-aic_sdk-VadContext-reset" />

### VadContext::reset

```rust theme={null}
pub fn reset(&self) -> Result<(), AicError>
```

Immediately clears the published decision to false and raw probability to 0.0, and requests processing-state reset on the next block. Audio configuration remains initialized. A terminated session is not reopened.

<a id="rust-aic_sdk-VadContext-update_bearer_token" />

### VadContext::update\_bearer\_token

```rust theme={null}
pub fn update_bearer_token(&self, token: &str) -> Result<(), AicError>
```

Updates a JWT only when the original and new credentials are JWTs; otherwise returns `TokenUpdateUnsupported`. Embedded NUL returns `LicenseFormatInvalid`. Local success does not prove backend acceptance; keep handling processing errors.

<a id="rust-aic_sdk-VadParameter" />

## VadParameter

```rust theme={null}
pub enum VadParameter { SpeechHoldDuration, Sensitivity, MinimumSpeechDuration }
```

Named parameter selectors. Implements `Debug`, `Clone`, `Copy`, `PartialEq`, `Eq` and `Hash`, plus native parameter conversion. Read defaults from the active context.

<a id="rust-aic_sdk-VadParameter-SpeechHoldDuration" />

### VadParameter::SpeechHoldDuration

```rust theme={null}
VadParameter::SpeechHoldDuration
```

Duration in seconds controlling the speech-to-silence transition. Range: 0.0 through 300 times the model frame duration. The effective duration is rounded to model frames. When the current probability is at or below threshold, speech remains detected while at least half the approximately `2 * duration` history was above threshold.

<a id="rust-aic_sdk-VadParameter-Sensitivity" />

### VadParameter::Sensitivity

```rust theme={null}
VadParameter::Sensitivity
```

Probability threshold, 0.0 through 1.0. A probability strictly greater than this value contributes a positive frame. A lower threshold is more permissive.

<a id="rust-aic_sdk-VadParameter-MinimumSpeechDuration" />

### VadParameter::MinimumSpeechDuration

```rust theme={null}
VadParameter::MinimumSpeechDuration
```

Duration in seconds required for consecutive above-threshold frames to turn speech detection on. Range: 0.0 through 1.0. Effective timing is rounded to model frames; the stored value can differ from the effective duration.

<a id="rust-aic_sdk-VadAsync" />

## VadAsync

```rust theme={null}
pub struct VadAsync { /* private fields */ }
```

**Requires feature:** `async`. Uses the same shared worker pool and per-instance mutex as [async enhancement](/reference/sdk/api/rust/enhancement#rust-aic_sdk-ProcessorAsync). Constructors are synchronous, model data must be static, and async operations should be awaited in stream order. The type is `Send` and `Sync`; share through `Arc` when needed.

<a id="rust-aic_sdk-VadAsync-new" />

### VadAsync::new

```rust theme={null}
pub fn new(model: &Model<'static>, license_key: &str) -> Result<Self, AicError>
```

Creates an uninitialized dedicated detector. Model and credential errors match `Vad::new`.

<a id="rust-aic_sdk-VadAsync-with_otel_config" />

### VadAsync::with\_otel\_config

```rust theme={null}
pub fn with_otel_config(
    model: &Model<'static>,
    license_key: &str,
    otel_config: &OtelConfig,
) -> Result<Self, AicError>
```

Creates an uninitialized detector with copied telemetry settings.

<a id="rust-aic_sdk-VadAsync-with_config" />

### VadAsync::with\_config

```rust theme={null}
pub async fn with_config(self, config: &ProcessorConfig) -> Result<Self, AicError>
```

Consumes the detector and awaits initialization. Failure drops the consumed object.

<a id="rust-aic_sdk-VadAsync-initialize" />

### VadAsync::initialize

```rust theme={null}
pub async fn initialize(&self, config: &ProcessorConfig) -> Result<(), AicError>
```

Copies settings and initializes on the shared worker pool. Errors match `Vad::initialize`.

<a id="rust-aic_sdk-VadAsync-process" />

### VadAsync::process

```rust theme={null}
pub async fn process(&self, audio: Vec<f32>) -> Result<Vec<f32>, AicError>
```

Consumes the vector, reads it on the processing pool and returns it unchanged on success. Updates the prediction. On failure the vector is dropped. This Rust return value differs from Python VAD's `None` result; input length and errors match `Vad::process`.

<a id="rust-aic_sdk-VadAsync-terminate_session" />

### VadAsync::terminate\_session

```rust theme={null}
pub async fn terminate_session(&self) -> Result<(), AicError>
```

Waits for exclusive access and requests termination. Stop submitting audio first; use a new object for another session. Await the method, but do not treat completion as proof that native signal handling or remote usage acknowledgment has finished when other sessions remain alive.

<a id="rust-aic_sdk-VadAsync-context" />

### VadAsync::context

```rust theme={null}
pub async fn context(&self) -> VadContext
```

Waits for exclusive access and returns a context. Internal native context creation failure can panic.

See [configuration](/reference/sdk/api/rust/models-and-config), [errors](/reference/sdk/api/rust/errors-and-features) and the [symbol index](/reference/sdk/api/rust/index).

## Read a prediction

The caller supplies an initialized dedicated detector and a normalized mono block. Prediction is read only after successful processing:

```rust theme={null}
use aic_sdk::{AicError, Vad};

fn detect_block(vad: &mut Vad<'_>, audio: &[f32]) -> Result<bool, AicError> {
    let context = vad.context();
    vad.process(audio)?;
    Ok(context.is_speech_detected())
}
```
