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
impl Engine
Sourcepub fn new(cfg: Config) -> Result<Arc<Engine>, Error>
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.
Sourcepub fn wait_ready(&self) -> Result<(), Error>
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.
Sourcepub fn silence_floor(&self) -> f32
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.
Sourcepub fn transcribe(&self, source: impl AudioSource) -> Result<Ticket, Error>
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.
Sourcepub fn transcribe_with(
&self,
source: impl AudioSource,
options: NormalizeOptions,
) -> Result<Ticket, Error>
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.
Sourcepub fn capture_stream(self: &Arc<Self>) -> Result<StreamCapture, Error>
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.