foley.sources.freesound.adapter#
Freesound APIv2 retrieve adapter — CC0 (and CC-BY) sounds, stored strictly by-reference.
Freesound (report 01 §Freesound) is foley’s anchor retrieve source. This adapter
turns a natural-language query into ranked, license-clean
Candidates over the Freesound APIv2, honoring two
load-bearing constraints:
CC0 by default, CC-BY on request, pushed into the query. The CC0 filter is sent as the native
filter=license:"Creative Commons 0"so other sounds never leave the server (alicenseother than CC0 also asks for"Attribution": the credit-bearing sounds thekeep()gate then admits only for a caller that can attribute). Each returned item is also re-checked fail-closed against theaccepted_license_idsallowlist — the server filter is a promise foley does not control, so an NC / SA / ND item that slips through is dropped, never indexed.By-reference storage (TOS). The Freesound API TOS forbids caching the audio bytes even for CC0, so every sound is licensed
cache_bytes_ok=False(a per-item override on top of its own CC id — seeapi_license()). foley keeps the stable sound-page URI + provenance + the CLAP vector; the bytes fetched here (a token-tier previewtranscode) are transient — embedded once by
ingest_one(), then discarded, never persisted.
HTTP is dependency-injected (a Transport), so the
adapter is fully testable with no network and import foley stays dol-only; the
real requests lives only behind
requests_transport() (the foley[freesound] extra).
Ingestion (decode / QC / embed / tag / store) is NOT reimplemented here — the
foley.sources.pull.add_from() façade routes every hit through the shared
ingest_one pipeline (it wraps the corpus machinery, it does not fork it).
Module Attributes
Registry convention (arioso): the loader imports |
Classes
Registry convention (arioso): the loader imports |
|
|
Live Freesound APIv2 retrieve adapter (a |
- foley.sources.freesound.adapter.Adapter#
Registry convention (arioso): the loader imports
adapter.Adapter.
- class foley.sources.freesound.adapter.FreesoundAdapter(config=None, *, api_key=None, http=None)[source]#
Bases:
objectLive Freesound APIv2 retrieve adapter (a
SourceAdapter).- Parameters:
config (
Optional[dict]) – TheSOURCE_CONFIG(defaults to the module’s). Passed positionally by the registry’s lazy loader (the ariosoAdapter(config)convention).api_key (
Optional[str]) – The Freesound token. Defaults to$FREESOUND_API_KEY.http (
Optional[Transport]) – The injectedTransport(defaults torequests_transport()); tests pass a fake.
- property api_key: str#
The Freesound token (constructor, else a bound key, else
$FREESOUND_API_KEY).
- download(source_id, *, preview_url=None)[source]#
Return a sound’s transient preview bytes (token-tier; never cached).
- Parameters:
- Return type:
- Returns:
The preview audio bytes (embedded once, then discarded — see the by-reference storage contract).
- Raises:
LookupError – If the sound exposes no preview.
- get(source_id)[source]#
Resolve one Freesound id (
'12345'or'freesound:12345') to a record.- Raises:
LookupError – If the sound’s license is not in the accepted allowlist.
- Return type:
- invoke_native(path, **params)[source]#
GET a Freesound APIv2
pathwith nativeparams; return the parsed JSON.The public escape hatch below foley’s translation (#61), e.g.
invoke_native("/search/", query="rain", filter="ac_brightness:[50 TO 100]"). It bypasses the licence filter and the per-item licence re-check thatsearch()applies: the caller owns licence gating for what it gets back (and the dispatch layer’s egress check is not run either).- Raises:
RuntimeError – On a non-200 response (with Freesound’s
detail).
- search(query, *, license='cc0', k=15, duration_range=None, sort=None, page=1, kind='sfx', similar_to=None, ucs_category=None, provider_params=None, **kw)[source]#
Search Freesound for
query; return license-clean candidates.The license filter is pushed into the native Solr
filterso other sounds never leave the server; every returned item is still re-checked fail-closed before it becomes a candidate.- Parameters:
license (
Optional[str]) – A licence id ('cc0'is an alias for CC0-1.0,'cc-by'keeps the CC-BY ids).'cc0'(default) sends the CC0 filter; another id asks for CC0 + Attribution;Nonesends no filter. Whatever the filter, only items under the asked id (and theaccepted_license_idsallowlist) are kept, so NC / SA / ND never come back.k (
int) – Max results (Freesound capspage_sizeat 150).duration_range (
Optional[tuple[float,float]]) – Optional(min_s, max_s)native duration filter.sort (
Optional[str]) –relevance(default) |newest|popular|duration, translated to Freesound’s native key.page (
int) – The results page (1-based,kper page).kind (
str) –sfx(default, no filter) ormusic(the Broad Sound Taxonomy’s “Music” top level). With aucs_categorythat maps to another top level it raisesSearchArgumentError(nothing could match).similar_to (
Optional[str]) – A Freesound sound id (either id form): “more like this one”.ucs_category (
Optional[str]) – A UCS CatID or category, mapped to a coarse Broad Sound Taxonomycategorypre-filter (no filter if it is not recognised;SearchArgumentErrorifkindasks for another top level).provider_params (
Optional[dict]) – Native Freesound search params foley has no affordance for, merged over the translated ones (#61), e.g.{"filter": "ac_brightness:[50 TO 100]"}. Per the config’sprovider_paramspolicy, afilteris appended to foley’s as one group (the licence filter cannot be replaced or widened, and a category clause is refused whenkind/ucs_categoryalready send one),fieldsare appended to foley’s (the licence fields cannot be dropped), andqueryis refused; the per-item licence re-check still applies.**kw – Ignored extra affordances (
on_unsupported_param='warn').
- Return type:
- Returns:
Up to
kCandidates (origin=retrieved), each carrying a by-referenceLicenseRecord, a transientpreview_uriand the item JSON it was parsed from asraw.