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’s SoundRecord, or its LicenseRecord); without them, or with rights that do not allow

    an edit (foley.licensing.derivative_refusal()), it is refused fail-closed (EditRefusal). This holds for foley.edit() and for a raw foley.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 to transformations, which the credits (foley.provenance.credits.derived_sources()) and the content credential (a parentOf ingredient) read.

  • resolve_edit() — what foley.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

EditSource

What an edit may be told it derives from (derived_from=).

Functions

edit_backend(op[, backend, injected])

The backend that runs an edit of op: backend, else the injected adapter config's name, else the op's default (foley.sources.generate.default_edit_backend()).

edit_lineage(derived_from, *, config, ...)

The gated EditLineage of an edit call: the edit mode's licence gate (#162).

edit_use_refusal(call, intended_use)

Why the edit call could not serve intended_use, or None if it can.

estimate_edit(op, *[, source, backend, ...])

What foley.edit() of op would cost in USD, or None if unknown.

resolve_edit(source, op[, prompt, backend, ...])

Resolve an edit of a library sound: its record, its op and its backend.

Classes

EditCall(backend, prompt, source, op)

An edit of a library sound, resolved (see resolve_edit()).

EditLineage(op, source_id, source_license, ...)

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: object

An edit of a library sound, resolved (see resolve_edit()).

backend#

The edit source that will run it.

Type:

str

prompt#

The prompt sent (the source’s caption when none was given).

Type:

str

source#

The source sound’s record (the edit’s derived_from).

Type:

SoundRecord

op#

The edit op (a foley.base.EDIT_OPS name).

Type:

str

class foley.sources.edit.EditLineage(op, source_id, source_license, source_credit, source_content=None, params=dict())[source]#

Bases: object

What an edited clip derives from: the op and its parameters, and the source.

op#

The edit op (a foley.base.EDIT_OPS name).

Type:

str

source_id#

The source sound’s id (None when only its licence is known).

Type:

Optional[str]

source_license#

The source’s rights.

Type:

LicenseRecord

source_credit#

The source’s own credit line (foley.provenance.credits.attribution_line(), plain).

Type:

str

source_content#

The content key of the clip sent (its bytes’ digest).

Type:

Optional[str]

params#

The op’s parameters as given (strength, the windows).

Type:

dict

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 its transformations.

Return type:

LicenseRecord

transformation()[source]#

The transformations entry 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:

dict

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 are made), or None.

It may when it is this same edit (its transformations hold this one) and is no wider than made (foley.licensing.wider_rights()).

Return type:

Optional[str]

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 the injected adapter 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:

str

foley.sources.edit.edit_lineage(derived_from, *, config, affordances)[source]#

The gated EditLineage of 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:
Raises:
Return type:

EditLineage

foley.sources.edit.edit_use_refusal(call, intended_use)[source]#

Why the edit call could not serve intended_use, or None if 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.

Return type:

Optional[str]

foley.sources.edit.estimate_edit(op, *, source=None, backend=None, library=None, adapter=None, **kwargs)[source]#

What foley.edit() of op would cost in USD, or None if 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). Given source, the clip is read from library (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 doing op; 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= (as foley.edit()).

  • KeyError – For an unknown backend, or a source not in the library.

Return type:

Optional[float]

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, when affordances carry an intended_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 SoundLibrary holding source.

  • backend (Optional[str]) – An edit source that does op; None: the injected adapter’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 (an audio= or derived_from= is refused: both come from the library).

Raises:
Return type:

EditCall