Skip to main content

Analyzer

Struct Analyzer 

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

Runs an analysis model over the audio buffered by a Collector.

The analyzer is designed to be run in a non-audio thread. Analysis models are computationally expensive and cannot run in the audio thread. The analyzer has access to the audio buffered by the collector, and it can access it safely across threads.

Implementations§

Source§

impl<'a> Analyzer<'a>

Source

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

Clears all internal state and buffers.

Call this when the audio stream is interrupted or when seeking to prevent mispredictions from previous audio content.

This operates on both the analyzer and its collector.

The Collector stays initialized to the configured settings.

§Returns

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

§Real-time safety

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

§Example
analyzer.reset()?;
Source

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

Analyze the buffered signal.

The analyzer runs a forward-pass of the analysis model with a fixed length of audio, determined by the model.

If this function is called before the collector has buffered that length of audio, the analyzer will run the analysis with silence (zeros) in the tail of the input.

§Note

When buffering, all channels are mixed down to mono. To analyze channels independently, create separate analyzer pairs.

§Returns

Returns an AnalysisResult if successful, otherwise an AicError.

§Real-time safety

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

Source

pub fn update_bearer_token(&self, token: &str) -> Result<(), AicError>

Replaces the bearer token on the analyzer.

Use this when your license key is a JWT and needs to be refreshed before it expires. Audio processing continues uninterrupted, the context handle stays valid, and the new token is used for all subsequent authentication against the ai-coustics backend.

In-place updates are only supported when both the originally configured key and the new token are JWTs. If either side is not, the call returns AicError::TokenUpdateUnsupported and the existing token stays in use.

§Arguments
  • token - The new JWT to install.
§Returns

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

§Real-time safety

This function is not real-time safe. It locks a mutex and allocates memory. Avoid calling it from audio threads.

§Example
let renewed_jwt = String::from("<JWT_BEARER_TOKEN>");
analyzer.update_bearer_token(&renewed_jwt)?;

Trait Implementations§

Source§

impl<'a> Drop for Analyzer<'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 Analyzer<'a>

Source§

impl<'a> Sync for Analyzer<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Analyzer<'a>

§

impl<'a> RefUnwindSafe for Analyzer<'a>

§

impl<'a> Unpin for Analyzer<'a>

§

impl<'a> UnsafeUnpin for Analyzer<'a>

§

impl<'a> UnwindSafe for Analyzer<'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.