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.

§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 terminate_session(&mut self) -> Result<(), AicError>

Terminates the telemetry session associated with this analyzer.

Once the request has been handled, the analyzer is no longer allowed to analyze buffered audio.

This function is meant to be used in lifecycle management events. A telemetry session is automatically stopped when an analyzer 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 telemetry session 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
analyzer.terminate_session()?;
Source

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

Replaces the bearer token on a running analyzer.

Use this when your license key is a JWT and needs to be refreshed before it expires. Calling this with a renewed token lets you stay authenticated without tearing down and recreating the analyzer: the analyzer handle stays valid, buffered audio remains available, 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. Other license types cannot be swapped in this way.

On any error the call is a no-op: the previously active token stays in use and the telemetry session is unaffected (no backoff, no interruption to processing).

On success the swap is applied immediately and is not gated on backend acceptance. The token is validated locally for format only; if the backend later rejects it (e.g. expired or revoked), the SDK retries it under backoff rather than rolling back to the prior token, and analysis calls may be rejected if no accepted token arrives in time. Supplying a known-good token via this call during that window recovers the session.

§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> 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