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

# WebAssembly VAD API

> Process dedicated VAD models and read speech predictions.

**Version:** `@ai-coustics/aic-sdk-wasm` 0.23.0, Core SDK 0.23.0. [API index](/reference/sdk/api/wasm/index) · [WebAssembly quickstart](/reference/sdk/language-bindings/wasm).

<span id="wasm-vad" />

## `Vad`

```typescript theme={null}
export class Vad
```

A synchronous dedicated voice activity detection stream. Supply a VAD Multi Speaker or VAD Voice Focus model. Each instance keeps separate signal state and retains the model weights.

<span id="wasm-vad-free" />

### `Vad.free`

```typescript theme={null}
free(): void;
```

Releases the owned WebAssembly allocation. Call once in `finally` and do not use the handle afterward. Garbage collection does not guarantee timely cleanup; `free()` does not acknowledge session termination.

<span id="wasm-vad-symbol-dispose" />

### `Vad.Symbol.dispose`

```typescript theme={null}
[Symbol.dispose](): void;
```

Aliases `free()` when the runtime supports `Symbol.dispose`; do not call both on the same handle. Otherwise, call `free()` in `finally`.

<span id="wasm-vad-getvadcontext" />

### `Vad.getVadContext`

```typescript theme={null}
getVadContext(): VadContext;
```

Returns a newly owned handle to shared prediction and control state. The handle does not contain a separate VAD model. Repeated calls require separate `free()` calls for the returned contexts.

<span id="wasm-vad-initialize" />

### `Vad.initialize`

```typescript theme={null}
initialize(sample_rate: number, block_size: number, variable_block_size: boolean): void;
```

All three arguments are required. `sample_rate` is a whole-number rate in Hz from 8,000 through 192,000; `block_size` is a positive whole-number count of mono samples, not bytes. Prefer the model's optimal sample rate and block size. Unsupported block configurations throw. Pass `false` for fixed blocks of exactly `block_size` samples or `true` to permit shorter blocks up to that maximum. Variable blocks can add buffering delay. Initialization allocates memory and resets signal state. A failed initialization leaves processing uninitialized; correct the configuration before submitting audio again.

<span id="wasm-vad-constructor" />

### `Vad.constructor`

```typescript theme={null}
constructor(model: Model, license_key: string);
```

Creates a dedicated VAD stream using a live VAD `model` and the credential in `license_key`. Use a short-lived JWT from your backend in browser code. Enhancement and analysis models are rejected. Construction can throw for model type, model creation or credential errors. Initialize the audio format before processing. No OpenTelemetry configuration argument is exposed.

<span id="wasm-vad-process" />

### `Vad.process`

```typescript theme={null}
process(audio: Float32Array): void;
```

Processes one block of normalized mono `Float32Array` samples without changing the caller's array. Samples are copied into WebAssembly memory and into the VAD's processing buffer. Returns `void`; read the prediction through the context afterward. Requires successful initialization and the configured block length. Throws for uninitialized or mismatched audio, disallowed processing or runtime failures.

<span id="wasm-vad-terminatesession" />

### `Vad.terminateSession`

```typescript theme={null}
terminateSession(): void;
```

Requests termination of the telemetry session. Stop submitting audio before calling this method. Processing becomes disallowed once the telemetry task handles the signal; the `void` return is not an acknowledgment of server delivery or immediate completion. This method neither flushes delayed audio nor frees the object. Call `free()` separately when finished.

<span id="wasm-vadcontext" />

## `VadContext`

```typescript theme={null}
export class VadContext
```

A shared prediction and control handle returned by `Vad.getVadContext`. Its constructor is private. Each returned handle must be freed separately. Freeing it does not free its VAD. A surviving context retains state after the VAD is freed, but cannot produce new predictions.

<span id="wasm-vadcontext-free" />

### `VadContext.free`

```typescript theme={null}
free(): void;
```

Releases the owned WebAssembly allocation. Call once in `finally` and do not use the handle afterward. Garbage collection does not guarantee timely cleanup; `free()` does not acknowledge session termination.

<span id="wasm-vadcontext-symbol-dispose" />

### `VadContext.Symbol.dispose`

```typescript theme={null}
[Symbol.dispose](): void;
```

Aliases `free()` when the runtime supports `Symbol.dispose`; do not call both on the same handle. Otherwise, call `free()` in `finally`.

<span id="wasm-vadcontext-getparameter" />

### `VadContext.getParameter`

```typescript theme={null}
getParameter(parameter: VadParameter): number;
```

Returns the stored floating-point value for the selected `VadParameter`. Duration values are in seconds. Effective timing follows model frame boundaries; do not interpret the getter as a measurement of the resulting delay.

