Skip to main content
Version: @ai-coustics/aic-sdk-wasm 0.23.0, Core SDK 0.23.0. API index · WebAssembly quickstart.

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.

Vad.free

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.

Vad.Symbol.dispose

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

Vad.getVadContext

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.

Vad.initialize

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.

Vad.constructor

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.

Vad.process

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.

Vad.terminateSession

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.

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.

VadContext.free

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.

VadContext.Symbol.dispose

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

VadContext.getParameter

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.

VadContext.getPredictionDelay

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.

VadContext.getRawVadProbability

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.

VadContext.isSpeechDetected

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

VadContext.reset

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.

VadContext.setParameter

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.

VadContext.updateBearerToken

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.

VadParameter

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

VadParameter.SpeechHoldDuration

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.

VadParameter.Sensitivity

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

VadParameter.MinimumSpeechDuration

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.