foley.prompt_match#
Does a generated clip sound like what was asked for? A text-audio check, or an honest “unchecked”.
Tier-0 QC (foley.qc) catches broken audio: clipping, silence, NaN. It cannot
catch a clean, well-levelled clip of the wrong thing, and a text-to-audio model
produces those: asked for “a flintlock musket placed into a hand”, Stable Audio 3
returned a sound that had nothing to do with it, and it went through unflagged. That
is the job here: score the clip against its own prompt in a joint text-audio
embedding space (CLAP), and flag it when the score is under the embedder’s threshold.
An embedder takes part only when it says its two spaces are comparable, by carrying a
prompt_match_threshold (foley.index.embedders.ClapEmbedder does). Anything
else, a test’s bag-of-words fake, no embedder at all, an embedder whose model cannot
load on this host, gives status='unchecked' with the reason: never a silent pass.
The verdict is a flag, not a quarantine: the clip is kept (it was paid for) and the
candidate’s notes and record.qc['prompt_match'] say it does not match, so a person
or the SELECT agent listens before using it.
Zero-dependency import: numpy and the embedder’s own stack load inside.
Module Attributes
Where the per-checkpoint calibrated thresholds live (package data, so they ship in the wheel). |
|
the clip matches its prompt, does not, or was not checked. |
|
the clip matches its prompt, does not, or was not checked. |
|
the clip matches its prompt, does not, or was not checked. |
Functions
|
An embedder's prompt-match threshold: its override, else the calibration, else |
|
|
|
The one-line candidate note for a |
|
Score |
|
The calibrated threshold of checkpoint |
- foley.prompt_match.MATCH = 'match'#
the clip matches its prompt, does not, or was not checked.
- Type:
statusvalues
- foley.prompt_match.MISMATCH = 'mismatch'#
the clip matches its prompt, does not, or was not checked.
- Type:
statusvalues
- foley.prompt_match.THRESHOLDS_PATH = PosixPath('/home/runner/work/foley/foley/foley/data/prompt_match/thresholds.json')#
Where the per-checkpoint calibrated thresholds live (package data, so they ship in the wheel). Written by
foley.eval.prompt_match.save_threshold().
- foley.prompt_match.UNCHECKED = 'unchecked'#
the clip matches its prompt, does not, or was not checked.
- Type:
statusvalues
- foley.prompt_match.calibrated_threshold(model_id, override=None, *, provisional)[source]#
An embedder’s prompt-match threshold: its override, else the calibration, else
provisional.- Return type:
- foley.prompt_match.load_thresholds(path=PosixPath('/home/runner/work/foley/foley/foley/data/prompt_match/thresholds.json'))[source]#
{model_id: calibration dict}; empty when nothing has been calibrated.- Return type:
- foley.prompt_match.note_for(result)[source]#
The one-line candidate note for a
prompt_match()result.
- foley.prompt_match.prompt_match(prompt, audio_bytes, *, embedder, fallback=None)[source]#
Score
audio_bytesagainstpromptwithembedder; never raises.- Parameters:
prompt (
str) – The text the clip was generated from.audio_bytes (
bytes) – The clip (any formatsoundfiledecodes).embedder – A text-audio embedder (
embed_text/embed_audio, L2-normalised vectors) carryingprompt_match_threshold; anything else isunchecked.fallback – A callable returning a second embedder (or
None), tried only whenembedderwas meant to check but could not run (it failed to load or embed: a small host withouttransformers). Its own threshold applies and its model is named in the result. The defaultNonetries nothing else.
- Returns:
status(match|mismatch|unchecked), andscore(cosine similarity),thresholdandmodelwhen checked, orreasonwhen not.- Return type:
>>> prompt_match("a door creak", b"", embedder=None)["status"] 'unchecked'