OnlineStream

Struct OnlineStream 

Source
pub struct OnlineStream { /* private fields */ }
Expand description

Context state for streaming speech recognition.

You can do VAD if you want to reduce compute utilization, but feeding constant streaming audio into this is perfectly reasonable. Decoding is incremental and constant latency.

Created by Model::online_stream.

Implementations§

Source§

impl OnlineStream

Source

pub unsafe fn flush_buffers(&mut self)

Flush extant buffers (feature frames) and signal that no further inputs will be made available.

§Safety

Do not call OnlineStream::accept_waveform after calling this function.

That restriction makes it quite useless, so ymmv. I have not observed any problems doing so so long as an intervening call to OnlineStream::reset exists:

unsafe { s.flush_buffers() };
s.decode();
s.reset();
s.accept_waveform(16000, &[ ... ]);

Regardless, upstream docs state not to call OnlineStream::accept_waveform after, so do so at your own risk.

Source

pub fn accept_waveform(&mut self, sample_rate: usize, samples: &[f32])

Accept ((-1, 1)) normalized) input audio samples and buffer the computed feature frames.

Source

pub fn is_ready(&self) -> bool

Returns true if there are enough feature frames for decoding.

Source

pub fn decode(&mut self)

Decode all available feature frames.

Source

pub unsafe fn decode_unchecked(&mut self)

Decode an unspecified number of feature frames.

It is a logic error to call this function when OnlineStream::is_ready returns false.

§Safety

Ensure OnlineStream::is_ready returns true. It is probably not ever worth eliding the check, but hey, you do you.

Source

pub fn decode_batch<I: IntoIterator<Item = Q>, Q: DerefMut<Target = Self>>( streams: I, )

Decode all available feature frames in the provided iterator of streams concurrently.

This batches all operations together, and thus is superior to calling OnlineStream::decode on every OnlineStream in separate threads (though it is not invalid to do so, if desired).

Source

pub fn decode_shared(&mut self)

Decode all available feature frames in a shared concurrency context.

This introduces a small amount of synchronization overhead in exchange for much better compute utilization.

Source

pub fn result(&self) -> Result<String>

Returns recognition state since the last call to OnlineStream::reset.

Source

pub fn result_with<F: FnOnce(Cow<'_, str>) -> R, R>(&self, f: F) -> Result<R>

Returns recognition state since the last call to OnlineStream::reset.

Source

pub fn is_endpoint(&self) -> bool

Returns true if an endpoint has been detected.

Source

pub fn reset(&mut self)

Clear any extant neural network and decoder states.

Source

pub fn sample_rate(&self) -> usize

Returns the native sample rate.

Source

pub fn chunk_size(&self) -> usize

Returns the chunk size at the native sample rate.

The stream becomes ready for decoding once this many samples have been accepted.

Trait Implementations§

Source§

impl Drop for OnlineStream

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for OnlineStream

Source§

impl Sync for OnlineStream

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, 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T