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

> Processor, ProcessorAsync, contexts, stream ownership 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-Processor" />

## Processor

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

Stateful mono enhancement. Use one instance per independent stream. Mutable borrowing serializes initialization, processing and termination; a separate `ProcessorContext` can control state from another thread. Implements `Drop`, `Send` and `Sync`; it is not `Clone`. Native model storage is retained internally, while `'a` keeps any borrowed model bytes alive. Dropping the model handle does not invalidate the processor, but its borrowed backing bytes must outlive it.

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

### Processor::new

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

Creates an uninitialized processor for an enhancement or bypass model. The credential is an SDK key or JWT. Invalid credentials and incompatible model types return the corresponding `AicError`. Call `initialize` or `with_config` before processing.

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

### Processor::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 processor with explicit [OpenTelemetry settings](/reference/sdk/api/rust/models-and-config#rust-aic_sdk-OtelConfig). Settings and credential data are copied into the native session. A NUL-containing SDK key returns `LicenseFormatInvalid`; a NUL-containing telemetry session ID returns `Internal`.

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

### Processor::with\_config

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

Consumes the processor, calls initialization and returns it on success. On failure, the consumed processor is dropped. Use this to chain construction and initialization.

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

### Processor::initialize

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

Configures the input sample rate and block size, copies the settings and initializes processing state. Invalid configurations return `AudioConfigUnsupported`. This allocates and must run outside the audio callback. If reinitialization fails, do not continue with assumed previous settings; successfully initialize again before processing.

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

### Processor::process

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

Enhances normalized mono samples in place. Fixed mode requires exactly `block_size` samples; variable mode accepts slices up to that size. Returns `NotInitialized`, `AudioConfigMismatch` or `ProcessingNotAllowed` when applicable.

The returned `Result` must be checked even when construction succeeded. The native processor may write delay-preserving fallback samples when processing is disallowed; other errors are not a universal unchanged-buffer guarantee. Handle errors according to your application's continuity policy.

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

### Processor::context

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

Creates a shared control handle. Multiple contexts refer to the same control state, not separate audio streams. Context creation asserts native success rather than returning a `Result`; an internal failure can panic.

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

### Processor::terminate\_session

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

Requests termination of the telemetry and authorization session. Stop submitting work before termination. A successful return is not an acknowledgment that a remote service has received all usage. The object cannot start a new session; create a new processor to resume. This operation 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-ProcessorContext" />

## ProcessorContext

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

Create with `Processor::context` or await `ProcessorAsync::context`. There is no public constructor. Implements `Drop`, `Send` and `Sync`. Contexts share native control state and can be used while another thread processes audio. Dropping a context releases that handle; it does not destroy its processor. Keeping a context does not produce audio after its processor is gone.

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

### ProcessorContext::set\_parameter

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

Sets a parameter using the bounds below. Values outside the accepted range, including NaN, return `ParameterOutOfRange`.

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

### ProcessorContext::parameter

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

Reads the current parameter value. Read the active model's enhancement level rather than assuming a universal model default.

<a id="rust-aic_sdk-ProcessorContext-audio_delay" />

### ProcessorContext::audio\_delay

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

Returns algorithmic and internal buffering delay in samples at the configured input rate, or native rate before initialization. It excludes CPU execution time, scheduling, transport and application queues. Convert using `1000.0 * delay as f64 / sample_rate as f64`. The native query is asserted and can panic on internal failure.

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

### ProcessorContext::reset

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

Requests a reset. The processing path clears its state and buffers on its next processing call, retaining audio configuration. Reset does not reopen a terminated session.

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

### ProcessorContext::update\_bearer\_token

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

Replaces a JWT in a session originally created with a JWT. Otherwise returns `TokenUpdateUnsupported`; an embedded NUL returns `LicenseFormatInvalid`. A rejected replacement is not installed. Successful local replacement does not prove backend acceptance; continue handling processing errors.

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

## ProcessorParameter

```rust theme={null}
pub enum ProcessorParameter { Bypass, EnhancementLevel }
```

Parameter selector. Both variants accept values from 0.0 through 1.0. Implements `Debug`, `Clone`, `Copy`, `PartialEq`, `Eq` and `Hash`, plus conversion to the matching native parameter type. There is no Rust `VoiceGain` variant in this release.

<a id="rust-aic_sdk-ProcessorParameter-Bypass" />

### ProcessorParameter::Bypass

```rust theme={null}
ProcessorParameter::Bypass
```

Zero enables enhancement; any positive accepted value enables delay-preserving bypass. Readback is 0.0 or 1.0. The initial bypass value is 0.0.

<a id="rust-aic_sdk-ProcessorParameter-EnhancementLevel" />

### ProcessorParameter::EnhancementLevel

```rust theme={null}
ProcessorParameter::EnhancementLevel
```

Controls enhancement strength. Quail models adjust suppression, including competing speech for Quail Voice Focus. Rook models adjust mixback for human listening. Initial strength can be model-specific; read `parameter` for the active value.

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

## ProcessorAsync

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

**Requires feature:** `async`. Owns a synchronized processor backed by a shared worker pool. Constructors are synchronous. Methods marked `async` serialize access to this instance through a mutex and run expensive processing work on the pool. Await blocks in stream order and bound pending work; separate instances serve independent streams.

`AIC_NUM_THREADS`, read when the global pool is first created, selects a positive thread count; the default is available CPU parallelism. This type requires `Model<'static>`, from file loading or static embedded data. It implements `Send` and `Sync` through its fields, but not `Clone`; use `Arc` to share it. No cancellation or unbounded queue guarantee is implied.

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

### ProcessorAsync::new

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

Synchronously creates an uninitialized enhancement processor. Construction errors match `Processor::new`.

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

### ProcessorAsync::with\_otel\_config

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

Synchronously creates an uninitialized processor with explicit telemetry settings; errors match the synchronous constructor.

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

### ProcessorAsync::with\_config

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

Consumes the async processor, awaits initialization and returns it. A failed initialization drops the consumed instance.

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

### ProcessorAsync::initialize

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

Copies the configuration, waits for exclusive access and initializes on the processing pool. Unsupported configurations return `AudioConfigUnsupported`.

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

### ProcessorAsync::process

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

Takes ownership of the audio vector, processes it in place on the background pool and returns the vector on success. Input size and sample rules match `Processor::process`. On error the vector is dropped and is not returned, including when the native processor wrote fallback data.

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

### ProcessorAsync::terminate\_session

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

Waits for exclusive access and requests termination on the background pool. Stop submitting audio first; create 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-ProcessorAsync-context" />

### ProcessorAsync::context

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

Waits for the mutex and returns a control handle. This method is async in Rust, unlike the Python wrapper's `get_context`. Internal native context creation failure can panic.

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

## Process one block

This function receives an initialized processor and a normalized mono block from the caller. Errors propagate to the application:

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

fn enhance_block(processor: &mut Processor<'_>, audio: &mut [f32]) -> Result<(), AicError> {
    processor.process(audio)
}
```

With the `async` feature, ownership of the vector passes to the operation:

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

async fn enhance_owned(processor: &ProcessorAsync, audio: Vec<f32>) -> Result<Vec<f32>, AicError> {
    processor.process(audio).await
}
```
