Skip to main content

TurnSession

Struct TurnSession 

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

An end-of-turn session.

Implementations§

Source§

impl TurnSession

Source

pub fn set_cancel_token(&mut self, token: &CancelToken)

Install a CancelToken so an in-flight run, feed or flush can be aborted from another thread (the call then returns Error::Aborted). Replaces any previously installed token. A batch feed checks the token of every session in the batch.

Source

pub fn clear_cancel_token(&mut self)

Remove any installed cancel token.

Source

pub fn run(&mut self, pcm: &[f32], options: &TurnOptions) -> Result<TurnResult>

Score one clip of 16 kHz mono float32 PCM (the audio of the current turn, from where the speaker started): has the turn ended at its end? Starts fresh and discards any stream in progress. Audio longer than TurnInfo::max_audio_ms is scored on its tail. Models that can stream also return every frame’s turn (and speech) probability. Error::InvalidArgument (empty or non-finite input, a threshold above 1) leaves the stream and last result unchanged.

Source

pub fn stream_feed(&mut self, pcm: &[f32]) -> Result<TurnResult>

Append audio to the stream and return the turn probabilities of the frames it completed and the speech probabilities of the frames the model judged; a partial frame waits for the next call. On CPU the stream’s probabilities equal a run over the same audio. Error::NotImplemented if the model cannot stream (TurnInfo::frame_samples is 0). Error::InvalidArgument (e.g. NaN input) leaves the stream intact; an abort or processing error resets it to frame 0.

Source

pub fn stream_feed_batch<'s, 'p, I>(batch: I) -> Result<Vec<TurnResult>>
where I: IntoIterator<Item = (&'s mut TurnSession, &'p [f32])>,

Feed several streams of one model in one compute, much faster than one feed per session: each (session, pcm) ends up as after session.stream_feed(pcm), and result i is that session’s. Uses the first session’s thread count and checks every session’s cancel token. Error::InvalidArgument for an empty batch, or from the library for sessions of different models (every stream unchanged); otherwise errors as stream_feed, an abort or processing error resetting every listed stream.

Source

pub fn stream_flush(&mut self) -> Result<TurnResult>

End the stream: process the buffered partial frame, zero padded (one turn probability, or none), and return the speech probabilities of every frame not yet judged. The next feed starts at frame 0; a processing error also resets the stream.

Source

pub fn stream_reset(&mut self)

Drop the stream without processing it; the next feed starts at frame 0. Keeps the last result.

Source

pub fn timings(&self) -> Timings

Model load time plus the last call’s stage timings.

Trait Implementations§

Source§

impl Debug for TurnSession

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for TurnSession

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 Send for TurnSession

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, 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 = !

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.