foley.index.ingest#
The ingestion pipeline — turn any audio file into a searchable SoundRecord.
probe -> QC -> supervised tag -> zero-shot tag -> caption -> resolve taxonomy
-> embed -> assemble -> store (report 03 Stages 0-5, report 08 §3 QC gate,
report 09 §5 decode-once). It is almost entirely composition over primitives
that already exist:
decode / archive:
foley.audio.load()/encode()(decode once, then fan the one array out to QC + taggers + embedder),QC gate:
foley.qc.run_qc()(afailclip is quarantined, not added),embed: the library’s
ClapEmbedder(the vector is reused for zero-shot tagging — no second CLAP pass),taxonomy:
foley.index.taxonomy.resolve_catid()(tags+caption -> UCS),store + index:
foley.index.library.SoundLibrary.add()(the by-value/by-reference license gate + vector upsert + BM25 index).
Enrichment stages degrade gracefully: a missing foley[tag] (PANNs) or
captioner is skipped with a note, never a crash — only the CLAP embedding is
required (retrieval-first). Everything heavy is lazy-imported; importing this
module costs only the stdlib.
Module Attributes
Audio file extensions the folder walker ingests. |
|
the duplicate is the clip made again, so the fresh record's lineage and credits replace the stored ones. |
|
The note on a clip stored under a licence that forbids AI training, by the caller's explicit consent ( |
|
The licence a stored, embedded clip falls back to when its new licence needs AI consent that was not given (fail-closed: unverified, so keep() refuses it). |
|
Named selections for |
|
re-derive each record's id from the licence URL / label its source served (kept in |
Functions
|
Return the reproducible content-hash id foley assigns to |
|
Whether |
|
Whether |
|
Ingest every audio file under |
|
Ingest one clip into |
Whether |
|
|
Whether |
|
Yield the audio files under |
|
The rights record for a local ingest: fail-closed unless rights are asserted (#55). |
|
Re-stamp the licence of stored sounds; a dry run unless |
Classes
|
The rolled-up outcome of a folder ingest (JSON-serializable). |
|
The outcome of ingesting one clip. |
Exceptions
|
Raised by an |
A per-file plan and the caller set the same |
- foley.index.ingest.AUDIO_EXTS: tuple[str, ...] = ('.wav', '.flac', '.aiff', '.aif', '.ogg', '.mp3', '.opus', '.m4a')#
Audio file extensions the folder walker ingests.
- foley.index.ingest.CONSENT_NOTE = 'AI-training restriction acknowledged by operator (consent recorded)'#
The note on a clip stored under a licence that forbids AI training, by the caller’s explicit consent (
allow_ai_training_forbidden/accept_ai_restricted).
- foley.index.ingest.FROM_LICENSE_URL = 'from-url'#
re-derive each record’s id from the licence URL / label its source served (kept in
license_url).- Type:
restamp_rights(license=FROM_LICENSE_URL)
- class foley.index.ingest.IngestReport(root, results=list(), notes=list())[source]#
Bases:
SerializableMixinThe rolled-up outcome of a folder ingest (JSON-serializable).
- property errored: list[IngestResult]#
Results that raised during ingest.
- exception = None#
The exception behind the last
errorresult, kept so a raising façade can chain it (raise ... from); a plain attribute, never serialized.
- property ingested: list[IngestResult]#
Results that were added to the library (
passorwarn).
- property quarantined: list[IngestResult]#
Results rejected by the QC gate.
- record(result)[source]#
Append one
IngestResult.- Return type:
- property rights_blocked: list[IngestResult]#
Results refused by the fail-closed AI-training/license rights gate.
- skip(path, skip)[source]#
Record a file a per-file plan declined (
IngestSkip), with its reason.- Return type:
- property skipped: list[IngestResult]#
Results skipped as content-addressed duplicates.
- class foley.index.ingest.IngestResult(id, status, record=None, qc=None, notes=list(), error=None, cost_estimate_usd=None, cost_actual_usd=None, cache_key=None)[source]#
Bases:
SerializableMixinThe outcome of ingesting one clip.
status:'pass'/'warn'(ingested),'quarantined'(QC-rejected, not added),'skipped_dup'(content already in the library),'rights_blocked'(license forbids AI training / embedding, refused before embed — seeingest_one()),'skipped_license'(dropped by a bootstrap commercial-use / fail-closed license filter, or a file no licence sidecar covers — seeIngestSkip), or'error'.recordis present only when the clip was ingested.cache_keyis set byfoley.generate()to the key its paid bytes were kept under in the generations cache (foley.generations.get(cache_key)), whatever the outcome — a quarantined generation is retrievable, since it was billed either way (#107). It is the content key of the provider’s bytes as received (their sha256) — notid(the decoded-PCM hash) norrecord.content_sha256(the stored FLAC archive’s), and not the request digest the notes name (which also resolves throughget).- audio_bytes = None#
what the library would have served. A plain attribute, never serialized (like
IngestReport.exception), soto_dict/to_jsonstay byte-free.- Type:
The archive bytes of a clip assembled but not stored (
store=False)
- raw = None#
What the provider returned besides the audio of a generation (#61; see
foley.sources.base.GeneratedClip.raw). A plain attribute, never serialized.
- exception foley.index.ingest.IngestSkip(reason, *, status='skipped_license')[source]#
Bases:
ExceptionRaised by an
ingest_folder()file_kwargsplan to decline one file.Not an error: the file is recorded with
status(default'skipped_license') andreasonas its note, whateveron_errorsays, and the folder carries on.
- foley.index.ingest.LEGACY_SELECTORS = {'has-license-url': <function has_license_url>, 'legacy-elevenlabs': <function is_legacy_elevenlabs>, 'legacy-user-owned': <function is_legacy_default_user_owned>}#
Named selections for
restamp_rights()(foley restamp-rights --select NAME).
- exception foley.index.ingest.PlanConflict[source]#
Bases:
TypeErrorA per-file plan and the caller set the same
ingest_one()keyword.
- foley.index.ingest.RESTAMP_REMADE = 'remade'#
the duplicate is the clip made again, so the fresh record’s lineage and credits replace the stored ones.
- Type:
ingest_one(restamp_duplicate=RESTAMP_REMADE)
- foley.index.ingest.UNCONSENTED_LICENSE_ID = 'unknown'#
The licence a stored, embedded clip falls back to when its new licence needs AI consent that was not given (fail-closed: unverified, so keep() refuses it).
- foley.index.ingest.content_id(src)[source]#
Return the reproducible content-hash id foley assigns to
src.Decodes
src(path / bytes / file-like) to canonical PCM and hashes it — the SAME valueingest_one()mints as the record id whensound_idisNone. Exposed so a caller can learn a clip’s stored id before ingesting it (e.g. the generate façade keys a content-credential sidecar by the id and setslicense.c2pa_manifest_refin the same pass — seefoley.sources.generate.generate()). Cheap-ish: it fully decodessrc.- Return type:
- foley.index.ingest.embedding_permitted(lic, lib, commercial=None)[source]#
Whether
lib’s embedder may use a sound underlic(the ingest rights gate).The check
ingest_one()makes before it embeds anything; a caller that will ingest later (a paid render first) asks it up front. Without consent (allow_ai_training_forbidden) aFalsehere is'rights_blocked'.- Return type:
- foley.index.ingest.has_license_url(lic)[source]#
Whether
lickept the licence string its source served (re-derivable).- Return type:
- foley.index.ingest.ingest_folder(path, *, library=None, recursive=True, exts=('.wav', '.flac', '.aiff', '.aif', '.ogg', '.mp3', '.opus', '.m4a'), on_error='collect', file_kwargs=None, **ingest_one_kw)[source]#
Ingest every audio file under
pathand return anIngestReport.- Parameters:
path – A folder (walked) or a single audio file.
library – Target library (default: the process-wide default).
recursive (
bool) – Recurse into sub-folders.on_error (
str) –'collect'records per-file errors and continues;'raise're-raises the first error. Either way anEgressBlocked(offline, the embedder’s weights not cached) raises at once: every file would fail the same way.file_kwargs (
Optional[Callable[[Path],dict]]) – Optional per-file plan,path -> dictofingest_one()keywords for that file (its licence, caption, tags…), besideingest_one_kw; a keyword in both raisesPlanConflict(the run stops: every file would conflict). It may raiseIngestSkipto decline the file (recorded, never raised); any other exception is a per-file error.foley.index.licensed_library.ingest_licensed_folder()uses it.**ingest_one_kw – Forwarded to
ingest_one()(license, taggers, QC flags, …).
- Return type:
- Returns:
An
IngestReport(with.summary()counts and per-file results).
- foley.index.ingest.ingest_one(src, *, library=None, sound_id=None, source_uri=None, license=None, tagger=None, zeroshot_tagger=None, captioner=None, do_qc=True, min_status=QCStatus.warn, do_supervised=True, do_zeroshot=True, do_caption=True, thresholds=QCThresholds(clip_full_scale=0.999, clip_min_run=3, clip_reject_ratio=0.0001, clip_reject_run=10, true_peak_max_dbtp=-1.0, true_peak_oversample=None, dc_offset_fail=0.01, dc_offset_warn=0.001, silence_rms_dbfs=-60.0, snr_clean_db=20.0, snr_quiet_percentile=10.0, snr_frame_s=0.025, snr_hop_s=0.01, edge_rel_peak_dbfs=-40.0, edge_fade_s=0.01, lufs_gate_floor=-70.0, lufs_outlier_lu=6.0, duration_min_s=0.1, deliver_min_sample_rate=44100), store=True, allow_ai_training_forbidden=False, seed_tags=None, ucs_catid=None, restamp_duplicate=False, commercial=None, catid_min_confidence=0.5)[source]#
Ingest one clip into
libraryand return anIngestResult.Pipeline: probe + decode-once -> content-address dedup -> QC gate -> embed (once) -> supervised + zero-shot tags -> caption -> resolve UCS -> assemble
SoundRecord->SoundLibrary.add().- Parameters:
src (
Union[str,PathLike,bytes,BinaryIO]) – A path,bytes, or file-like audio source.library – Target
SoundLibrary(default: the process-wide default library).sound_id (
Optional[str]) – Optional canonical id override. Defaults toNone→ the content-hash of the decoded PCM (the local-ingest identity, used as the recordidand dedup key). A live source adapter passes a short, case-stable, source-native id (e.g.'freesound:12345') so dedup keys on the stable id rather than on re-fetched (lossy, byte-varying) preview bytes; when it does, the PCM hash is computed only for the (skipped) default and is not persisted. Separately,content_sha256records the hash of the stored FLAC archive bytes (set bystore_sound), which is a different byte source from this PCM hash.source_uri (
Optional[str]) – Optional by-reference fetchable URI override. Defaults toNone→ the resolved local path whensrcis path-like. A live adapter passes the stable source page URL (e.g.'https://freesound.org/s/12345/') thatfoley.stores.store_sound()requires for a by-reference sound.license (
Optional[LicenseRecord]) – Rights record, or alicense_idstring the caller asserts ('user-owned'), orNone(default): rights unknown, so the clip is indexed butfoley.keep()refuses it (#55). Seeresolve_ingest_license().tagger – Supervised
Tagger(default: PANNs viadefault_tagger()).zeroshot_tagger – Zero-shot tagger (default: CLAP via
default_zeroshot_tagger()).captioner – Optional
Captioner(default: none — the caption stage is off unless one is injected).do_qc (
bool) – Run the Tier-0 QC gate.min_status (
QCStatus) – Admission floor — a QC status worse than this is quarantined (defaultwarn: onlyfailclips are rejected).do_caption (
bool) – Toggle each enrichment stage.thresholds (
QCThresholds) – QC thresholds.store (
bool) – IfFalse, assemble the record but do not add it to the library (probe/QC/enrich only — a preview). The result’saudio_bytesthen carries the archive bytes the library would have stored, and an enrichment stage whose optional extra is absent (thefoley[clap]embedder) is skipped with a note rather than failing: a preview is never indexed, so it never needs the vector (#107).seed_tags (
Optional[list]) – Optional caller-supplied tags (e.g. a corpus’s folder-path taxonomy) unioned into the record’stagsalongside the supervised/zero-shot tags — so they feed the BM25 keyword index.ucs_catid (
Optional[str]) – Optional CatID the file declares about itself (its iXMLCATID,foley.embedded_metadata). It setsucs_category(which holds the CatID) when the filename does not parse and the UCS table knows it; otherwise tags/caption decide.restamp_duplicate (
Union[bool,Literal['remade']]) – When the clip is already stored (skipped_dup), re-stamp the stored record fromlicensewithout ever widening it (foley.licensing.restamped_license()withwiden=False; its note lands on the result). The rights gate below holds here too: a new licence that forbids AI use (the clip is already embedded) is applied only withallow_ai_training_forbidden; without it the stored record becomesunknown(unverified, sofoley.keep()refuses it) and the resultrights_blocked, as a fresh ingest would be. DefaultFalse: a duplicate is left as it is.'remade': the clip was made again (RESTAMP_REMADE), solicense’s lineage and credits replace the stored ones too (restamped_license(remade=True)), still never widening.allow_ai_training_forbidden (
bool) – The universal fail-closed rights gate. A sound whose license hasai_training_ok=False(e.g. Sonniss, BBC RemArc) is refused with status'rights_blocked'before it is embedded or stored — CLAP-embedding-and-persisting is itself a form of AI training on the corpus. PassTrueto record explicit operator consent and admit it anyway (seefoley.bootstrap.bootstrap()’saccept_ai_restricted). Protects every ingest path, not just bootstrap.commercial (
Optional[bool]) – Whether the AI use is for a commercial purpose (decides anc_open_source_onlyscope, #69).None(default) meansDEFAULT_INTENDED_USE’s (commercial).catid_min_confidence (
float) – The least resolution confidence stamped as the record’s UCS CatID (defaultRECORD_MIN_CONFIDENCE, an AudioSet-map hit’s). A weaker keyword brush (a category name alone, a synonym many rows share) is left off the record, with a note;0stamps any.
- Return type:
- Returns:
An
IngestResult; itsrecordisNonewhen quarantined, a duplicate, or rights-blocked.
- foley.index.ingest.is_legacy_default_user_owned(lic)[source]#
Whether
licis theuser-ownedstamp foley used to put on any unlicensed ingest.Before #55,
foley.ingest(path)with no licence stamped every fileuser-owned+ verified. An explicit assertion now also recordsverified_at; the old default never did, which is what tells them apart.- Return type:
- foley.index.ingest.is_legacy_elevenlabs(lic)[source]#
Whether
licis an ElevenLabs generation stamped before the plan was explicit (#56).- Return type:
- foley.index.ingest.iter_audio_files(path, *, recursive=True, exts=('.wav', '.flac', '.aiff', '.aif', '.ogg', '.mp3', '.opus', '.m4a'))[source]#
Yield the audio files under
path(orpathitself if it is a file).The shared corpus/folder walk — reused by
ingest_folder()and the bulk-corpus adapters infoley.sourcesso the traversal is not forked.
- foley.index.ingest.resolve_ingest_license(license, *, source_url=None)[source]#
The rights record for a local ingest: fail-closed unless rights are asserted (#55).
None(no licence given) →license_id='unknown',rights_verified=False:foley.keep()refuses it for every use. The bytes are still kept locally(
cache_bytes_ok=True: it is the user’s own disk, no terms of service apply), so the clip is searchable and can be re-stamped later without re-ingesting.a
str→ thatlicense_id, which must be aLICENSE_FLAGSrow, withrights_verified=True(the caller is asserting it) andverified_atset — e.g.'user-owned'for the user’s own recordings.a
LicenseRecord→ used as given.
- Raises:
ValueError – If a
strlicence id has noLICENSE_FLAGSrow.- Return type:
- foley.index.ingest.restamp_rights(library=None, *, license='unknown', ids=None, where=None, select='legacy-user-owned', apply=False)[source]#
Re-stamp the licence of stored sounds; a dry run unless
apply=True.The migration for libraries built before #55 / #56. A re-ingest does not do it (content-addressed dedup skips files already stored), so this rewrites the stored records in place:
foley restamp-rights --apply— every sound an older foley stampeduser-ownedwithout being told becomesunknown(fail closed);foley restamp-rights --license user-owned --apply— the same sounds, but you assert that you own them (now recorded with averified_attimestamp);foley restamp-rights --select legacy-elevenlabs --license elevenlabs-paid-plan --apply— ElevenLabs generations made before the plan was explicit;foley restamp-rights --select has-license-url --license from-url --apply— every record that kept its source’s licence string (Freesound pulls) is re-derived by today’s mapper (CC versions, PDM, NC spellings);corpus clips (Clotho, FSD50K) are repaired by re-running
foley bootstrap, which re-stamps already-stored clips from the corpus metadata.
Re-stamping never widens a derivative (an edit, #162): the new flags stay bounded by every licence the record derives from (
foley.licensing.derived_license_ids()). A record stored beforederived_from_license_idsexisted falls back to its edit entries, which name only the direct source, so an edit of an edit stored then is bounded by its parent’s licence, not its grandparent’s.- Parameters:
library – The
SoundLibrary(default: the default one).license (
str) – Thelicense_idto stamp (aLICENSE_FLAGSrow; default'unknown'), orFROM_LICENSE_URLto re-derive each record from its ownlicense_url.ids (
Optional[list[str]]) – Re-stamp exactly these sound ids (overrideswhere/select).where – A predicate
LicenseRecord -> boolchoosing the records (overridesselect).select (
str) – ALEGACY_SELECTORSname (default'legacy-user-owned').apply (
bool) – Write the change.False(default) only reports what would change.
- Return type:
- Returns:
The ids that were (or, in a dry run, would be) re-stamped.
- Raises:
ValueError – If
licenseorselectis unknown.