foley.weave.anchor#
Symbolic-anchor → sample-onset heuristics — the SELECT→WEAVE timing bridge (report 06 §2.4).
Pure, stdlib-only functions that turn a placed sound’s symbolic anchor (SELECT’s
"on 'pushed open'" string, or a resolved Placement) into a
concrete trigger time (seconds) against a forced-aligned word_timeline
([{'word','start','end'}, ...]). Cheapest-first, exactly as report 06 §2.4:
word anchor (one-shots) — fire on the onset of the trigger word;
pre-roll — shift a clip earlier so its salient transient lands on the anchor;
sentence span (beds) — start at the first word of the sentence, run to the last;
scene / paragraph boundary (stingers, ambience swaps) — the boundary’s first word;
pause snapping — nudge an onset to the nearest inter-word gap to avoid masking speech.
These are pure (anchor, word_timeline) -> seconds functions with no I/O and no
heavy dependency, so they are independently unit-testable and keep import
foley.weave dol-only. Every word lookup goes through one resolver,
match_word(), which also says HOW it matched (exact / stem / fuzzy /
fallback); resolve_placement() records that on the resolved placement. foley.weave.anchor.parse_symbolic_anchor is the single
SSOT bridge from SELECT’s sparse TimelineItem.onset string to a
Placement.
Module Attributes
Inter-word gap (seconds) that ends a sentence segment (report 06 §2.4 uses |
|
A stem match needs at least this many letters; a cue shorter than the spoken word must also hold this share of it ( |
|
A fuzzy match needs at least this |
Functions
|
Return the |
|
The |
|
Parse SELECT's sparse symbolic |
|
Resolve a |
|
Resolve a |
- foley.weave.anchor.FUZZY_MIN_RATIO: float = 0.6#
A fuzzy match needs at least this
difflibratio, and a candidate at least this share of the cue’s length:thescores 0.6 againstthunderbut is not it (#257).
- foley.weave.anchor.PREFIX_MIN_CHARS: int = 3#
A stem match needs at least this many letters; a cue shorter than the spoken word must also hold this share of it (
slam→slammed), soanever claimsapple. A spoken word that is a compound cue’s tail must leave a head this long too (foot|steps), soth|underis not a compound ofthunder(#263).
- foley.weave.anchor.SEGMENT_GAP_S: float = 0.35#
Inter-word gap (seconds) that ends a sentence segment (report 06 §2.4 uses
> ~350 msas a lightweight sentence segmenter over the aligned transcript).
- foley.weave.anchor.match_word(ref, word_timeline)[source]#
Return the
word_timelineentry best matchingrefand how it matched (#263).The one word resolver every anchor goes through, cheapest and surest first (earliest occurrence wins at each step): the phrase’s first token exactly; else a word sharing its stem (
_is_stem_match()); else the closest word by lexical (difflib) ratio over any token, among words at leastFUZZY_MIN_LENGTH_SHAREof its length (fuzzy, which can be a false match).(None, MatchKind.fallback)when nothing is close orrefis empty.>>> wt = [{"word": "The"}, {"word": "doors"}, {"word": "slammed."}] >>> [(w["word"], k.value) for w, k in (match_word(c, wt) for c in ("door", "slam"))] [('doors', 'stem'), ('slammed.', 'stem')] >>> match_word("zzzzz", wt) (None, <MatchKind.fallback: 'fallback'>)
- foley.weave.anchor.nearest_word(ref, word_timeline)[source]#
The
word_timelineentry best matchingref(seematch_word()), orNone.
- foley.weave.anchor.parse_symbolic_anchor(onset, *, layer=Layer.sfx_fg, loop=False)[source]#
Parse SELECT’s sparse symbolic
onsetstring into a resolved-laterPlacement.The anchor type follows the item’s role (report 06 §2.4): beds (
loop/ambience/music) span a sentence, stingers land on a scene boundary, and everything else is a word anchor; therefis the quoted phrase the sound lands on. ANoneonset means “no cue”: beds span from the start, one-shots sit atabsolute0. A bare number (defensive — SELECT is told never to emit one) is read as an absolute offset in seconds.- Parameters:
- Return type:
- Returns:
A
Placementwhoseonset(seconds) is resolved later byresolve_anchor()against theword_timeline.
- foley.weave.anchor.resolve_anchor(placement, word_timeline, *, snap_pauses=False)[source]#
Resolve a
Placementto(onset_seconds, duration_seconds_or_None).The tuple view of
resolve_placement()(which also says how it matched).
- foley.weave.anchor.resolve_placement(placement, word_timeline, *, snap_pauses=False)[source]#
Resolve a
Placementagainst theword_timeline— a NEW placement.Dispatches on
placement.anchor(report 06 §2.4):absoluteuses the stored offset;wordfires on the trigger word;sentencespans its sentence (fillingdurationwhen unset — beds loop to fill it);scene/paragraphland on the boundary.pre_rollis then subtracted (clamped at 0), and — whensnap_pauses— the onset snaps to the nearest inter-word gap.match_kindrecords how the anchor matched (MatchKind): a cue with no word timings, or that matched no word, is afallbackat its stored onset (word) or the whole narration (span); a cue-less span isabsolute.- Parameters:
- Return type:
- Returns:
A copy with
onset(seconds),duration(filled only for a span anchor whosedurationwas unset) andmatch_kindresolved.