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

> Process audio blocks and control enhancement state.

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

## `Processor`

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

A synchronous mono enhancement stream. Each instance has its own signal state and retains the model weights. Use one instance per stream and process blocks in order.

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

### `Processor.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-processor-symbol-dispose" />

### `Processor.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-processor-getprocessorcontext" />

### `Processor.getProcessorContext`

```typescript theme={null}
getProcessorContext(): ProcessorContext;
```

Returns a newly owned handle to this processor's shared control state. Repeated calls produce separate handles to the same state. Free each returned context when finished.

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

### `Processor.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-processor-constructor" />

### `Processor.constructor`

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

Creates an enhancement stream using a live `model` and the credential in `license_key`. For browser applications, pass a short-lived JWT supplied by your backend. Enhancement and bypass model types are accepted; dedicated VAD and analysis models are rejected. The constructor can throw for model creation, model type or credential errors. It does not initialize the audio format. No OpenTelemetry configuration argument is exposed.

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

### `Processor.process`

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

Processes one block of normalized mono floating-point samples and writes the enhanced samples back into the same `Float32Array`. Returns `void`. The generated binding copies input into WebAssembly memory and copies processed values back; this is not zero-copy processing. Requires successful initialization and the configured block length. Throws for mismatched audio, disallowed processing or runtime failures. Do not rely on the input remaining unchanged if processing throws.

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

### `Processor.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-processorcontext" />

## `ProcessorContext`

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

A shared control handle returned by `Processor.getProcessorContext`. Its constructor is private. Each returned context is separately owned and must be freed. Freeing a context does not free the processor. A context can retain control state after the processor is freed, but it does not keep an active processing stream alive.

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

### `ProcessorContext.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-processorcontext-symbol-dispose" />

### `ProcessorContext.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-processorcontext-getaudiodelay" />

### `ProcessorContext.getAudioDelay`

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

Returns end-to-end processing delay in samples at the initialized host sample rate, including block adaptation and model delay. Query after initialization or reinitialization. Divide by the host sample rate to convert to seconds.

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

### `ProcessorContext.getParameter`

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

Returns the stored value for a `ProcessorParameter`. Bypass reads as `0` or `1`; enhancement level is a normalized floating-point value.

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

### `ProcessorContext.reset`

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

Requests clearing of signal history on the next processing pass, retaining the initialized audio configuration and parameter values. Use when beginning a new unrelated stream. It does not allocate a new processor or terminate its session.

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

### `ProcessorContext.setParameter`

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

Sets the selected parameter. Both parameters accept finite values from `0` through `1`; out-of-range values and NaN throw `RangeError`. Changes affect subsequent processing. See `ProcessorParameter` below for defaults and interpretation.

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

### `ProcessorContext.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-processorparameter" />

## `ProcessorParameter`

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

Parameters accepted by `ProcessorContext.getParameter` and `setParameter`.

<span id="wasm-processorparameter-bypass" />

### `ProcessorParameter.Bypass`

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

`0` disables bypass; any accepted value greater than `0` enables bypass and reads back as `1`. Default: `0`. Bypass preserves the configured processing delay.

<span id="wasm-processorparameter-enhancementlevel" />

### `ProcessorParameter.EnhancementLevel`

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

Normalized enhancement amount from `0` through `1`. `0` is dry output and `1` uses the model's maximum enhancement. The initial value is the model's default, falling back to `1` when absent.

## Process one block

This helper assumes module initialization has completed, `model` is a live enhancement model, `token` is a backend-issued JWT and `audio` contains exactly one optimal block of mono samples. It copies the caller's block before enhancement, then returns the enhanced block and delay. For a stream, retain the processor across blocks instead of creating it for each call.

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

/**
 * @param {import("@ai-coustics/aic-sdk-wasm").Model} model
 * @param {string} token
 * @param {Float32Array} audio
 */
export function enhanceBlock(model, token, audio) {
  const sampleRate = model.getOptimalSampleRate();
  const blockSize = model.getOptimalBlockSize(sampleRate);
  if (audio.length !== blockSize) throw new Error("Expected one optimal block");
  const processor = new Processor(model, token);
  try {
    processor.initialize(sampleRate, blockSize, false);
    const context = processor.getProcessorContext();
    try {
      const output = audio.slice();
      processor.process(output);
      return { output, delaySamples: context.getAudioDelay() };
    } finally {
      context.free();
    }
  } finally {
    try {
      processor.terminateSession();
    } finally {
      processor.free();
    }
  }
}
```
