Skip to main content

Engine

Struct Engine 

Source
pub struct Engine {
    max_capture: Duration,
    normalize_options: NormalizeOptions,
    silence_floor: f32,
    diagnostics_dir: Option<PathBuf>,
    models: Arc<TakeModels>,
    stopping: Arc<AtomicBool>,
    in_flight: Arc<Mutex<Option<CancelToken>>>,
    jobs: Option<Sender<Job>>,
    worker: Option<JoinHandle<()>>,
    readiness: Arc<Readiness>,
}
Expand description

Loads the models and runs transcriptions, one at a time.

The recognition session needs &mut self to run, so one set of weights means one caller at a time whatever the API looks like.

Fields§

§max_capture: Duration§normalize_options: NormalizeOptions§silence_floor: f32§diagnostics_dir: Option<PathBuf>

Where take diagnostics land, if the caller pointed them anywhere. Held here because the worker consumes the config, and the per-take segmenter writes the record at finish.

§models: Arc<TakeModels>

The models this engine runs, resolved from the config before the worker consumes it: what every take’s diagnostics record names itself by.

§stopping: Arc<AtomicBool>

Set before teardown. The worker checks it between jobs, so a backlog is DISCARDED rather than drained: shutdown should not wait out work whose callers are going away with it.

§in_flight: Arc<Mutex<Option<CancelToken>>>

The running job’s cancel token, so teardown can abort an inference already in progress instead of waiting for it.

§jobs: Option<Sender<Job>>

None only while dropping.

§worker: Option<JoinHandle<()>>§readiness: Arc<Readiness>

Answers Engine::wait_ready once the worker has the weights.

Implementations§

Source§

impl Engine

Source

pub fn new(cfg: Config) -> Result<Arc<Engine>, Error>

Load the configured models and start the worker.

Blocking, like everything else here. Weights load on the worker thread, so this returns without waiting for them; a model that cannot be loaded surfaces from the first Ticket::recv rather than here, because that is where it is first used.

Source

pub fn wait_ready(&self) -> Result<(), Error>

Wait for the weights to be in memory.

Engine::new hands the load to the worker and returns without it, so an engine over a model that cannot be read looks healthy until somebody speaks. This is how a caller learns which one it has before asking anyone to.

Blocking, like everything else here. Returns once every configured model is loaded, or with the Error::ModelLoad a transcription would have failed with, naming the file. Idempotent and safe from several threads: the answer is kept and handed to each caller.

Source

pub fn silence_floor(&self) -> f32

The configured silence floor, in dBFS. A host drawing the capture level bar needs the same floor the silence decision uses, so the meter and the Outcome::NoAudio verdict agree by construction rather than by a host guessing the default.

Source

pub fn transcribe(&self, source: impl AudioSource) -> Result<Ticket, Error>

Queue source for transcription.

Rejects a source the models cannot read before queueing anything. A wrong sample rate or channel count is a caller mistake, knowable the moment the source is handed over, so it is refused here rather than arriving later mixed in with real runtime failures.

Source

pub fn transcribe_with( &self, source: impl AudioSource, options: NormalizeOptions, ) -> Result<Ticket, Error>

Queue source, overriding the configured normalizer options for this transcription only. Styling is a per-recording choice, so it belongs on the call rather than on the engine.

Source

pub fn capture_stream(self: &Arc<Self>) -> Result<StreamCapture, Error>

Start a take fed by pushed frames.

The one refusal is an engine that is winding down, whose drain would discard every job the take queued.

Source

fn begin_take(self: &Arc<Self>, jobs: Sender<Job>) -> TakeParts

The take side: the recording sample_cap samples long, the segmenter cutting windows off it as it grows, and the channels a Capture hands on at finish.

Source

fn submit( &self, pcm: Vec<f32>, resample: Duration, truncated: bool, options: NormalizeOptions, ) -> Result<Ticket, Error>

Queue already-captured audio.

Trait Implementations§

Source§

impl Drop for Engine

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

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
§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more