pub struct Stream<'a> { /* private fields */ }Expand description
An active streaming run, borrowed from a Session.
Feed PCM with Stream::feed, read the UI-stable text with
Stream::text, and end input with Stream::finalize. Dropping the
Stream (without finalizing) abandons it and returns the session to idle.
Send but not Sync, like the session it borrows.
The borrow means a session can’t be freed while its stream (or any other call on it) is still in use, so no native free ever races a compute:
use transcribe_cpp::{Model, RunOptions, StreamOptions};
let model = Model::load("model.gguf").unwrap();
let mut session = model.session().unwrap();
let mut stream = session
.stream(&RunOptions::default(), &StreamOptions::default())
.unwrap();
drop(session); // error[E0505]: cannot move out of `session` while borrowed
stream.feed(&[0.0; 160]).unwrap();Implementations§
Source§impl Stream<'_>
impl Stream<'_>
Sourcepub fn feed(&mut self, pcm: &[f32]) -> Result<StreamUpdate>
pub fn feed(&mut self, pcm: &[f32]) -> Result<StreamUpdate>
Feed a chunk of 16 kHz mono float32 PCM and return the change metadata.
Sourcepub fn finalize(&mut self) -> Result<StreamUpdate>
pub fn finalize(&mut self) -> Result<StreamUpdate>
Signal end of input: flush buffered audio and emit the final text. The session transitions to finished.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Abandon the stream and return the session to idle (clears all snapshot
state). Releases the model’s compute lease (the stream is no longer
active), so other sessions of the model can proceed without waiting for
this Stream to drop.
Sourcepub fn text(&self) -> StreamText
pub fn text(&self) -> StreamText
The current UI-facing text snapshot (owned copies).
Sourcepub fn snapshot(&self) -> Transcript
pub fn snapshot(&self) -> Transcript
A full structured snapshot (segments/words/tokens) of the current
hypothesis. For most UIs Stream::text is the better choice.
Sourcepub fn state(&self) -> StreamState
pub fn state(&self) -> StreamState
The stream’s lifecycle state.
Sourcepub fn revision(&self) -> i32
pub fn revision(&self) -> i32
The monotonic snapshot revision; diff against the previous value.
Sourcepub fn last_status(&self) -> Option<Error>
pub fn last_status(&self) -> Option<Error>
The stream’s recorded terminal failure, or None while it is healthy.
Set after a feed / finalize
transitioned the stream to StreamState::Failed; reset by a new
stream. Inspect it when state is Failed to learn why.
Sourcepub fn was_aborted(&self) -> bool
pub fn was_aborted(&self) -> bool
Whether the stream was ended by cancellation.