Skip to main content

VadAsync

Struct VadAsync 

Source
pub struct VadAsync { /* private fields */ }
Available on crate feature async only.
Expand description

A wrapper around Vad for use in async contexts.

§Threading

Processing runs on the same background thread pool as ProcessorAsync, shared across all instances. The pool defaults to one thread per logical CPU. Override with the AIC_NUM_THREADS environment variable, which is read once on first use.

§Example

use aic_sdk::{Model, ProcessorConfig, VadAsync};
#[tokio::main]
async fn main() -> Result<(), aic_sdk::AicError> {
    let license_key = std::env::var("AIC_SDK_LICENSE").unwrap();
    let model = Model::from_file("/path/to/vad_model.aicmodel")?;
    let config = ProcessorConfig::optimal(&model);

    let vad = VadAsync::new(&model, &license_key)?.with_config(&config).await?;
    let vad_ctx = vad.context().await;

    let mut audio = vec![0.0f32; config.block_size];
    for _ in 0..2 {
        // `process` hands the block back, so the same allocation can be reused.
        audio = vad.process(audio).await?;
        println!("Speech detected: {}", vad_ctx.is_speech_detected());
    }
    Ok(())
}

Implementations§

Source§

impl VadAsync

Source

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

Creates a new async voice activity detector instance.

See Vad::new for details.

Source

pub fn with_otel_config( model: &Model<'static>, license_key: &str, otel_config: &OtelConfig, ) -> Result<Self, AicError>

Creates a new async voice activity detector instance with explicit OpenTelemetry configuration.

See Vad::with_otel_config for details.

Source

pub async fn with_config( self, config: &ProcessorConfig, ) -> Result<Self, AicError>

Initializes the async VAD with the given configuration.

This is a convenience method that calls VadAsync::initialize internally and returns self.

Source

pub async fn initialize(&self, config: &ProcessorConfig) -> Result<(), AicError>

Initializes the VAD with the given configuration.

See Vad::initialize for details.

§Warning

This allocates memory internally. Do not call from latency-sensitive paths.

Source

pub async fn process(&self, audio: Vec<f32>) -> Result<Vec<f32>, AicError>

Processes mono audio and updates the VAD prediction.

This method takes ownership of audio, moves it to a background processing thread, and returns the audio block unmodified. Ownership is required because the background thread outlives the borrow if this future is cancelled; handing the block back lets a streaming loop reuse the same allocation for every block.

See Vad::process for details.

Source

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

Terminates the telemetry session associated with this VAD.

See Vad::terminate_session for details.

§Warning

This may block until the session is terminated, so it runs on the background thread pool rather than the calling task.

Source

pub async fn context(&self) -> VadContext

Returns a VadContext to read the prediction and control parameters.

See Vad::context for details.

Auto Trait Implementations§

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