Skip to main content

Module engine

Module engine 

Source
Expand description

The transcription engine and the tickets it hands back.

Re-exportsΒ§

use std::path::Path; πŸ”’
use std::path::PathBuf; πŸ”’
use std::sync::atomic::AtomicBool; πŸ”’
use std::sync::atomic::Ordering; πŸ”’
use std::sync::mpsc::Receiver; πŸ”’
use std::sync::mpsc::RecvTimeoutError; πŸ”’
use std::sync::mpsc::Sender; πŸ”’
use std::sync::mpsc::channel; πŸ”’
use std::sync::Arc; πŸ”’
use std::sync::Condvar; πŸ”’
use std::sync::Mutex; πŸ”’
use std::sync::Once; πŸ”’
use std::sync::PoisonError; πŸ”’
use std::time::Duration; πŸ”’
use std::time::Instant; πŸ”’
use transcribe_cpp::CancelToken; πŸ”’
use transcribe_cpp::Feature; πŸ”’
use transcribe_cpp::Model; πŸ”’
use transcribe_cpp::RunOptions; πŸ”’
use transcribe_cpp::Session; πŸ”’
use crate::audio::AudioSource; πŸ”’
use crate::audio::SAMPLE_RATE; πŸ”’
use crate::diagnostics; πŸ”’
use crate::normalize::NormalizeOptions; πŸ”’
use crate::Config; πŸ”’
use crate::Error; πŸ”’

StructsΒ§

Capture
One take in flight: the recording it grows, its segmenter, and the channels finish hands on.
CaptureMeter
The polling view of a live capture: the level read and the cap flag, over a shared handle to the recording. Sync and Send, so an async host can hold it across await points.
Engine
Loads the models and runs transcriptions, one at a time.
FinishTake πŸ”’
What the host hands a pipelined take at finish: the normalizer options for the one join pass, and whether the recording stopped itself at the cap.
FrameSink
The write half of a stream-fed take.
Job πŸ”’
One queued transcription.
JobOutcome πŸ”’
What one job’s answer and diagnostics record come to.
Loaded πŸ”’
Every configured model, in memory.
Readiness πŸ”’
How the weights ended up, once the worker has resolved them.
Stages
Where the time went in one transcription.
StreamCapture
A take fed by frames from somewhere other than a device: what Engine::capture_stream hands back.
TakeParts πŸ”’
The take side both capture paths share, from Engine::begin_take: the recording samples land in, the segmenter cutting it, and the channels a capture hands on at finish.
TakeSegmenter πŸ”’
One capture’s segmenter: cuts windows off the growing recording as they pass the reliability ceiling and queues each for recognition while the microphone keeps running; at finish it submits the tail, waits out every segment, and normalizes the join exactly once, on the worker where the normalizer lives. No partial text is ever produced - the only thing that leaves this thread before the answer is the progress count.
TakeShared πŸ”’
The channels a take’s segmenter shares with its capture and ticket.
TakeState πŸ”’
The take’s accumulated state across its windows.
Ticket
A transcription in flight. On the pipelined capture path this is the take’s AGGREGATE: it resolves once every segment and the tail have run and the join has been normalized once.
Transcript
Clean text, plus what it was before normalization.
WindowProgress
How far a take’s transcription has got, for a host that shows progress while the recording runs. done counts the segments that have settled, in order; total is None until finish has submitted the tail, because a live recording does not know how many segments it will produce. A single-segment take reports twice at stop, at 0 of 1 and 1 of 1, and no host has to special-case it.

EnumsΒ§

Aggregate πŸ”’
What a take’s settled parts come to, before normalization.
Outcome
What a finished transcription produced.
Part πŸ”’
One settled piece of a pipelined take, in submission order.
WindowAction πŸ”’
What one window’s run outcome tells the take to do next.

ConstantsΒ§

