foley.weave.align#
Forced-alignment adapters — the Aligner seam’s fake default + WhisperX real impl.
Forced alignment takes narration audio and its known transcript and returns
word-level timestamps (report 06 §2). foley ships two implementations behind the
Aligner seam, mirroring
foley.agent.decompose’s fake/real discipline exactly:
FakeAligner— the deterministic, torch-free default: it evenly spaces the transcript’s words across the clip’s duration. No model, no network, fully reproducible — so hermetic CI (and any bare install) gets a usableword_timelinewith zero heavy dependencies.WhisperXAligner— the real ≈±50 ms impl behindfoley[align](whisperx+torch), lazy-imported inside its method soimport foley.weavestays dol-only.
Montreal Forced Aligner and aeneas run as external programs
(foley.weave.cli_aligners); inject one with aligner=.
SegmentedAligner wraps any of them for narration made of segments whose
start offsets are known (one audio file per beat, concatenated): it aligns each
segment’s words against that segment’s own slice of the audio and shifts the
timings back, so even the fake spreads words over the right span.
_default_aligner auto-upgrades to WhisperX when foley[align] is installed,
else falls back to the fake — the progressive-disclosure rule.
Module Attributes
Fallback speaking cadence used only when the clip's duration is unknown (empty audio); otherwise |
|
WhisperX runs alignment at 16 kHz mono (its wav2vec2 CTC model's native rate). |
Functions
|
The aligner's |
Classes
Deterministic, torch-free |
|
|
An |
|
The real ≈±50 ms |
- class foley.weave.align.FakeAligner[source]#
Bases:
objectDeterministic, torch-free
Aligner— evenly spaces the transcript’s words.The hermetic default: given a transcript, it returns one
{'word','start','end'}per whitespace token, spread uniformly across the clip’s duration (or atWORDS_PER_SECONDwhen the audio is empty). No transcript → an emptyword_timeline(the render then falls back to absolute anchors).
- class foley.weave.align.SegmentedAligner(starts, segments, *, base=None)[source]#
Bases:
objectAn
Alignerfor narration whose segments start at known offsets.Splits the transcript’s words by segment (each segment’s word count), aligns each piece with
baseagainst that segment’s slice of the audio, and adds the slice’s start to the timings. Segmentispansstarts[i]tostarts[i + 1]; the last runs to the end of the audio; a segment with no words is skipped. Words keep the transcript’s order, so anchors resolve exactly as with a whole-file aligner.baseis called once per segment:WhisperXAlignerloads its models once and reuses them, but a subprocess aligner (MFAAligner,AeneasAligner) starts one process per segment.basemust align the audio it is given: one that returns precomputed whole-file timings should be passed toweave(aligner=)directly, not wrapped.- Parameters:
starts (
Sequence[float]) – Each segment’s start, in seconds into the narration audio (one per segment, non-decreasing).segments (
Sequence[str]) – The segments’ texts; only their word counts are used, to split the transcriptword_timelinereceives.base (
Optional[Aligner]) – The aligner run on each slice (default: WhisperX if installed, else the fake, chosen at first use).
- spans(duration, *, sample_rate)[source]#
Each segment’s
(start, end)in audio ofdurationseconds (ValueErrorif a segment with words starts at or past the end, or spans no sample).
- foley.weave.align.WHISPERX_SAMPLE_RATE: int = 16000#
WhisperX runs alignment at 16 kHz mono (its wav2vec2 CTC model’s native rate).
- foley.weave.align.WORDS_PER_SECOND: float = 2.5#
Fallback speaking cadence used only when the clip’s duration is unknown (empty audio); otherwise
FakeAlignerspreads words across the real audio duration so its timings are audio-length-aware.
- class foley.weave.align.WhisperXAligner(*, model_size='small', device='cpu', batch_size=16)[source]#
Bases:
objectThe real ≈±50 ms
Aligner(foley[align]) — faster-whisper ASR + wav2vec2 CTC.Lazy-imports
whisperxinsideword_timeline()soimport foley.weavestays dol-only. Transcribes (if no transcript) then force-aligns at 16 kHz mono. The loaded models are kept on the instance (per model size, device and language), so aligning many clips, or aSegmentedAligner’s segments, loads them once.- Parameters: