foley.eval.external_toolkit#

A reference toolkit run in its own interpreter: the part every adapter shares (#48, #262).

Several evaluation toolkits cannot share foley’s environment: fadtk and kadtk pin numpy<2 and an old torch, audiobox_aesthetics pulls a recent torch foley does not need. Each runs the way foley.external runs MFA and aeneas: clips are written as mono 16-bit WAVs to a temporary directory, the toolkit’s interpreter runs foley.eval.toolkit_driver on a JSON spec, and the JSON it writes back is the answer. ExternalToolkit is that mechanism (the interpreter and its install hint, the failure hints, the run); what is computed over the files is the subclass’s: a set-level distance (foley.eval.external_fidelity.ExternalFidelity) or a per-clip score (foley.eval.aesthetics.AudioboxAesthetics). Nothing from any toolkit is imported here.

Module Attributes

DRIVER

The script run inside a toolkit's interpreter.

MAX_CHANNELS

The most channels a clip may have.

SCORED

scored (no floor), above (ok) or below (low) a floor, or unchecked (it could not be had: the reason says why).

OK

scored (no floor), above (ok) or below (low) a floor, or unchecked (it could not be had: the reason says why).

LOW

scored (no floor), above (ok) or below (low) a floor, or unchecked (it could not be had: the reason says why).

UNCHECKED

scored (no floor), above (ok) or below (low) a floor, or unchecked (it could not be had: the reason says why).

REASON_MAX_CHARS

The longest reason an unchecked verdict stores.

Functions

as_frames_channels(wav)

wav as foley's (frames,) / (frames, channels); refuse other layouts.

clip_verdict(audio_bytes, *, scorer, scored)

Score one clip with scorer ((wavs, *, sr) -> [score]) and turn its one score into a verdict with scored(score, scorer); never raises.

publishable_reason(exc, *[, prefixes, max_chars])

exc as a short, publishable reason: its type, first and last line, no absolute path.

write_set(wavs, sr, folder, *, prefix[, check])

Write each waveform in wavs as a mono 16-bit WAV in folder; return the count.

Classes

ExternalToolkit(*[, python, env, timeout, ...])

A toolkit run by DRIVER in a separate interpreter.

foley.eval.external_toolkit.DRIVER = PosixPath('/home/runner/work/foley/foley/foley/eval/toolkit_driver.py')#

The script run inside a toolkit’s interpreter.

class foley.eval.external_toolkit.ExternalToolkit(*, python=None, env=None, timeout=None, runner=<function run>)[source]#

Bases: object

A toolkit run by DRIVER in a separate interpreter.

Subclasses set toolkit, python_env, install, isolation_reason (and optionally failure_hints), and call run_driver().

Parameters:
  • python (Optional[str]) – An interpreter with the toolkit installed, usually in its own venv (default: $<python_env>; neither set raises with the install line).

  • env (Optional[Mapping[str, str]]) – Variables added to this process’s environment for the program, e.g. {"TORCH_HOME": ...} or {"HF_HOME": ...} to choose where weights go.

  • timeout (Optional[float]) – Seconds before the run is abandoned (default: none).

  • runner (Callable[..., CompletedProcess]) – Runs the command (default subprocess.run).

failure_hints: Mapping[str, str] = {}#

A substring of a failed run’s output → what to do about it.

isolation_reason: str#

Why the toolkit cannot live in foley’s environment (said when no interpreter).

local_paths()[source]#

The interpreter as given and resolved, and its venv root: paths to keep out of anything published (foley.obs.redact.redact_paths()). Never raises.

Return type:

list[str]

resolve_python()[source]#

The toolkit’s interpreter as an executable path; raise with the install line if none.

Cheap (no program runs), so a caller can fail before anything is paid for.

Return type:

str

run_driver(spec, *, out, cwd, what, python=None)[source]#

Run DRIVER on spec (plus toolkit and out); return its JSON.

python is the already-resolved interpreter (default: resolve it now); a caller resolves it first to fail before writing any file.

Raises:
Return type:

dict

foley.eval.external_toolkit.LOW = 'low'#

scored (no floor), above (ok) or below (low) a floor, or unchecked (it could not be had: the reason says why).

Type:

A per-clip verdict’s status

foley.eval.external_toolkit.MAX_CHANNELS = 8#

The most channels a clip may have. A 2-D array with at most this many rows and more columns than that is channel-first, and is refused (as_frames_channels()).

foley.eval.external_toolkit.OK = 'ok'#

scored (no floor), above (ok) or below (low) a floor, or unchecked (it could not be had: the reason says why).

Type:

A per-clip verdict’s status

foley.eval.external_toolkit.REASON_MAX_CHARS = 200#

The longest reason an unchecked verdict stores.

foley.eval.external_toolkit.SCORED = 'scored'#

scored (no floor), above (ok) or below (low) a floor, or unchecked (it could not be had: the reason says why).

Type:

A per-clip verdict’s status

foley.eval.external_toolkit.UNCHECKED = 'unchecked'#

scored (no floor), above (ok) or below (low) a floor, or unchecked (it could not be had: the reason says why).

Type:

A per-clip verdict’s status

foley.eval.external_toolkit.as_frames_channels(wav)[source]#

wav as foley’s (frames,) / (frames, channels); refuse other layouts.

A channel-first (2, N) array would otherwise be read as two-sample clips.

Return type:

ndarray

foley.eval.external_toolkit.clip_verdict(audio_bytes, *, scorer, scored)[source]#

Score one clip with scorer ((wavs, *, sr) -> [score]) and turn its one score into a verdict with scored(score, scorer); never raises.

Anything that keeps a score from being had (no interpreter, a clip the scorer refuses, a timeout, a crash, a scorer answering anything but one well-formed score) gives {"status": "unchecked", "reason": ...} (publishable_reason()).

Return type:

dict

foley.eval.external_toolkit.publishable_reason(exc, *, prefixes=(), max_chars=200)[source]#

exc as a short, publishable reason: its type, first and last line, no absolute path.

A failed run’s message carries the program’s output tail and local paths, and the reason is stored on the record, so only its first line (what failed) and last line (the program’s error, or foley’s hint about it) are kept, cut, and scrubbed of paths by foley.obs.redact.redact_paths() (prefixes: the interpreter and its venv, replaced whole first).

Return type:

str

foley.eval.external_toolkit.write_set(wavs, sr, folder, *, prefix, check=None)[source]#

Write each waveform in wavs as a mono 16-bit WAV in folder; return the count.

Files are named <prefix><n:05d>.wav from 1, so sorting them keeps the input order. check(clip, sr=, name=), if given, sees each (frames[, channels]) clip first and raises to refuse it.

Return type:

int