> ## 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 analysis API

> Collect audio, analyze a window and release analysis results.

**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-analyzer" />

## `Analyzer`

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

Collects mono audio and runs an analysis model such as Tyto over the latest retained window. The window uses the maximum length supported by the model; this binding has no window-length argument. New audio replaces older audio. Short histories include zero-filled input, so track how much real audio you have collected.

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

### `Analyzer.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-analyzer-symbol-dispose" />

### `Analyzer.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-analyzer-analyze" />

### `Analyzer.analyze`

```typescript theme={null}
analyze(): AnalysisResult;
```

Synchronously analyzes the current retained window and returns a newly allocated `AnalysisResult`. It blocks the calling JavaScript thread. Short or empty histories are zero-padded; a successful result does not establish that enough real audio was collected. This method reads a snapshot and does not consume or clear the buffered history. Throws for disallowed processing or native analysis failure. Free each returned result after copying its values.

<span id="wasm-analyzer-buffer" />

### `Analyzer.buffer`

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

Synchronously collects a block of normalized mono `Float32Array` samples without modifying the caller's array. The binding copies samples into WebAssembly memory. This call does not run analysis inference. Requires successful initialization and the configured block length; invalid input throws. The collector retains only the newest model window.

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

### `Analyzer.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-analyzer-constructor" />

### `Analyzer.constructor`

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

Creates an analysis collector and engine using a live analysis `model` and the credential in `license_key`. Use a backend-issued short-lived JWT in browsers. An enhancement or VAD model cannot be analyzed through this interface. Construction can throw for model type, runtime creation or credential errors. No OpenTelemetry configuration or analysis-window argument is exposed.

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

### `Analyzer.reset`

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

Requests clearing of collector signal history on the next `buffer` call while preserving the initialized audio format. Until that call applies the reset, `analyze()` uses a zero-filled snapshot instead of the previously buffered audio.

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

### `Analyzer.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-analyzer-updatebearertoken" />

### `Analyzer.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-analysisresult" />

## `AnalysisResult`

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

An owned WebAssembly result returned by `Analyzer.analyze`, with seven read-only numeric properties. Its constructor is private. Read the values into ordinary JavaScript data before freeing the result. It is not a plain JavaScript record and spreading it does not copy these prototype getters.

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

### `AnalysisResult.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-analysisresult-symbol-dispose" />

### `AnalysisResult.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-analysisresult-codecdegradation" />

### `AnalysisResult.codecDegradation`

```typescript theme={null}
readonly codecDegradation: number;
```

Codec-degradation estimate from the analysis model.

<span id="wasm-analysisresult-interferingspeech" />

### `AnalysisResult.interferingSpeech`

```typescript theme={null}
readonly interferingSpeech: number;
```

Interfering-speech estimate, taking the larger of the model's background-speaker and background-media outputs.

<span id="wasm-analysisresult-noise" />

### `AnalysisResult.noise`

```typescript theme={null}
readonly noise: number;
```

Background-noise estimate from the analysis model.

<span id="wasm-analysisresult-packetloss" />

### `AnalysisResult.packetLoss`

```typescript theme={null}
readonly packetLoss: number;
```

Packet-loss estimate from the analysis model.

<span id="wasm-analysisresult-riskscore" />

### `AnalysisResult.riskScore`

```typescript theme={null}
readonly riskScore: number;
```

Composite risk score derived from the model outputs and the loaded model's postprocessing coefficients. It is not a measured word error rate.

<span id="wasm-analysisresult-speakerloudness" />

### `AnalysisResult.speakerLoudness`

```typescript theme={null}
readonly speakerLoudness: number;
```

Main-speaker loudness estimate from the analysis model. Do not interpret it as a calibrated sound-pressure measurement.

<span id="wasm-analysisresult-speakerreverb" />

### `AnalysisResult.speakerReverb`

```typescript theme={null}
readonly speakerReverb: number;
```

Main-speaker reverberation estimate from the analysis model.

## Copy and release a result

This helper assumes initialization has completed, `model` is a live analysis model and `token` is a backend-issued JWT. Supply mono audio at the model's optimal sample rate with a length divisible by its optimal block size. It buffers the supplied audio and returns ordinary JavaScript numbers, freeing the WebAssembly result afterward. Supply enough real audio for the model's window; shorter input is padded with zeros. Buffering a long recording synchronously blocks the event loop, so run that work in an appropriate worker.

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

/**
 * @param {import("@ai-coustics/aic-sdk-wasm").Model} model
 * @param {string} token
 * @param {Float32Array} audio
 */
export function analyzeWindow(model, token, audio) {
  const sampleRate = model.getOptimalSampleRate();
  const blockSize = model.getOptimalBlockSize(sampleRate);
  if (audio.length % blockSize !== 0) throw new Error("Expected complete blocks");
  const analyzer = new Analyzer(model, token);
  try {
    analyzer.initialize(sampleRate, blockSize, false);
    for (let offset = 0; offset < audio.length; offset += blockSize) {
      analyzer.buffer(audio.subarray(offset, offset + blockSize));
    }
    const result = analyzer.analyze();
    try {
      return {
        riskScore: result.riskScore,
        speakerReverb: result.speakerReverb,
        speakerLoudness: result.speakerLoudness,
        interferingSpeech: result.interferingSpeech,
        noise: result.noise,
        codecDegradation: result.codecDegradation,
        packetLoss: result.packetLoss,
      };
    } finally {
      result.free();
    }
  } finally {
    try {
      analyzer.terminateSession();
    } finally {
      analyzer.free();
    }
  }
}
```
