foley.sources.edit#
Edits of a sound (#162): audio-to-audio, inpaint, extend — the parts an edit adds to generation.
An edit is a generation mode ('edit': an edit source given a source clip,
audio=), so it runs through the same dispatch as every generation
(foley.generate(): cost gate, budget, generations cache, safety screen,
watermark, ingest, QC). What is particular to an edit lives here:
edit_lineage()— the mode’s licence gate, run by the generation workhorse before anything is paid for. An edit needs its source’s rights (derived_from=: the source’sSoundRecord, or itsLicenseRecord); without them, or with rights that do not allowan edit (
foley.licensing.derivative_refusal()), it is refused fail-closed (EditRefusal). This holds forfoley.edit()and for a rawfoley.generate(..., audio=...)alike.EditLineage— what the edit derives from. It keys the request (an edit’s cache entry is never shared with another source or licence), and is applied to the new clip’s licence before the repair, the watermark, the credential and the ingest: the rights are narrowed to the source’s (foley.licensing.narrow_to_source()), and the edit (op, parameters, source id, content key, licence, credit) is appended totransformations, which the credits (foley.provenance.credits.derived_sources()) and the content credential (aparentOfingredient) read.resolve_edit()— whatfoley.edit()adds on top: the source sound from the library (its bytes, which must be sendable), the op and the backend (edit_backend(): named, or the op’s default from the registry configs’edit_op), and, given an intended use, whether the edit could serve it (edit_use_refusal()).estimate_edit()— what an edit would cost, priced by its op and backend through the same path as the call (foley.estimate()('edit', ...)).
Module Attributes
What an edit may be told it derives from ( |
Functions
|
The backend that runs an edit of |
|
The gated |
|
Why the edit |
|
What |
|
Resolve an edit of a library sound: its record, its op and its backend. |
Classes
|
An edit of a library sound, resolved (see |
|
What an edited clip derives from: the op and its parameters, and the source. |
- class foley.sources.edit.EditCall(backend, prompt, source, op)[source]#
Bases:
objectAn edit of a library sound, resolved (see
resolve_edit()).- source#
The source sound’s record (the edit’s
derived_from).- Type:
- op#
The edit op (a
foley.base.EDIT_OPSname).- Type:
- class foley.sources.edit.EditLineage(op, source_id, source_license, source_credit, source_content=None, params=dict())[source]#
Bases:
objectWhat an edited clip derives from: the op and its parameters, and the source.
- op#
The edit op (a
foley.base.EDIT_OPSname).- Type:
- source_license#
The source’s rights.
- Type:
- source_credit#
The source’s own credit line (
foley.provenance.credits.attribution_line(), plain).- Type:
- apply(lic)[source]#
Make
lic(the new clip’s licence) say what it derives from, in place: its rights narrowed to the source’s, the edit appended to itstransformations.- Return type:
- transformation()[source]#
The
transformationsentry recording this edit (JSON-safe; also its key).>>> from foley.base import LicenseRecord >>> lin = EditLineage("extend", "s1", LicenseRecord(source="u", license_id="CC0-1.0"), ... '"Door" by u', params={"extend_after_s": 2.0}) >>> t = lin.transformation() >>> t["op"], t["source_license_id"], t["source_license_name"][:7] ('extend', 'CC0-1.0', 'CC0 1.0')
- Return type:
- twin_refusal(twin, made)[source]#
Why a byte-identical sound already in the library (rights
twin) may not be handed back as this edit (whose narrowed rights aremade), orNone.It may when it is this same edit (its
transformationshold this one) and is no wider thanmade(foley.licensing.wider_rights()).
- foley.sources.edit.EditSource#
What an edit may be told it derives from (
derived_from=).alias of
SoundRecord|LicenseRecord
- foley.sources.edit.edit_backend(op, backend=None, *, injected=None)[source]#
The backend that runs an edit of
op:backend, else theinjectedadapter config’s name, else the op’s default (foley.sources.generate.default_edit_backend()).Read from the configs only: no adapter is built and no key is needed, so an estimate resolves the backend exactly as the call does.
- Raises:
ValueError – For an unknown op, or a named backend that does another op.
KeyError – For an unknown backend.
- Return type:
- foley.sources.edit.edit_lineage(derived_from, *, config, affordances)[source]#
The gated
EditLineageof an edit call: the edit mode’s licence gate (#162).Run by the generation workhorse before anything is paid for, for every call of an edit source given its source clip (
affordances['audio']).- Parameters:
derived_from (
Union[SoundRecord,LicenseRecord,None]) – The source clip’sSoundRecord(whatfoley.edit()passes), or itsLicenseRecord(a clip that is not in the library). Required.config (
dict) – The edit source’s config (itsedit_op).affordances (
dict) – The call’s affordances (the clip, the op’s parameters).
- Raises:
EditRefusal – Without
derived_from; when its rights do not allow the edit (foley.licensing.derivative_refusal()), or the backend’s vendor trains on its input and they do not allow that (foley.licensing.vendor_training_refusal()); or when the clip sent is not the bytes of thederived_fromrecord.TypeError – For a
derived_fromthat is neither record.
- Return type:
- foley.sources.edit.edit_use_refusal(call, intended_use)[source]#
Why the edit
callcould not serveintended_use, orNoneif it can.The edit’s rights are its backend’s narrowed to its source’s (
EditLineage.apply()), so the use is refused when either refuses it: an edit of a non-commercial sound under a commercial use is money spent on a clip nobody may place. Decided before anything is paid for; a backend’s refusal names the other backends of the op that could run this edit (_could_edit()) and whose licence fits.
- foley.sources.edit.estimate_edit(op, *, source=None, backend=None, library=None, adapter=None, **kwargs)[source]#
What
foley.edit()ofopwould cost in USD, orNoneif unknown.Priced by the backend the call would use (
edit_backend(): named, or the op’s default, whether or not paid generation is opted in: the price is what opting in would spend) through the call’s own pricing (foley.sources._dispatch.estimate_generation(): same translation, same parameter checks, same input cover). Givensource, the clip is read fromlibrary(default: the process-wide one), so a window past its end raises as the call would, and a price by the clip’s length is known.- Parameters:
op (
str) – The edit op (foley.base.EDIT_OPS).source (
Optional[str]) – The library id of the sound to edit (optional).backend (
Optional[str]) – An edit source doingop;None: the op’s default.library – The library holding
source.adapter – An injected adapter, as the call’s: its config names the backend and prices it (the plan prices the adapter’s config).
**kwargs – The op’s parameters and the call’s other keywords (the ones that are not generation affordances,
prompt=included, are ignored).
- Raises:
ValueError – For an unknown op, a backend that does another op, the op’s parameters missing or out of range, or an
audio=/derived_from=(asfoley.edit()).KeyError – For an unknown backend, or a
sourcenot in the library.
- Return type:
- foley.sources.edit.resolve_edit(source, op, prompt='', *, library, backend=None, adapter=None, affordances=None)[source]#
Resolve an edit of a library sound: its record, its op and its backend.
The op’s parameters and the source’s rights are checked by the generation’s edit mode itself (
foley.sources._dispatch.translate_affordances(),edit_lineage()), before anything is paid for. Checked here is what must be known before the source’s bytes are read from the library, and, whenaffordancescarry anintended_use, whether the edit could serve it (edit_use_refusal()).- Parameters:
source (
str) – The library id of the sound to edit.op (
str) –'audio_to_audio'|'inpaint'|'extend'(foley.base.EDIT_OPS).prompt (
str) – What the edit should sound like;'': the source’s caption.library – The
SoundLibraryholdingsource.backend (
Optional[str]) – An edit source that doesop;None: the injectedadapter’s, else the op’s default (foley.sources.generate.default_edit_backend()), which is paid, so it needs paid generation opted in ($FOLEY_GENERATE_PAID=1; a key in the environment is not consent, #58).adapter – An injected adapter (its config names the backend).
affordances (
Optional[dict]) – The call’s other keywords (anaudio=orderived_from=is refused: both come from the library).
- Raises:
ValueError – For an unknown op, an
audio=orderived_from=, or a backend that does another op.KeyError – If
sourceis not inlibrary, orbackendis unknown.EditRefusal – If the source’s bytes may not be sent on (
foley.licensing.upload_refusal(): a by-reference Freesound sound), or the edit could not serve theintended_usegiven.SourceConfigurationError – For an unnamed paid backend without the opt-in.
- Return type: