foley.base#

Canonical data models for foley — the single source of truth (SSOT) types.

This module is stdlib-only and declarative: it defines the dataclasses, enums, and affordance registries every other layer shares, plus generic dict/JSON (de)serialization. It contains NO policy (see foley.licensing) and NO I/O (see foley.stores / foley.audio).

Serialization contract:

  • record.to_dict() -> a plain dict (nested dataclasses recursed via dataclasses.asdict; enum members preserved, and JSON-safe because every enum subclasses str).

  • record.to_json() -> a JSON string.

  • Cls.from_dict(d) / Cls.from_json(s) -> reconstructs, coercing enum fields from their string values and nested LicenseRecord from its dict. Unknown keys are ignored (forward-compatible schema evolution); missing keys fall back to field defaults.

Module Attributes

SUSPECT_MATCH_KINDS

The match kinds whose sound may not sit on its cue word, and why — the SSOT the weave notes and the taste eval both flag (#263).

QUERY_AFFORDANCES

Unified query-stage parameters (search / find / filter surface).

GENERATION_AFFORDANCES

Unified generation-stage parameters (generate backends map onto these).

EDIT_AFFORDANCES

an edit is a generation whose input includes a source clip.

EDIT_OPS

each is offered by two or more providers).

EDIT_TRANSFORMATION

The kind of the transformations entry an edit appends to its clip's licence (#162): what it derives from (see foley.sources.edit.EditLineage).

ISO_COUNTRY_CODES

The ISO 3166-1 alpha-2 country codes (the 249 officially assigned).

TERRITORY_ALIASES

the UK's common one and the EU's code for Greece.

WORLDWIDE

The territory of a sound used everywhere (online publishing reaches every country): a licence that excludes any territory refuses it (#175).

MASTER_PROFILES

The named delivery targets (report 06 §5.2).

Functions

check_edit_args(op, affordances, *[, ...])

Raise ValueError unless affordances are a valid call of the edit op.

checked_layers(layers)

layers (names or Layer members) as a set of members, checked up front so a typo raises before any paid call (reeleehq/foley#316).

normalize_territory(territory)

territory as an ISO 3166-1 alpha-2 code (or WORLDWIDE), None when unstated.

reject_renamed(names[, vocabulary])

Raise TypeError if any of names is an affordance's old spelling.

resolve_master(master)

Resolve a master spec (profile name, explicit profile, or None) to a MasterProfile.

Classes

AcquisitionMethod(*values)

How a sound entered foley (retrieval channel or origin).

Affordance(name, type, description[, ...])

Descriptor for a unified parameter affordance (arioso analog).

Anchor(*values)

How a WEAVE Placement binds its symbolic time to the narration (report 06 §2.4).

Candidate(sound[, origin, event, ...])

A ranked, license-checked, (optionally) verified sound for one SoundEvent.

CandidateOrigin(*values)

Whether a candidate was retrieved from the index or freshly generated.

EditOp(name, description[, requires, ...])

One edit operation and the EDIT_AFFORDANCES it takes (a row of EDIT_OPS).

IntendedUse([commercial, publish, ...])

What the caller intends to do with a sound; consumed by keep().

Layer(*values)

Mix layer (shared by SoundEvent now and TimelineItem later).

LicenseRecord(source[, source_id, ...])

Per-sound rights + provenance.

MasterProfile([target_lufs, true_peak_db, ...])

Loudness master target — the delivery spec as data, not code (report 06 §5.2).

MatchKind(*values)

HOW a Placement's anchor was resolved against the narration (#263).

Placement([anchor, ref, onset, pre_roll, ...])

WHERE/WHEN a clip sits — a symbolic anchor plus its resolved time (report 06 §6.3).

Processing([gain_db, pan, distance, ...])

HOW a clip sounds — all optional with identity defaults (report 06 §3, §6.3).

Salience(*values)

How prominent a sound event is within a passage.

SerializableMixin()

Adds to_dict/to_json/from_dict/from_json to a dataclass.

SoundDesignTimeline([items, ...])

The editable, re-renderable sound-design plan — the SELECT→WEAVE bridge and render SSOT.

SoundEvent(query[, layer, diegetic, ...])

One salient, physically-audible event decomposed from a passage.

SoundRecord(id[, content_sha256, hash_algo, ...])

Canonical SSOT per sound.

StorageMode(*values)

How a sound's bytes are held (DERIVED from license.cache_bytes_ok).

TimelineItem(clip_ref[, onset, gain, layer, ...])

One placed sound on the sound-design timeline — sparse seed + resolved render fields.

Verdict(match, confidence[, reason, level])

The result of one verification rung for a candidate.

VerifyLevel(*values)

Which rung of the verification ladder produced a Verdict.

class foley.base.AcquisitionMethod(*values)[source]#

Bases: str, Enum

How a sound entered foley (retrieval channel or origin).

class foley.base.Affordance(name, type, description, default=None, stage='query', carries_meaning=False, choices=None, renamed_from=None, bounds=None)[source]#

Bases: object

Descriptor for a unified parameter affordance (arioso analog).

name#

Canonical parameter name used at the façade level.

Type:

str

type#

Expected Python type.

Type:

type

description#

Human-readable description.

Type:

str

default#

Default value (None = no default / required).

Type:

Any

stage#

'query' (search/find/filter) or 'generate'.

Type:

str

carries_meaning#

Dropping it would change what the caller gets (a seed they will rely on to reproduce, content they asked to exclude), so a backend that cannot honour it raises instead of dropping it (#53).

Type:

bool

choices#

The values it accepts, when it is an enumeration (sort, kind); any other value raises ValueError before any call.

Type:

Optional[tuple]

renamed_from#

The name it had before a release renamed it (#75): passing the old name raises a TypeError naming this one (see reject_renamed()). For a generation affordance, the generations cache still reads entries kept under the old name.

Type:

Optional[str]

bounds#

(lo, hi) for a number (either end None: open), checked before any call where the affordance’s registry says so (see check_edit_args()).

Type:

Optional[tuple]

class foley.base.Anchor(*values)[source]#

Bases: str, Enum

How a WEAVE Placement binds its symbolic time to the narration (report 06 §2.4).

absolute is a fixed offset; the rest resolve against the forced-aligned word_timeline — word to a trigger word’s onset, sentence across a sentence span, scene/paragraph to a boundary’s first spoken word.

class foley.base.Candidate(sound, origin=CandidateOrigin.retrieved, event=None, clap_score=None, bm25_score=None, rrf_score=None, rerank_score=None, verdict=None, license_ok=None, preview_uri=None, notes=list(), cost_estimate_usd=None, cost_actual_usd=None)[source]#

Bases: SerializableMixin

A ranked, license-checked, (optionally) verified sound for one SoundEvent.

Retrieval and generation return the SAME shape; only origin differs. Nested sound / event / verdict dataclasses are decoded generically by _decode() — no per-field code needed.

audio_bytes = None#

The clip’s bytes when foley holds them nowhere it can serve them from — a generate(store=False) preview (the archive bytes the library would have stored). A plain class attribute, NOT a dataclass field, so it is never serialized: to_dict/to_json stay byte-free (cf. IngestReport.exception). copy/deepcopy/pickle keep it; dataclasses.replace and a from_dict round trip drop it.

raw = None#

the item JSON a retrieve source parsed it from (Freesound), or what a generator returned besides the audio (see foley.sources.base.GeneratedClip.raw), else None. Like audio_bytes, a plain class attribute, NOT a dataclass field: it is never serialized, so it never reaches the meta store however large it is.

Type:

The provider’s own payload for this candidate (#61)

class foley.base.CandidateOrigin(*values)[source]#

Bases: str, Enum

Whether a candidate was retrieved from the index or freshly generated.

foley.base.EDIT_AFFORDANCES: dict[str, Affordance] = {'audio': Affordance(name='audio', type=<class 'object'>, description='The source clip to edit (a URL, a local path or bytes; keyed by content)', default=None, stage='generate', carries_meaning=True, choices=None, renamed_from=None, bounds=None), 'extend_after_s': Affordance(name='extend_after_s', type=<class 'float'>, description='Seconds of new sound after the source', default=None, stage='generate', carries_meaning=True, choices=None, renamed_from=None, bounds=(0.0, None)), 'extend_before_s': Affordance(name='extend_before_s', type=<class 'float'>, description='Seconds of new sound before the source', default=None, stage='generate', carries_meaning=True, choices=None, renamed_from=None, bounds=(0.0, None)), 'inpaint_end_s': Affordance(name='inpaint_end_s', type=<class 'float'>, description='End of the window to regenerate (s into the source)', default=None, stage='generate', carries_meaning=True, choices=None, renamed_from=None, bounds=(0.0, None)), 'inpaint_start_s': Affordance(name='inpaint_start_s', type=<class 'float'>, description='Start of the window to regenerate (s into the source)', default=None, stage='generate', carries_meaning=True, choices=None, renamed_from=None, bounds=(0.0, None)), 'strength': Affordance(name='strength', type=<class 'float'>, description="0..1 how far from the source (1.0 is pure generation); None => the backend's", default=None, stage='generate', carries_meaning=True, choices=None, renamed_from=None, bounds=(0.0, 1.0))}#

an edit is a generation whose input includes a source clip. Only a source whose config declares modes=['edit'] takes them (see foley.edit()); a text-to-audio or video-to-audio source refuses audio=.

Type:

Edit-stage parameters (#162)

foley.base.EDIT_OPS: dict[str, EditOp] = {'audio_to_audio': EditOp(name='audio_to_audio', description='Regenerate the whole clip from the source (strength: how far from it)', requires=(), requires_any=(), accepts=('strength',), ordered=(), within_clip=(), adds=()), 'extend': EditOp(name='extend', description='Add new sound before and/or after the source', requires=(), requires_any=('extend_before_s', 'extend_after_s'), accepts=(), ordered=(), within_clip=(), adds=('extend_before_s', 'extend_after_s')), 'inpaint': EditOp(name='inpaint', description='Regenerate one window of the source, keeping the rest', requires=('inpaint_start_s', 'inpaint_end_s'), requires_any=(), accepts=(), ordered=(('inpaint_start_s', 'inpaint_end_s'),), within_clip=('inpaint_start_s', 'inpaint_end_s'), adds=())}#

each is offered by two or more providers).

Type:

SSOT

Type:

the edit operations (report 13 §3

foley.base.EDIT_TRANSFORMATION = 'edit'#

The kind of the transformations entry an edit appends to its clip’s licence (#162): what it derives from (see foley.sources.edit.EditLineage).

class foley.base.EditOp(name, description, requires=(), requires_any=(), accepts=(), ordered=(), within_clip=(), adds=())[source]#

Bases: object

One edit operation and the EDIT_AFFORDANCES it takes (a row of EDIT_OPS).

name#

The op name (foley.edit(source, op); a source config’s edit_op).

Type:

str

description#

What it does.

Type:

str

requires#

Parameters that must all be given.

Type:

tuple

requires_any#

Parameters of which at least one must be given and above 0.

Type:

tuple

accepts#

Optional parameters.

Type:

tuple

ordered#

(lo, hi) parameter pairs that must satisfy lo < hi.

Type:

tuple

within_clip#

Parameters (times into the source) that may not pass its end.

Type:

tuple

adds#

Parameters whose seconds the output adds to the source’s length.

Type:

tuple

output_seconds(clip_s, params)[source]#

How long the op’s output is for a clip_s source (None: unknown), when no duration_s sets it: the source’s length plus what adds adds.

>>> EDIT_OPS["extend"].output_seconds(4.0, {"extend_after_s": 2.0})
6.0
>>> EDIT_OPS["inpaint"].output_seconds(4.0, {"inpaint_start_s": 1.0})
4.0
Return type:

Optional[float]

property params: tuple#

Every edit parameter this op takes (the source clip aside).

foley.base.GENERATION_AFFORDANCES: dict[str, Affordance] = {'duration_s': Affordance(name='duration_s', type=<class 'float'>, description='Seconds; None => backend auto', default=None, stage='generate', carries_meaning=False, choices=None, renamed_from='duration', bounds=None), 'expand_prompt': Affordance(name='expand_prompt', type=<class 'bool'>, description='Let the backend rewrite the prompt (the prompt it used is recorded)', default=None, stage='generate', carries_meaning=False, choices=None, renamed_from=None, bounds=None), 'keep_source_audio': Affordance(name='keep_source_audio', type=<class 'bool'>, description="Keep the video's own speech and build the sound around it", default=False, stage='generate', carries_meaning=False, choices=None, renamed_from=None, bounds=None), 'loop': Affordance(name='loop', type=<class 'bool'>, description='Seamless-loopable clip', default=False, stage='generate', carries_meaning=False, choices=None, renamed_from=None, bounds=None), 'model': Affordance(name='model', type=<class 'str'>, description="Pin a model / version (stored as generator_version); None => the backend's", default=None, stage='generate', carries_meaning=True, choices=None, renamed_from=None, bounds=None), 'negative_prompt': Affordance(name='negative_prompt', type=<class 'str'>, description='Content to exclude', default=None, stage='generate', carries_meaning=True, choices=None, renamed_from=None, bounds=None), 'output_format': Affordance(name='output_format', type=<class 'str'>, description='wav|opus|mp3', default='wav', stage='generate', carries_meaning=False, choices=None, renamed_from=None, bounds=None), 'preset': Affordance(name='preset', type=<class 'str'>, description='Category preset (procedural sources)', default=None, stage='generate', carries_meaning=False, choices=None, renamed_from=None, bounds=None), 'prompt': Affordance(name='prompt', type=<class 'str'>, description='Sound description', default=None, stage='generate', carries_meaning=False, choices=None, renamed_from=None, bounds=None), 'prompt_influence': Affordance(name='prompt_influence', type=<class 'float'>, description="0..1 unified adherence; None => the backend's native default", default=None, stage='generate', carries_meaning=False, choices=None, renamed_from=None, bounds=None), 'sample_rate': Affordance(name='sample_rate', type=<class 'int'>, description='Requested rate (Hz); the actual rate is measured and recorded', default=None, stage='generate', carries_meaning=False, choices=None, renamed_from=None, bounds=None), 'seed': Affordance(name='seed', type=<class 'int'>, description='Reproducibility (capture in provenance)', default=None, stage='generate', carries_meaning=True, choices=None, renamed_from=None, bounds=None), 'steps': Affordance(name='steps', type=<class 'int'>, description='Diffusion/flow steps', default=None, stage='generate', carries_meaning=False, choices=None, renamed_from=None, bounds=None), 'video': Affordance(name='video', type=<class 'object'>, description='The picture to sound (a URL, a RemoteVideo, a local path or bytes; keyed by content)', default=None, stage='generate', carries_meaning=True, choices=None, renamed_from=None, bounds=None)}#

Unified generation-stage parameters (generate backends map onto these).

foley.base.ISO_COUNTRY_CODES: frozenset = frozenset({'AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AO', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AW', 'AX', 'AZ', 'BA', 'BB', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BL', 'BM', 'BN', 'BO', 'BQ', 'BR', 'BS', 'BT', 'BV', 'BW', 'BY', 'BZ', 'CA', 'CC', 'CD', 'CF', 'CG', 'CH', 'CI', 'CK', 'CL', 'CM', 'CN', 'CO', 'CR', 'CU', 'CV', 'CW', 'CX', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM', 'DO', 'DZ', 'EC', 'EE', 'EG', 'EH', 'ER', 'ES', 'ET', 'FI', 'FJ', 'FK', 'FM', 'FO', 'FR', 'GA', 'GB', 'GD', 'GE', 'GF', 'GG', 'GH', 'GI', 'GL', 'GM', 'GN', 'GP', 'GQ', 'GR', 'GS', 'GT', 'GU', 'GW', 'GY', 'HK', 'HM', 'HN', 'HR', 'HT', 'HU', 'ID', 'IE', 'IL', 'IM', 'IN', 'IO', 'IQ', 'IR', 'IS', 'IT', 'JE', 'JM', 'JO', 'JP', 'KE', 'KG', 'KH', 'KI', 'KM', 'KN', 'KP', 'KR', 'KW', 'KY', 'KZ', 'LA', 'LB', 'LC', 'LI', 'LK', 'LR', 'LS', 'LT', 'LU', 'LV', 'LY', 'MA', 'MC', 'MD', 'ME', 'MF', 'MG', 'MH', 'MK', 'ML', 'MM', 'MN', 'MO', 'MP', 'MQ', 'MR', 'MS', 'MT', 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'NC', 'NE', 'NF', 'NG', 'NI', 'NL', 'NO', 'NP', 'NR', 'NU', 'NZ', 'OM', 'PA', 'PE', 'PF', 'PG', 'PH', 'PK', 'PL', 'PM', 'PN', 'PR', 'PS', 'PT', 'PW', 'PY', 'QA', 'RE', 'RO', 'RS', 'RU', 'RW', 'SA', 'SB', 'SC', 'SD', 'SE', 'SG', 'SH', 'SI', 'SJ', 'SK', 'SL', 'SM', 'SN', 'SO', 'SR', 'SS', 'ST', 'SV', 'SX', 'SY', 'SZ', 'TC', 'TD', 'TF', 'TG', 'TH', 'TJ', 'TK', 'TL', 'TM', 'TN', 'TO', 'TR', 'TT', 'TV', 'TW', 'TZ', 'UA', 'UG', 'UM', 'US', 'UY', 'UZ', 'VA', 'VC', 'VE', 'VG', 'VI', 'VN', 'VU', 'WF', 'WS', 'YE', 'YT', 'ZA', 'ZM', 'ZW'})#

The ISO 3166-1 alpha-2 country codes (the 249 officially assigned).

class foley.base.IntendedUse(commercial=True, publish=True, redistribute_standalone=False, will_train=False, can_attribute=True, revenue_usd=0, allow_voice_or_trademark=False, territory=None)[source]#

Bases: SerializableMixin

What the caller intends to do with a sound; consumed by keep().

territory: Optional[str] = None#

Where the sound is used (ISO 3166-1 alpha-2, e.g. "US"; "UK" reads as "GB"), or "WORLD" (WORLDWIDE: online publishing reaches every country). Only a licence that excludes territories asks (foley.licensing.LICENSE_EXCLUDED_TERRITORIES); for one, None fails closed, and so does "WORLD".

class foley.base.Layer(*values)[source]#

Bases: str, Enum

Mix layer (shared by SoundEvent now and TimelineItem later).

class foley.base.LicenseRecord(source, source_id=None, source_url=None, acquisition_method=AcquisitionMethod.user, retrieved_at=None, adapter_version=None, content_sha256=None, license_id='unknown', license_name=None, license_version=None, license_url=None, rights_holder=None, creator_name=None, creator_url=None, commercial_ok=False, embed_in_derivative_ok=True, redistribute_standalone_ok=False, cache_bytes_ok=False, modification_ok=False, ai_training_ok=False, ai_training_scope=None, gen_ai_preference=None, revenue_cap_usd=None, license_basis=None, license_basis_confidence=None, vendor_trains_on_output=None, terms_notes=list(), requires_attribution=False, attribution_text=None, notice_text_required=None, transformations=list(), derived_from_license_ids=list(), is_ai_generated=False, generator_model=None, generator_version=None, generation_prompt=None, generation_prompt_used=None, generation_seed=None, generation_params=dict(), watermark=None, vendor_watermark=None, c2pa_manifest_ref=None, contains_recognizable_voice=False, potential_trademark=False, disclosure_recommended=False, rights_verified=False, verified_at=None, schema_version=1)[source]#

Bases: SerializableMixin

Per-sound rights + provenance. SSOT for BOTH keep() and storage mode.

The derived permission flags default fail-closed here (the bare-record baseline) — with one deliberate exception: embed_in_derivative_ok defaults True (the normal case for a licensed sound). That is not a live bypass: keep() checks rights_verified first, so an unverified record is rejected regardless. Populate the flags from the license_id via foley.licensing.apply_license_flags (source overrides win). Never hand-set the derived flags — always route through the policy layer.

property generation_reproducible: Optional[bool]#

True iff a seed was recorded.

None for a sound that was not generated (by a model, or procedurally). A backend with no seed (ElevenLabs, Sonilo) records none, so its clips read False rather than carrying a seed that would reproduce nothing (#75). A seed is necessary, not sufficient: a hosted endpoint can change its model behind the same id. A clip whose generation_params say bit_exact is False (pyfxr’s noise waveform, #76) is False: the same seed and params render different bytes. A prompt the backend rewrote (expand_prompt) is False too: replaying it runs the rewrite again.

Type:

Whether this generated clip can be made again

foley.base.MASTER_PROFILES: dict[str, MasterProfile] = {'broadcast_atsc': MasterProfile(target_lufs=-24.0, true_peak_db=-2.0, lra=7.0, max_limiting_db=6.0), 'broadcast_ebu': MasterProfile(target_lufs=-23.0, true_peak_db=-1.0, lra=7.0, max_limiting_db=6.0), 'podcast': MasterProfile(target_lufs=-16.0, true_peak_db=-1.0, lra=11.0, max_limiting_db=6.0), 'streaming': MasterProfile(target_lufs=-14.0, true_peak_db=-1.0, lra=11.0, max_limiting_db=6.0)}#

The named delivery targets (report 06 §5.2). resolve_master() maps a profile name to one of these; these values are the SSOT so no LUFS literal hides in code.

class foley.base.MasterProfile(target_lufs=-16.0, true_peak_db=-1.0, lra=11.0, max_limiting_db=6.0)[source]#

Bases: SerializableMixin

Loudness master target — the delivery spec as data, not code (report 06 §5.2).

max_limiting_db: float = 6.0#

How far (dB) the master’s loudness stage lets the sample peak run over true_peak_db for the default lookahead limiter to take back (it may take off a little more, the inter-sample overshoot of those peaks). 0 restores a static, whole-program master. Transient foley (a door slam under narration) needs a few dB to reach the target at all (foley#91).

class foley.base.MatchKind(*values)[source]#

Bases: str, Enum

HOW a Placement’s anchor was resolved against the narration (#263).

exact — the cue word was spoken as written; stem — a word sharing its stem (an inflection, or the spoken part of a compound cue); fuzzy — only a lexically similar word (it may be a false match: thunder lands on “under”); fallback — nothing matched (or there were no word timings), so the stored onset or the whole narration was used; absolute — the placement names no word to match (an absolute offset, or a bed with no cue spanning the narration).

class foley.base.Placement(anchor=Anchor.absolute, ref=None, onset=0.0, pre_roll=0.0, duration=None, loop=False, match_kind=None)[source]#

Bases: SerializableMixin

WHERE/WHEN a clip sits — a symbolic anchor plus its resolved time (report 06 §6.3).

Filled by WEAVE’s aligner+anchor pass. onset is the resolved start in seconds (distinct from the sparse TimelineItem.onset symbolic string); pre_roll shifts the clip earlier so its salient transient — not its file start — lands on the anchor (report 06 §2.4). match_kind records how the anchor resolved (MatchKind), so a fuzzy or fallback placement is visible.

class foley.base.Processing(gain_db=0.0, pan=0.0, distance=0.0, reverb_send=0.0, fade_in=0.008, fade_out=0.012, duck_bed=False)[source]#

Bases: SerializableMixin

HOW a clip sounds — all optional with identity defaults (report 06 §3, §6.3).

Every field is a no-op at its default, so a sparse item (no processing) renders untouched; the mixer departs from dry/centered/full-level only when a field is set.

foley.base.QUERY_AFFORDANCES: dict[str, Affordance] = {'audioset_label': Affordance(name='audioset_label', type=<class 'str'>, description='AudioSet ontology facet (rolls up children)', default=None, stage='query', carries_meaning=False, choices=None, renamed_from=None, bounds=None), 'commercial_ok': Affordance(name='commercial_ok', type=<class 'bool'>, description='License filter shorthand', default=None, stage='query', carries_meaning=False, choices=None, renamed_from=None, bounds=None), 'duration_range': Affordance(name='duration_range', type=<class 'tuple'>, description='(min_s, max_s)', default=None, stage='query', carries_meaning=False, choices=None, renamed_from=None, bounds=None), 'filters': Affordance(name='filters', type=<class 'dict'>, description='Metadata predicates (SQL-style)', default=None, stage='query', carries_meaning=False, choices=None, renamed_from=None, bounds=None), 'include_explicit': Affordance(name='include_explicit', type=<class 'bool'>, description='Also return explicit / sensitive results', default=False, stage='query', carries_meaning=False, choices=None, renamed_from=None, bounds=None), 'include_pronunciations': Affordance(name='include_pronunciations', type=<class 'bool'>, description='Also return recordings of a person saying a word (#295, #319)', default=False, stage='query', carries_meaning=False, choices=None, renamed_from=None, bounds=None), 'k': Affordance(name='k', type=<class 'int'>, description='Number of results', default=10, stage='query', carries_meaning=False, choices=None, renamed_from=None, bounds=None), 'kind': Affordance(name='kind', type=<class 'str'>, description='Media kind: sfx | music', default='sfx', stage='query', carries_meaning=True, choices=('sfx', 'music'), renamed_from=None, bounds=None), 'license': Affordance(name='license', type=<class 'str'>, description='Explicit license id constraint', default=None, stage='query', carries_meaning=False, choices=None, renamed_from=None, bounds=None), 'min_snr': Affordance(name='min_snr', type=<class 'float'>, description='QC filter: min SNR dB', default=None, stage='query', carries_meaning=False, choices=None, renamed_from=None, bounds=None), 'page': Affordance(name='page', type=<class 'int'>, description='Results page (1-based; k per page)', default=1, stage='query', carries_meaning=True, choices=None, renamed_from=None, bounds=None), 'query': Affordance(name='query', type=<class 'str'>, description='Natural-language query', default=None, stage='query', carries_meaning=False, choices=None, renamed_from='text', bounds=None), 'rerank': Affordance(name='rerank', type=<class 'bool'>, description='Apply second-stage rerank', default=False, stage='query', carries_meaning=False, choices=None, renamed_from=None, bounds=None), 'semantic_text': Affordance(name='semantic_text', type=<class 'str'>, description='Query for CLAP semantic space', default=None, stage='query', carries_meaning=False, choices=None, renamed_from=None, bounds=None), 'similar_to': Affordance(name='similar_to', type=<class 'str'>, description='Source sound id: more like this one (a source that has it)', default=None, stage='query', carries_meaning=False, choices=None, renamed_from=None, bounds=None), 'sort': Affordance(name='sort', type=<class 'str'>, description='Result order', default='relevance', stage='query', carries_meaning=False, choices=('relevance', 'newest', 'popular', 'duration'), renamed_from=None, bounds=None), 'sources': Affordance(name='sources', type=<class 'list'>, description='Restrict an aggregator to these of its providers', default=None, stage='query', carries_meaning=True, choices=None, renamed_from=None, bounds=None), 'ucs_category': Affordance(name='ucs_category', type=<class 'str'>, description='UCS CatID facet', default=None, stage='query', carries_meaning=False, choices=None, renamed_from=None, bounds=None)}#

Unified query-stage parameters (search / find / filter surface).

foley.base.SUSPECT_MATCH_KINDS: dict[MatchKind, str] = {MatchKind.fallback: 'no spoken word (placed at a fallback onset)', MatchKind.fuzzy: 'only a similar word (it may be the wrong one)'}#

The match kinds whose sound may not sit on its cue word, and why — the SSOT the weave notes and the taste eval both flag (#263).

class foley.base.Salience(*values)[source]#

Bases: str, Enum

How prominent a sound event is within a passage.

class foley.base.SerializableMixin[source]#

Bases: object

Adds to_dict/to_json/from_dict/from_json to a dataclass.

Stdlib-only, DRY, no-magic (de)serialization. Every SSOT dataclass below inherits this instead of hand-rolling per-class encoders/decoders.

classmethod from_dict(d)[source]#

Reconstruct an instance from a plain dict.

Enum fields and nested dataclasses are coerced via _decode(). Unknown keys are ignored (forward-compatible); missing keys fall back to field defaults.

Parameters:

d (dict) – A plain dict (typically from to_dict() or json.loads).

Return type:

SerializableMixin

classmethod from_json(s)[source]#

Reconstruct an instance from a JSON string.

Parameters:

s (str) – A JSON string (typically from to_json()).

Return type:

SerializableMixin

to_dict()[source]#

Return the recursive plain-dict form.

Enum members are preserved (and remain JSON-safe because every enum subclasses str); nested dataclasses are recursed via dataclasses.asdict.

Return type:

dict

to_json(*, indent=None)[source]#

Return a JSON string (str-enums serialize to their .value).

Parameters:

indent (Optional[int]) – Optional pretty-print indent passed to json.dumps.

Return type:

str

class foley.base.SoundDesignTimeline(items=list(), run_manifest_ref=None, transcript_ref=None, schema_version=1, narration_ref=None, word_timeline=list(), master=MasterProfile(), sfx_gain_db=0.0)[source]#

Bases: SerializableMixin

The editable, re-renderable sound-design plan — the SELECT→WEAVE bridge and render SSOT.

SELECT (#7) emits the SPARSE form (just items + the run/transcript joins) via foley.agent.plan(). WEAVE (#8) grows it additively: narration_ref binds the voice audio, word_timeline caches the forced alignment (the reproducible seed), master carries the loudness target, and each item gains its resolved Placement/Processing. render(timeline, library) is then a PURE function of this data + the library, so editing any field and re-rendering reproduces exactly that change. run_manifest_ref == foley.obs.RunManifest.run_id (the reserved #8 plan_ref join).

sfx_gain_db: float = 0.0#

The sound-design bus’s level against the narration, in dB, before mastering (#292): part of the seed, so a re-render from this timeline keeps it. Left out of to_dict() at its 0 dB default, so a timeline that never set it serialises exactly as before.

to_dict()[source]#

The plain-dict form; sfx_gain_db only when it is not 0 dB.

Return type:

dict

class foley.base.SoundEvent(query, layer=Layer.sfx_fg, diegetic=True, salience=Salience.medium, onset=None, loop=False, ucs_catid=None, audioset=list(), era_place=None)[source]#

Bases: SerializableMixin

One salient, physically-audible event decomposed from a passage.

class foley.base.SoundRecord(id, content_sha256=None, hash_algo='sha256', uri=None, storage_mode=StorageMode.by_reference, archive_format=None, source_sample_rate=None, source_bit_depth=None, license=<factory>, caption=None, tags=list(), ucs_category=None, ucs_subcategory=None, audioset_labels=list(), duration_s=None, sample_rate=None, channels=None, loudness_lufs=None, format=None, qc=None, embedding_model=None, embedding_dim=None, embedding_ref=None, named_cue=None, schema_version=1)[source]#

Bases: SerializableMixin

Canonical SSOT per sound.

Audio bytes + CLAP vector live in SEPARATE stores keyed by the same id; this record holds a content-hash uri, never raw bytes.

class foley.base.StorageMode(*values)[source]#

Bases: str, Enum

How a sound’s bytes are held (DERIVED from license.cache_bytes_ok).

foley.base.TERRITORY_ALIASES = {'EL': 'GR', 'UK': 'GB'}#

the UK’s common one and the EU’s code for Greece.

Type:

Spellings that name a country by another code

class foley.base.TimelineItem(clip_ref, onset=None, gain=0.0, layer=Layer.sfx_fg, loop=False, id=None, placement=None, processing=None, event=None, enabled=True)[source]#

Bases: SerializableMixin

One placed sound on the sound-design timeline — sparse seed + resolved render fields.

SELECT (#7) sets only the sparse flat fields (clip_ref·onset·gain·layer·loop); WEAVE (#8) additively fills id / placement / processing (and may carry the originating event for provenance). enabled is a non-destructive mute. The sparse flat fields are never removed — they stay SELECT’s SSOT input; the render reads the resolved placement/processing (falling back to the flat fields when those are absent).

class foley.base.Verdict(match, confidence, reason='', level=VerifyLevel.clap)[source]#

Bases: SerializableMixin

The result of one verification rung for a candidate.

class foley.base.VerifyLevel(*values)[source]#

Bases: str, Enum

Which rung of the verification ladder produced a Verdict.

foley.base.WORLDWIDE = 'WORLD'#

The territory of a sound used everywhere (online publishing reaches every country): a licence that excludes any territory refuses it (#175).

foley.base.check_edit_args(op, affordances, *, clip_s=None, limits=None, floors=None, bounds=None)[source]#

Raise ValueError unless affordances are a valid call of the edit op.

Checked before anything is paid for: the op is known, its required parameters are given, it is given no other op’s parameters, each number is within its Affordance.bounds and the backend’s own range (limits: name -> max; floors: name -> min), each ordered pair is increasing, and a time into the source (EditOp.within_clip) does not pass its end (clip_s, when known).

bounds are the backend’s limits on what the parameters make (a config’s edit_limits, each a (lo, hi) pair, either None): clip_s the source clip’s length, span_s each ordered window’s length, output_s the output’s length (EditOp.output_seconds()). A length that cannot be read is not checked.

>>> check_edit_args("inpaint", {"inpaint_start_s": 1.0, "inpaint_end_s": 2.5})
>>> check_edit_args("inpaint", {"inpaint_start_s": 1.0})
Traceback (most recent call last):
...
ValueError: the inpaint edit needs inpaint_end_s=
>>> check_edit_args("extend", {"extend_before_s": 0})
Traceback (most recent call last):
...
ValueError: the extend edit needs one of extend_before_s=, extend_after_s= above 0
>>> check_edit_args("inpaint", {"inpaint_start_s": 1, "inpaint_end_s": 9}, clip_s=4)
Traceback (most recent call last):
...
ValueError: inpaint_end_s=9 is past the end of the 4 s source clip
>>> check_edit_args("extend", {"extend_after_s": 5}, clip_s=58,
...                 bounds={"output_s": (None, 60)})
Traceback (most recent call last):
...
ValueError: the extend edit's output is 63 s; this backend takes 60 s at most
Return type:

None

foley.base.checked_layers(layers)[source]#

layers (names or Layer members) as a set of members, checked up front so a typo raises before any paid call (reeleehq/foley#316). A single name is one layer, not its letters; None stays None (every layer).

>>> checked_layers(["ambience", Layer.sfx_fg]) == {Layer.ambience, Layer.sfx_fg}
True
>>> checked_layers("ambience") == {Layer.ambience}
True
>>> checked_layers({"ambiance"})
Traceback (most recent call last):
...
ValueError: 'ambiance' is not a mix layer; the layers are voice, sfx_fg, ambience, stinger, music
Return type:

Optional[frozenset[Layer]]

foley.base.normalize_territory(territory)[source]#

territory as an ISO 3166-1 alpha-2 code (or WORLDWIDE), None when unstated.

>>> normalize_territory(" uk "), normalize_territory("EL"), normalize_territory("")
('GB', 'GR', None)
>>> normalize_territory("world")
'WORLD'
Raises:

ValueError – If it is not a country code (a name, an alpha-3 code, a region): a licence gate cannot judge what it cannot read.

Return type:

Optional[str]

foley.base.reject_renamed(names, vocabulary=None)[source]#

Raise TypeError if any of names is an affordance’s old spelling.

vocabulary defaults to GENERATION_AFFORDANCES; the old names come from each Affordance’s renamed_from.

>>> reject_renamed(["prompt", "duration_s"])
>>> reject_renamed(["duration"])
Traceback (most recent call last):
    ...
TypeError: duration= was renamed duration_s=
Return type:

None

foley.base.resolve_master(master)[source]#

Resolve a master spec (profile name, explicit profile, or None) to a MasterProfile.

Parameters:

master (Union[str, MasterProfile, None]) – A MASTER_PROFILES key (e.g. 'podcast'), an explicit MasterProfile, or None (-> the podcast default).

Return type:

MasterProfile

Returns:

The resolved MasterProfile.

Raises:

ValueError – If master is an unknown profile name.