foley.dataset#
Bulk training-dataset synthesis over foley’s generators (#321).
foley.generate makes one sound at a time and files it in a retrieval library. A
training set wants the opposite: many clips from a grid of prompts, seeds and durations,
written to a plain directory with the audit trail a dataset needs, under a hard budget,
and re-runnable without paying twice:
import foley.dataset as ds
spec = ds.DatasetSpec(
prompts={"laser": ["laser zap", "laser blast"], "coin": ["coin pickup"]},
seeds=range(5),
backends=("pyfxr",), # offline and free; a paid backend needs budget_usd
budget_usd=0.0,
per_class_seconds={"laser": 600},
)
report = ds.synthesize(spec, "~/datasets/sfx-v1")
out_dir then holds:
audio/<class>/<request_id>.flac one file per kept clip
manifest.jsonl one row per clip: request, QC, cost and the full LicenseRecord
terms/<backend>-<hash>.json the backend's stated terms, as read when the run began
ATTRIBUTION.md credits for the clips whose licences require them
DATASHEET.md, report.json what is in it, per-class seconds and synthetic share
Guarantees:
Fail-closed rights. Every clip is checked with the licence gate against
spec.intended_use(default: training use). A clip whose licence cannot serve it is recorded asrefusedwith the reason and its audio is not written.Hard budget. The run is inside a
foley.agent.policy.Budgetofbudget_usd; the first call the budget refuses ends the run (stopped='budget'), never a warning. A cost that is unknown counts as a refusal unless the budget approves it.Resumable, idempotent. A clip’s
request_idis the hash of everything that determines it (class, prompt, backend, seed, duration, params). A second run skips every id already in the manifest whose file exists, so an interrupted run continues and paid clips are never bought twice.No retrieval indexing. Clips are made with
store=False.
The generation call is the generate_fn seam (default foley.generate()), so tests
and callers with another generator can inject theirs. Everything else here is stdlib.
Functions
|
Write the dataset |
|
Content address of a clip request: the same request gives the same id. |
Classes
|
One clip to make: a class label, a prompt, a backend, a seed and a duration. |
|
What to synthesize: a grid of |
|
What a run did. |
- class foley.dataset.ClipRequest(klass, prompt, backend, seed=None, duration_s=None, params=dict())[source]#
Bases:
objectOne clip to make: a class label, a prompt, a backend, a seed and a duration.
- class foley.dataset.DatasetReport(out_dir, made=0, skipped_done=0, refused=0, failed=0, spent_usd=0.0, stopped=None, seconds_by_class=dict(), synthetic_share=dict())[source]#
Bases:
objectWhat a run did.
stoppedisNonefor a finished run, else why it stopped.
- class foley.dataset.DatasetSpec(prompts, seeds=(0,), durations_s=(None,), backends=('pyfxr',), budget_usd=1.0, per_class_seconds=dict(), real_seconds=dict(), intended_use=None, params=dict(), extra=())[source]#
Bases:
objectWhat to synthesize: a grid of
prompts(by class) xseedsxdurations_sxbackends.- Parameters:
prompts (
Mapping[str,Sequence[str]]) –{class: [prompt, ...]}; the class is the label of the clips.seeds (
Sequence[Optional[int]]) – One clip per seed (a backend that takes no seed ignores it, with a note).durations_s (
Sequence[Optional[float]]) – Requested durations;Noneleaves the duration to the backend.backends (
Sequence[str]) – Registered generate sources. Each is a grid axis, so every backend makes its own clip of each (prompt, seed, duration); none is a fallback for another.budget_usd (
float) – Hard cap on the run’s spend (defaultDFLT_BUDGET_USD).per_class_seconds (
Mapping[str,float]) – Stop making clips of a class once it holds this many seconds (counting clips from earlier runs). Withworkers > 1a class can overshoot by up toworkers - 1clips.real_seconds (
Mapping[str,float]) – Seconds of real (non-synthetic) audio per class, only to report each class’s synthetic share.intended_use (
Any) – Thefoley.IntendedUseevery clip must satisfy;Nonemeans training use (will_train=True), so a generator whose licence forbids training is refused clip by clip.params (
Mapping[str,Any]) – Extra provider params, passed to every call (provider_params).extra (
Sequence[ClipRequest]) – Any furtherClipRequestto add to the grid.
- foley.dataset.request_id(**request)[source]#
Content address of a clip request: the same request gives the same id.
>>> a = request_id(klass="laser", prompt="zap", backend="pyfxr", seed=1, duration_s=None) >>> a == request_id(duration_s=None, seed=1, backend="pyfxr", prompt="zap", klass="laser") True >>> a == request_id(klass="laser", prompt="zap", backend="pyfxr", seed=2, duration_s=None) False
- Return type:
- foley.dataset.synthesize(spec, out_dir, *, generate_fn=None, workers=1, generate_kwargs=None)[source]#
Write the dataset
specdescribes intoout_dir; return aDatasetReport.- Parameters:
spec (
DatasetSpec) – TheDatasetSpec.out_dir – The dataset directory (created; an existing one is resumed).
generate_fn (
Optional[Callable[...,Any]]) –generate_fn(prompt, *, backend, store=False, seed=..., ...)returning afoley.Candidatewithaudio_bytes; defaultfoley.generate().workers (
int) – Clips made at once (default 1).generate_kwargs (
Optional[Mapping[str,Any]]) – Extra keyword arguments for everygenerate_fncall, e.g.{'check_prompt': False}to skip the CLAP prompt match (which needs thefoley[clap]model) or{'level': 'sfx_fg'}.
- Return type: