Skip to main content

FileAnalyzer

Struct FileAnalyzer 

Source
pub struct FileAnalyzer<'model, 'a> { /* private fields */ }
Expand description

Analyzes complete mono audio buffers.

FileAnalyzer is a convenience wrapper around a Collector and Analyzer pair for non-real-time analysis of audio that is already loaded in memory.

Each call to analyze configures the collector for mono input with the model’s optimal frame size. It analyzes independent five-second windows, advancing the start of each window by step_samples.

For streaming or multi-channel analysis, use analyzer_pair directly.

Implementations§

Source§

impl<'model, 'a> FileAnalyzer<'model, 'a>

Source

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

Creates a new file analyzer.

The collector is not initialized until analyze is called. This lets the same FileAnalyzer instance analyze mono buffers with different sample rates or step sizes.

§Arguments
  • model - The loaded model instance
  • license_key - license key for the ai-coustics SDK (generate your key at developers.ai-coustics.com)
§Returns

Returns a FileAnalyzer if the analyzer pair can be created, otherwise an AicError.

§Example
let mut analyzer = FileAnalyzer::new(&model, &license_key)?;

let sample_rate = 16_000;
let audio = vec![0.0f32; 8000];
let results = analyzer.analyze(&audio, sample_rate, None)?;
Source

pub fn analyze( &mut self, audio: &[f32], sample_rate: u32, step_samples: Option<usize>, ) -> Result<Vec<AnalysisResult>, AicError>

Analyzes a complete mono audio buffer.

The input slice must contain mono f32 samples at sample_rate. No channel mixing or resampling is performed.

The analyzer evaluates five-second windows. FileAnalyzer buffers a window starting at sample 0, runs the analyzer once, resets the analyzer and collector, then repeats with a window starting step_samples later.

If audio is shorter than or equal to five seconds, it is padded with silence and only one result is returned. For longer signals, only complete five-second windows are analyzed after the first window.

§Arguments
  • audio - Mono audio samples to analyze
  • sample_rate - Sample rate of audio in Hz
  • step_samples - Number of samples to advance between analysis results. Defaults to the model’s window size (no overlap in analysis windows) if None.
§Returns

Returns a list of AnalysisResult values, or an AicError if initialization, buffering, or analysis fails.

§Real-time safety

This function is not real-time safe. Avoid calling it from audio threads.

Auto Trait Implementations§

§

impl<'model, 'a> Freeze for FileAnalyzer<'model, 'a>

§

impl<'model, 'a> RefUnwindSafe for FileAnalyzer<'model, 'a>

§

impl<'model, 'a> Send for FileAnalyzer<'model, 'a>

§

impl<'model, 'a> Sync for FileAnalyzer<'model, 'a>

§

impl<'model, 'a> Unpin for FileAnalyzer<'model, 'a>

§

impl<'model, 'a> UnsafeUnpin for FileAnalyzer<'model, 'a>

§

impl<'model, 'a> UnwindSafe for FileAnalyzer<'model, '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, 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.