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>
impl<'a> Analyzer<'a>
Sourcepub fn reset(&self) -> Result<(), AicError>
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()?;Sourcepub fn analyze_buffered(&mut self) -> Result<AnalysisResult, AicError>
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.
Sourcepub fn terminate_session(&mut self) -> Result<(), AicError>
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()?;Sourcepub fn update_bearer_token(&self, token: &str) -> Result<(), AicError>
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§
impl<'a> Send for Analyzer<'a>
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> 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