Skip to main content

Processor

Struct Processor 

Source
pub struct Processor<'a> { /* private fields */ }
Expand description

High-level wrapper for the ai-coustics audio enhancement processor.

A processor is created from an enhancement or bypass model. For voice activity detection, create a Vad from a VAD model instead.

This struct provides a safe, Rust-friendly interface to the underlying C library. It handles memory management automatically and converts C-style error codes to Rust Result types.

§Example

use aic_sdk::{Model, ProcessorConfig, Processor};

let license_key = std::env::var("AIC_SDK_LICENSE").unwrap();
let model = Model::from_file("/path/to/model.aicmodel")?;
let config = ProcessorConfig {
    block_size: 1024,
    ..ProcessorConfig::optimal(&model)
};

let mut processor = Processor::new(&model, &license_key)?.with_config(&config)?;

let mut audio_block = vec![0.0f32; config.block_size];
processor.process(&mut audio_block)?;

Implementations§

Source§

impl<'a> Processor<'a>

Source

pub fn new(model: &Model<'a>, license_key: &str) -> Result<Self, AicError>

Creates a new audio enhancement processor instance.

Multiple processors can be created to process different audio streams simultaneously or to switch between different enhancement algorithms during runtime.

The same Model may be passed to this function more than once: each call creates an independent processor that shares the underlying model data internally.

§Arguments
§Returns

Returns a Result containing the new Processor instance or an AicError if creation fails.

§Example
let license_key = std::env::var("AIC_SDK_LICENSE").unwrap();
let model = Model::from_file("/path/to/model.aicmodel")?;
let processor = Processor::new(&model, &license_key)?;
Source

pub fn with_otel_config( model: &Model<'a>, license_key: &str, otel_config: &OtelConfig, ) -> Result<Self, AicError>

Creates a new audio enhancement processor instance with explicit OpenTelemetry configuration.

If provided, telemetry will be sent according to the provided configuration. Otherwise it will be configured according to the runtime environment.

This overrides the SDK’s environment-based telemetry defaults (e.g. AIC_SDK_OTEL_ENABLE) for this processor.

§Example
let model = Model::from_file("/path/to/model.aicmodel")?;
let otel = OtelConfig::enabled();

let processor = Processor::with_otel_config(&model, &license_key, &otel)?;
Source

pub fn with_config(self, config: &ProcessorConfig) -> Result<Self, AicError>

Initializes the processor with the given configuration.

This is a convenience method that calls Processor::initialize internally and returns self. The processor is immediately ready to process audio after calling this method, so you don’t need to call Processor::initialize separately.

§Arguments
  • config - Audio processing configuration
§Returns

Returns Ok(Self) with the initialized processor, or an AicError if initialization fails.

§Example
let license_key = std::env::var("AIC_SDK_LICENSE").unwrap();
let model = Model::from_file("/path/to/model.aicmodel")?;
let config = ProcessorConfig::optimal(&model);

let mut processor = Processor::new(&model, &license_key)?.with_config(&config)?;

// Processor is ready to use - no need to call initialize()
let mut audio_block = vec![0.0f32; config.block_size];
processor.process(&mut audio_block)?;
Source

pub fn context(&self) -> ProcessorContext

Creates a ProcessorContext instance. This can be used to control all parameters and other settings of the processor.

§Example
let license_key = std::env::var("AIC_SDK_LICENSE").unwrap();
let model = Model::from_file("/path/to/model.aicmodel")?;
let processor = Processor::new(&model, &license_key)?;
let processor_context = processor.context();
Source

pub fn initialize(&mut self, config: &ProcessorConfig) -> Result<(), AicError>

Configures the processor for specific audio settings.

This function must be called before processing any audio. For the lowest delay use the sample rate and block size returned by Model::optimal_sample_rate and Model::optimal_block_size.

§Arguments
  • config - Audio processing configuration
§Returns

Returns Ok(()) on success or an AicError if initialization fails.

§Warning

Do not call from audio processing threads as this allocates memory.

§Example
let config = ProcessorConfig::optimal(&model);
processor.initialize(&config)?;
Source

pub fn process(&mut self, audio: &mut [f32]) -> Result<(), AicError>

Processes mono audio.

Enhances speech in the provided audio block in-place.

§Arguments
  • audio - Mono audio block to be enhanced in-place. Must match block_size from initialization, or if variable_block_size was enabled, must be less than or equal to block_size.
§Returns

Returns Ok(()) on success or an AicError if processing fails.

§Real-time safety

Real-time safe. Can be called from audio processing threads.

§Example
let config = ProcessorConfig::optimal(&model);
processor.initialize(&config)?;
let mut audio = vec![0.0f32; config.block_size];
processor.process(&mut audio)?;
Source

pub fn terminate_session(&mut self) -> Result<(), AicError>

Terminates the telemetry session associated with this processor.

Once the request has been handled, the processor is no longer allowed to process audio.

This function is meant to be used in lifecycle management events. A telemetry session is automatically stopped when a processor is destroyed. However, in cases where this SDK is integrated with languages with automatic memory management, object deallocation could be delayed. Use this function to terminate the session explicitly.

This function blocks until the telemetry session is terminated, unless another session is still alive. In that case, this function returns early and termination happens asynchronously. This keeps lifecycle management smooth while ensuring all sessions are closed when the last processor is terminated.

§Returns

Returns Ok(()) on success or an AicError if termination cannot be requested.

§Real-time safety

This function is not real-time safe. It may block until the session is terminated. Avoid calling it from audio threads.

§Example
let mut processor = Processor::new(&model, &license_key)?;
processor.terminate_session()?;

Trait Implementations§

Source§

impl<'a> Drop for Processor<'a>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<'a> Send for Processor<'a>

Source§

impl<'a> Sync for Processor<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Processor<'a>

§

impl<'a> RefUnwindSafe for Processor<'a>

§

impl<'a> Unpin for Processor<'a>

§

impl<'a> UnsafeUnpin for Processor<'a>

§

impl<'a> UnwindSafe for Processor<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more