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

> Collector, Analyzer, FileAnalyzer and AnalysisResult 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/). These APIs do not require the `async` feature. Import types from `aic_sdk`; signatures below are declarations.

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

## analyzer\_pair

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

Creates a collector and analyzer for a Tyto analysis model and an SDK key or JWT. The collector buffers a model-defined span of audio; new audio replaces older samples. Run expensive analysis separately from collection. Invalid credentials, incompatible model types and native creation failures return `AicError`.

The pair shares native audio state. Retained model storage keeps weights available after dropping the model handle; borrowed model bytes must still outlive the analyzer. There are no public `Collector::new` or `Analyzer::new` constructors. This function accepts no `OtelConfig`. Its native creation path disables optional OpenTelemetry export; SDK authorization and session reporting requirements remain separate.

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

## Collector

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

A buffering handle created by `analyzer_pair`. Implements `Drop`, `Send` and `Sync`; it is not `Clone`. Collection uses mutable access and can run on a separate thread from the paired analyzer. Dropping it releases its native handle.

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

### Collector::initialize

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

Configures the actual input rate and sample count. Use `ProcessorConfig::optimal(model)` as a starting point. The configuration is copied; unsupported combinations return `AudioConfigUnsupported`. This allocates and must run outside the audio callback.

<a id="rust-aic_sdk-Collector-buffer" />

### Collector::buffer

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

Reads normalized mono samples without modifying the slice. Requires initialization and the configured length, or a length up to `block_size` with variable blocks enabled. Returns `NotInitialized` or `AudioConfigMismatch` when applicable. The call buffers audio; it does not return a score or perform the expensive analysis forward pass.

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

## Analyzer

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

Analyzes audio buffered by the paired collector. Implements `Drop`, `Send` and `Sync`; it is not `Clone`. Mutable access serializes analysis and termination. The lifetime keeps borrowed model bytes alive; native handles retain model storage. Dropping the analyzer releases its handle and requests session shutdown.

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

### Analyzer::reset

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

Requests reset of the shared collector state. The next collection pass clears buffered/delayed state while preserving configuration. Until then, analysis uses a zero-filled snapshot instead of the previously published audio. Use this at an application stream boundary; reset does not restore authorization or reopen a terminated session.

<a id="rust-aic_sdk-Analyzer-analyze_buffered" />

### Analyzer::analyze\_buffered

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

Runs the model over the latest buffered span and returns a score snapshot. Incomplete initial input is padded with silence. This is blocking computation and must run outside the audio callback. Authorization failures return `ProcessingNotAllowed` with no result. Repeated calls without fresh audio are not fresh independent observations.

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

### Analyzer::terminate\_session

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

Requests session termination. Stop analysis and treat the session as closed. Native work becomes disallowed when the lifecycle task handles the signal; with other sessions alive this can happen after the method returns. It may block for final-session shutdown. Success is not a universal remote usage acknowledgment. Create a new pair for another session.

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

### Analyzer::update\_bearer\_token

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

Updates a JWT in a session originally created with a JWT. Returns `TokenUpdateUnsupported` for unsupported credential types and `LicenseFormatInvalid` for embedded NUL characters. Local replacement does not prove backend acceptance; keep checking analysis errors.

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

## FileAnalyzer

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

Convenience analysis for a mono buffer already decoded into memory. It does not open or decode an audio file. It owns a collector/analyzer pair and **borrows the `Model` itself for `'model`**; keep that model handle alive, as well as any bytes borrowed for `'a`. This is stricter than using `analyzer_pair` directly. Its owned fields release native resources on drop.

There is no public token-update, reset or session-termination method on this type. Use `Analyzer` directly when those lifecycle controls are required. Calls require mutable access and must be serialized.

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

### FileAnalyzer::new

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

Creates the internal pair for a Tyto model. The collector is initialized by each `analyze` call, allowing different input rates on subsequent calls. Credential and model errors match `analyzer_pair`.

<a id="rust-aic_sdk-FileAnalyzer-analyze" />

### FileAnalyzer::analyze

```rust theme={null}
pub fn analyze(
    &mut self,
    audio: &[f32],
    sample_rate: u32,
    step_samples: Option<usize>,
) -> Result<Vec<AnalysisResult>, AicError>
```

Reads normalized mono samples at their actual `sample_rate`, leaving the slice unchanged. The native collector handles supported non-native rates; this method does not mix channels. It initializes the collector at the model's preferred block size and analyzes independent five-second windows.

`step_samples` is the advance between window starts. `None` uses `5 * sample_rate`; smaller positive values overlap windows and larger values leave gaps. Rate zero or step zero returns `AudioConfigUnsupported`, as does an unsupported native configuration. Other initialization, buffering or analysis errors propagate as `AicError` without a partial result vector.

Empty input and buffers up to five seconds produce one silence-padded result. Longer buffers produce only complete windows on the step grid starting at zero; partial trailing windows are omitted. Each window resets the analysis/collection state. The operation allocates and performs blocking computation; run it outside the audio callback.

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

## AnalysisResult

```rust theme={null}
pub struct AnalysisResult {
    pub risk_score: f32,
    pub speaker_reverb: f32,
    pub speaker_loudness: f32,
    pub interfering_speech: f32,
    pub noise: f32,
    pub codec_degradation: f32,
    pub packet_loss: f32,
}
```

An owned score snapshot. Its public fields are writable Rust values; changing them does not change the analyzer. Implements `Debug`, `Clone` and `PartialEq`, plus conversion from the native result struct. Values returned by the model lie between 0.0 and 1.0. They are not calibrated failure probabilities for your downstream system.

<a id="rust-aic_sdk-AnalysisResult-risk_score" />

<a id="rust-aic_sdk-AnalysisResult-speaker_reverb" />

<a id="rust-aic_sdk-AnalysisResult-speaker_loudness" />

<a id="rust-aic_sdk-AnalysisResult-interfering_speech" />

<a id="rust-aic_sdk-AnalysisResult-noise" />

<a id="rust-aic_sdk-AnalysisResult-codec_degradation" />

<a id="rust-aic_sdk-AnalysisResult-packet_loss" />

| Field                     | Interpretation                                                                 |
| ------------------------- | ------------------------------------------------------------------------------ |
| `risk_score: f32`         | Overall audio risk for downstream speech processing; lower is less problematic |
| `speaker_reverb: f32`     | Speaker distance/reverberance; lower is less problematic                       |
| `speaker_loudness: f32`   | Relative loudness dimension; lower is not universally better                   |
| `interfering_speech: f32` | Interference from other speakers; lower is less problematic                    |
| `noise: f32`              | Ambient/environmental noise; lower is less problematic                         |
| `codec_degradation: f32`  | Lossy codec artifacts; lower is less problematic                               |
| `packet_loss: f32`        | Dropouts/discontinuities; lower is less problematic                            |

## Borrowing example

This reference function accepts a loaded Tyto model, decoded mono audio and a credential from its caller. Use the [Rust guide](/reference/sdk/language-bindings/rust) for project setup.

```rust theme={null}
use aic_sdk::{AicError, AnalysisResult, FileAnalyzer, Model};

fn analyze_audio(
    model: &Model<'_>,
    sdk_key: &str,
    audio: &[f32],
    sample_rate: u32,
) -> Result<Vec<AnalysisResult>, AicError> {
    let mut analyzer = FileAnalyzer::new(model, sdk_key)?;
    analyzer.analyze(audio, sample_rate, None)
}
```

See [Tyto analysis](/models/audio-insight/real-time-analysis), [errors and features](/reference/sdk/api/rust/errors-and-features) and the [symbol index](/reference/sdk/api/rust/index).