ENERGY_FRAME πŸ”’
20 ms energy frames for pause-seeking.
SEGMENT_POLL πŸ”’
How often the segmenter looks for the next window boundary. The cut needs no samples past WINDOW_TARGET after the previous cut, so this cadence bounds how long a segment can run past its ideal cut.
WINDOW_MIN πŸ”’
Shortest a sought window may be, so pause-seeking cannot shred a take into fragments too short to transcribe well. The take’s final window is exempt: it is whatever audio is left.
WINDOW_TARGET πŸ”’
Long takes are transcribed in windows rather than as one pass: the recognition runtime decodes a whole buffer against one encoder output, and past about two minutes the decoder derails into repetition loops and skip-ahead re-syncs that drop mid-take audio with nothing flagged. The ceiling is measured, not assumed: a four-minute ten-paragraph take loses whole paragraphs at a 90 s ceiling and lands complete at 60 s, so 60 is the shipping value.

StaticsΒ§

ROUTE_NATIVE_LOGS πŸ”’
Native diagnostics are routed once per process, before any model is loaded: unrouted, one load plus one inference writes 122 lines straight to stderr and corrupts any host that owns it.

FunctionsΒ§

aggregate_parts πŸ”’
Fold a take’s parts in submission order. A failure fails the take only when no part produced words; when any part did, the take keeps them and carries the first failure to the caller, which marks the transcript truncated. A cancel is the one exception: an abandoned take keeps nothing. Any recognized part sends the take down the join path, and only a take with nothing above the floor anywhere reads as silence.
audio_duration πŸ”’
Samples to wall-clock at the one rate the models accept. Integer maths so a long buffer cannot drift through a float cast.
diagnostic_outcome πŸ”’
The store entry a job’s answer earns: None keeps nothing.
failure_before_answer πŸ”’
The failure a job answers with, decided before its answer is built.
finalize_transcript πŸ”’
The joined raw recognition, and the rewritten text over it, in that order. The order is load-bearing: the normalizer reads the whole take at once, so a sentence crossing a window boundary is repaired with full context - normalizing per window would rewrite each fragment without the context around the cut.
finish_after_join πŸ”’
The answer a finished join amounts to.
finish_job πŸ”’
Finish one job: read its token, build the answer, decide its record.
fold_stages πŸ”’
Sum of the parts’ recognition work, for the take’s own stages and the diagnostics record.
join_window_texts πŸ”’
Window texts back into one transcript. Trims and drops empties, so a silent stretch inside a take vanishes at the join instead of leaving a doubled space.
keep_job_record πŸ”’
Keep one direct job’s diagnostics record.
kept_diagnostics πŸ”’
The store entry a finished answer earns, read with the cancel token at the write decision.
load_models πŸ”’
Load the recognition model, and the normalizer when one is configured.
next_cut πŸ”’
Where the next window past start ends, once more than WINDOW_TARGET has accrued past it: the quietest ENERGY_FRAME block between WINDOW_MIN and WINDOW_TARGET past start. None while the region is still short.
normalize_text πŸ”’
Rewrite recognition output, recording what it cost.
peak_dbfs πŸ”’
Loudest sample in pcm, in dBFS.
quietest_frame πŸ”’
Sample offset of the quietest ENERGY_FRAME block by summed square. Ties go to the latest block, so a window runs as long as the reliability ceiling allows and a flat pause cuts at its end. Zero for a region shorter than one block.
take_is_truncated πŸ”’
Whether a take that kept some words is still incomplete: a segment’s own truncation, the capture cap, or a failed segment.
window_action πŸ”’
window_bounds πŸ”’
Sample ranges tiling pcm, each at most WINDOW_TARGET long, cutting at the quietest ENERGY_FRAME block between WINDOW_MIN and WINDOW_TARGET past the previous cut. A take that fits one window comes back whole, which is the exact buffer the recognition runtime saw before windowing existed.
worker πŸ”’
Owns the weights and drains the queue.