foley.agent.preview#
Audition UX — preview a sound, find similar ones, and refine by relevance feedback (#12).
The interactive/agentic layer over the existing retrieval engine, all thin over
foley.index.SoundLibrary:
preview()— synthesize a short audition clip for a sound and reference it by a store key (never raw bytes over the wire); degrades topreview_uri=Nonewhen the audio codec extra is absent.similar_to()— “more like this”:sound_id/Candidate→ by-id neighbours (SoundLibrary.similar), or a raw clip → audio-to-audio search (SoundLibrary.search_clip). A NEW clip/candidate-in entrypoint, distinct from the existing by-idSoundLibrary.similar.refine()— TRUE relevance feedback (distinct from the query-paraphrasefoley.refine_query()): expand the query for recall, pull neighbours of thesession’s picks, drop its rejects, and re-rank.
Dol-only core (numpy/soundfile only inside preview()’s encode path).
Module Attributes
Default audition length (seconds). |
Functions
|
Produce a short audition of a sound; set its |
|
Relevance-feedback refinement: expand for recall, boost picks, drop rejects, re-rank. |
|
"More like this" — neighbours of a sound id / candidate, or of a raw clip. |
Classes
|
The output of |
- class foley.agent.preview.RefineResult(queries, results)[source]#
Bases:
objectThe output of
refine(): the expanded queries and the re-ranked candidates.
- foley.agent.preview.preview(candidate_or_id, *, seconds=6, library=None, byte_store=None, session=None)[source]#
Produce a short audition of a sound; set its
preview_urito a store key.Writes the first
secondsof the clip (FLAC) intobyte_storeunder its content key and pointsCandidate.preview_uriat that key — referencing the audio, never returning bytes. Fail-safe: if the audio codec extra (foley[audio]) or the clip is unavailable,preview_uriisNone(the sound id + duration still let a client fetch it).- Parameters:
candidate_or_id – A
Candidateor a sound id.seconds (
int) – Audition length.library – The
foley.index.SoundLibrary(default: the shared one).byte_store – A
MutableMapping[str, bytes]to hold the preview (default: none — thenpreview_uristaysNone).session (
Optional[SessionStore]) – Optional session (unused here; accepted for a uniform signature).
- Return type:
- Returns:
The candidate with
preview_uriset (orNoneon graceful degradation).
- foley.agent.preview.refine(session=None, *, query=None, picked_ids=(), rejected_ids=(), hint=None, n=3, k=10, library=None, refiner=None)[source]#
Relevance-feedback refinement: expand for recall, boost picks, drop rejects, re-rank.
Distinct from
foley.refine_query()(which only paraphrases a query): this reads the session’s picks/rejects (or the explicitpicked_ids/rejected_ids), expands the query into paraphrases for recall, gathers neighbours of every pick, drops the rejects, and re-ranks by score.- Parameters:
session (
Optional[SessionStore]) – The audition session (source of picks/rejects when not passed explicitly).query (
Optional[str]) – The base text query to expand (optional).rejected_ids (
tuple[str,...]) – Explicit feedback (override the session’s).n (
int) – Paraphrases to request.k (
int) – Result depth.library – The
foley.index.SoundLibrary(default: the shared one).refiner – The query-expansion seam (default: the deterministic fake).
- Return type:
- Returns:
A
RefineResult.
- foley.agent.preview.similar_to(clip_or_candidate, *, k=10, library=None)[source]#
“More like this” — neighbours of a sound id / candidate, or of a raw clip.
A
strid or aCandidateuses by-id neighbours (SoundLibrary.similar, self excluded); a raw working-array / bytes clip uses audio-to-audio search (SoundLibrary.search_clip).