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>
impl<'a> Processor<'a>
Sourcepub fn new(model: &Model<'a>, license_key: &str) -> Result<Self, AicError>
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
model- The loaded model instance. Must be an enhancement or bypass model, otherwiseAicError::ModelTypeUnsupportedis returned.license_key- license key for the ai-coustics SDK (generate your key at developers.ai-coustics.com)
§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)?;Sourcepub fn with_otel_config(
model: &Model<'a>,
license_key: &str,
otel_config: &OtelConfig,
) -> Result<Self, AicError>
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)?;Sourcepub fn with_config(self, config: &ProcessorConfig) -> Result<Self, AicError>
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)?;Sourcepub fn context(&self) -> ProcessorContext
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();Sourcepub fn initialize(&mut self, config: &ProcessorConfig) -> Result<(), AicError>
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)?;Sourcepub fn process(&mut self, audio: &mut [f32]) -> Result<(), AicError>
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 matchblock_sizefrom initialization, or ifvariable_block_sizewas enabled, must be less than or equal toblock_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)?;Sourcepub fn terminate_session(&mut self) -> Result<(), AicError>
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§
impl<'a> Send for Processor<'a>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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