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>
impl<'model, 'a> FileAnalyzer<'model, 'a>
Sourcepub fn new(
model: &'model Model<'a>,
license_key: &str,
) -> Result<Self, AicError>
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 instancelicense_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)?;Sourcepub fn analyze(
&mut self,
audio: &[f32],
sample_rate: u32,
step_samples: Option<usize>,
) -> Result<Vec<AnalysisResult>, AicError>
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 analyzesample_rate- Sample rate ofaudioin Hzstep_samples- Number of samples to advance between analysis results. Defaults to the model’s window size (no overlap in analysis windows) ifNone.
§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> 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> 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