pub struct VadAsync { /* private fields */ }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
impl VadAsync
Sourcepub fn new(model: &Model<'static>, license_key: &str) -> Result<Self, AicError>
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.
Sourcepub fn with_otel_config(
model: &Model<'static>,
license_key: &str,
otel_config: &OtelConfig,
) -> Result<Self, AicError>
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.
Sourcepub async fn with_config(
self,
config: &ProcessorConfig,
) -> Result<Self, AicError>
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.
Sourcepub async fn initialize(&self, config: &ProcessorConfig) -> Result<(), AicError>
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.
Sourcepub async fn process(&self, audio: Vec<f32>) -> Result<Vec<f32>, AicError>
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.
Sourcepub async fn terminate_session(&self) -> Result<(), AicError>
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.
Sourcepub async fn context(&self) -> VadContext
pub async fn context(&self) -> VadContext
Returns a VadContext to read the prediction and control parameters.
See Vad::context for details.
Auto Trait Implementations§
impl !RefUnwindSafe for VadAsync
impl !UnwindSafe for VadAsync
impl Freeze for VadAsync
impl Send for VadAsync
impl Sync for VadAsync
impl Unpin for VadAsync
impl UnsafeUnpin for VadAsync
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