<span id="wasm-vadcontext-getpredictiondelay" />

### `VadContext.getPredictionDelay`

```typescript theme={null}
getPredictionDelay(): number;
```

Returns end-to-end prediction delay in samples at the initialized host sample rate, including input block adaptation. Query after initialization. Divide by sample rate for seconds.

<span id="wasm-vadcontext-getrawvadprobability" />

### `VadContext.getRawVadProbability`

```typescript theme={null}
getRawVadProbability(): number;
```

Returns the latest raw speech probability as a number from `0` through `1`, before the hold and minimum-duration decision logic. A fresh or reset context reads `0` until new predictions are available.

<span id="wasm-vadcontext-isspeechdetected" />

### `VadContext.isSpeechDetected`

```typescript theme={null}
isSpeechDetected(): boolean;
```

Returns the latest speech decision after sensitivity and duration logic. A fresh or reset context reads `false` until processing provides a new decision.

<span id="wasm-vadcontext-reset" />

### `VadContext.reset`

```typescript theme={null}
reset(): void;
```

Immediately clears the published speech decision and raw probability, and requests clearing of the underlying signal history on the next processing pass. Preserves the initialized format and configured parameters.

<span id="wasm-vadcontext-setparameter" />

### `VadContext.setParameter`

```typescript theme={null}
setParameter(parameter: VadParameter, value: number): void;
```

Sets the parameter for subsequent processing. Invalid ranges, infinities and NaN throw `RangeError`. Defaults come from the loaded model, so query them rather than assuming a universal preset. See `VadParameter` below for units and ranges.

<span id="wasm-vadcontext-updatebearertoken" />

### `VadContext.updateBearerToken`

```typescript theme={null}
updateBearerToken(token: string): void;
```

Replaces the bearer token for subsequent session requests without creating a new processing instance. Both the original credential and the replacement must be JWT-form credentials. A malformed or unsupported replacement throws and leaves the previous credential in place. Local format acceptance does not prove that the backend accepts the new token. Obtain fresh short-lived tokens through your backend; keep the SDK key on the server. This call returns `void`, not a network-completion promise.

<span id="wasm-vadparameter" />

## `VadParameter`

```typescript theme={null}
export enum VadParameter
```

Parameters accepted by `VadContext.getParameter` and `setParameter`. Defaults are supplied by the model.

<span id="wasm-vadparameter-speechholdduration" />

### `VadParameter.SpeechHoldDuration`

```typescript theme={null}
SpeechHoldDuration = 0,
```

Controls recent-speech hold behavior in seconds. Range: `0` through the model's maximum supported hold duration. When the current probability is at or below the threshold, the decision uses the positive-frame count in the recent lookback window. Above the threshold, the consecutive-frame rule from `MinimumSpeechDuration` applies. Effective timing follows frame boundaries.

<span id="wasm-vadparameter-sensitivity" />

### `VadParameter.Sensitivity`

```typescript theme={null}
Sensitivity = 1,
```

Speech-decision threshold from `0` through `1`. Lower values classify more frames as speech.

<span id="wasm-vadparameter-minimumspeechduration" />

### `VadParameter.MinimumSpeechDuration`

```typescript theme={null}
MinimumSpeechDuration = 2,
```

Required speech duration in seconds, from `0` through `1`, before speech is detected. Effective timing follows frame boundaries.

## Read a block prediction

This helper assumes the module is initialized, `model` is a live dedicated VAD model, `token` is a backend-issued JWT and `audio` contains one optimal mono block. A single initial block can precede a usable prediction because of model delay and duration settings. Keep a VAD instance alive across the full stream in an integration.

```javascript theme={null}
import { Vad } from "@ai-coustics/aic-sdk-wasm";

/**
 * @param {import("@ai-coustics/aic-sdk-wasm").Model} model
 * @param {string} token
 * @param {Float32Array} audio
 */
export function detectBlock(model, token, audio) {
  const sampleRate = model.getOptimalSampleRate();
  const blockSize = model.getOptimalBlockSize(sampleRate);
  if (audio.length !== blockSize) throw new Error("Expected one optimal block");
  const vad = new Vad(model, token);
  try {
    vad.initialize(sampleRate, blockSize, false);
    const context = vad.getVadContext();
    try {
      vad.process(audio);
      return {
        speech: context.isSpeechDetected(),
        probability: context.getRawVadProbability(),
        delaySamples: context.getPredictionDelay(),
      };
    } finally {
      context.free();
    }
  } finally {
    try {
      vad.terminateSession();
    } finally {
      vad.free();
    }
  }
}
```
