pub struct TurnSession { /* private fields */ }Expand description
An end-of-turn session.
Implementations§
Source§impl TurnSession
impl TurnSession
Sourcepub fn set_cancel_token(&mut self, token: &CancelToken)
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.
Sourcepub fn clear_cancel_token(&mut self)
pub fn clear_cancel_token(&mut self)
Remove any installed cancel token.
Sourcepub fn run(&mut self, pcm: &[f32], options: &TurnOptions) -> Result<TurnResult>
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.
Sourcepub fn stream_feed(&mut self, pcm: &[f32]) -> Result<TurnResult>
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.
Sourcepub fn stream_feed_batch<'s, 'p, I>(batch: I) -> Result<Vec<TurnResult>>
pub fn stream_feed_batch<'s, 'p, I>(batch: I) -> Result<Vec<TurnResult>>
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.
Sourcepub fn stream_flush(&mut self) -> Result<TurnResult>
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.
Sourcepub fn stream_reset(&mut self)
pub fn stream_reset(&mut self)
Drop the stream without processing it; the next feed starts at frame 0. Keeps the last result.