an.sound_fetch#
Add a sound from a URL, with its provenance and the cut taken (an#318).
A production that sources its music or an effect from the web used to write
the same script each time: download, cut with ffmpeg, type an AssetSource
by hand, an.sounds.add_sound(). add_sound_from_url() is that script:
the download is a seam,
fetcher=: any(url) -> Fetched(the bytes in any container ffmpeg reads, and what the source says about itself). The default,yb_fetcher(), uses yb when it is installed (pip install ybwith itsyt-dlpextra); it is never a dependency ofan. Another ingest (braidio’s) plugs in here;the cut (
start,duration,fade_out) is made by ffmpeg into a 16-bit WAV, and recorded with the source, soan creditssays which part of which page it is (“0:07.9–0:08.8 of <url>”);the licence is the caller’s statement, never guessed: required, and
"unknown"says so explicitly (the sound is then UNVERIFIED) – unless the source states its own rights (Fetched.source). A sound from a foley library does (an#729):foley_fetcher()readsfoley:<sound_id>throughfoley.export_sound, whose rights become the sound’sAssetSource(foley_asset_source(), with foley’swhole provenance as
foley_provenance), so the licence may be omitted, and a caller’s licence that disagrees is refused. A fetcher says which refs it states rights for (fetcher_states_rights()), so a licence missing for any other is refused before anything is downloaded. The default fetcher (default_fetcher()) sends afoley:ref to foley and anything else toyb, soan sounds add <project> door foley:fsd-222works.
>>> fetched = Fetched(audio=b"...", url="https://example.org/a", id="a", author="Ann")
>>> fetched.provider
'web'
Module Attributes
the caller states no licence, which only a source that states its own rights ( |
|
how |
Functions
|
Fetch |
|
What an AI-generated source's disclosure says, or |
|
|
|
The default |
|
Whether |
|
|
|
foley's |
|
Fetch |
|
The notice a source's licence requires shown verbatim, or |
|
Fetch the audio of |
Classes
|
What a fetcher returns: the media's bytes, and what its page says about it. |
|
The type of |
- class an.sound_fetch.Fetched(audio, url, id=None, title=None, author=None, provider='web', source=None)[source]#
Bases:
objectWhat a fetcher returns: the media’s bytes, and what its page says about it.
When
sourceis set it is the sound’s whole provenance (the rights the source states), andid,title,authorandproviderare not read; otherwise they are, with the caller’s licence.- source: AssetSource | None = None#
The rights the source itself states (a foley library’s export), or
None: then the licence is the caller’s statement.
- an.sound_fetch.Fetcher#
how
add_sound_from_url()gets the media. A fetcher whose source states its own rights for some refs says which with astates_rights(url) -> boolattribute (fetcher_states_rights()).- Type:
(url) -> Fetched
- an.sound_fetch.UNSTATED = Unstated.UNSTATED#
the caller states no licence, which only a source that states its own rights (
Fetched.source) may do.- Type:
license=left out
- class an.sound_fetch.Unstated(*values)[source]#
Bases:
EnumThe type of
UNSTATED,license=left out.
- an.sound_fetch.add_sound_from_url(store, key, url, *, license=Unstated.UNSTATED, fetcher=None, start=None, duration=None, fade_out=None, provider=None, author=None, description='')[source]#
Fetch
url, cut it, and put it in the soundsstoreunderkeywith its provenance.- license: the licence code the caller vouches for, never guessed;
"unknown"(orNone) records that nobody has said. Required unless the source states its own rights (Fetched.source, afoley:sound), which are then recorded; a licence given with them must agree- fetcher:
(url) -> Fetched(defaultdefault_fetcher(): a foley:<sound_id>ref from foley, anything else withyb)
start, duration, fade_out: the cut, in seconds of the fetched media provider, author: override what the fetcher reported (never on a source
that states its rights)
No cut is recorded when the whole media is kept (no
start,durationorfade_out).- Raises:
SoundError – For no licence for a ref the fetcher states no rights for (before anything is fetched:
fetcher_states_rights()), or from a source that turned out to state none; a caller’s licence that contradicts the source’s, or a provider or author set over it; and whatever the fetch, the cut or the store refuse.- Return type:
- an.sound_fetch.ai_label(source)[source]#
What an AI-generated source’s disclosure says, or
Nonefor any other.The model; whether the disclosure is a duty (a recognizable voice: “must be disclosed”) or a recommendation; and, when foley’s EU AI Act Art. 50 checklist is not
publish_ready, the obligations still pending.>>> ai = {"is_ai_generated": True, "publish_ready": False, ... "pending": ["machine_readable_mark", "provenance_manifest"], ... "obligations": {"voice_disclosure": {"required": False}}, ... "provenance": {"generator_model": "stable-audio-open-1.0"}} >>> ai_label(AssetSource(provider="stability-ai", foley_provenance={"ai_disclosure": ai})) 'AI-generated with stable-audio-open-1.0: disclosure recommended; not publish-ready, Art. 50 pending: machine_readable_mark, provenance_manifest' >>> ai_label(AssetSource(provider="fsd50k")) is None True
- an.sound_fetch.cut_to_wav(audio, *, start=None, duration=None, fade_out=None)[source]#
audio(any container ffmpeg reads) cut to[start, start + duration], as 16-bit WAV.fade_out: seconds of linear fade at the end of the cut.- Return type:
- an.sound_fetch.default_fetcher(url)[source]#
The default
fetcher=:foley_fetcher()for afoley:ref, elseyb_fetcher().- Return type:
- an.sound_fetch.fetcher_states_rights(fetcher, url)[source]#
Whether
fetcherdeclares that its source states the rights ofurl.Read from its
states_rights(url)attribute (afunctools.partialof a fetcher keeps the declaration); a fetcher without one states none.>>> fetcher_states_rights(default_fetcher, "foley:fsd-222") True >>> fetcher_states_rights(default_fetcher, "https://youtu.be/x"), fetcher_states_rights(print, "x") (False, False)
- Return type:
- an.sound_fetch.file_digest_fields(fields)[source]#
fieldswithsha256(the fetched or library file’s) moved toFILE_SHA256_FIELD: a stored sound is the cut WAV, whose digest is theSoundAsset’s (an#623, an#729).>>> file_digest_fields({"provider": "p", "sha256": "ab"}) {'provider': 'p', 'file_sha256': 'ab'}
- an.sound_fetch.foley_asset_source(rights, provenance, *, url=None)[source]#
foley’s
(rights, provenance)(foley.export_sound) as anAssetSource.rightsis keyed by the source’s own field names (foley pins them tolacing.Rights, an’sAssetSource); itstitlerides as an extra.sha256is the exported bytes’ digest, and the wholeprovenance(JSON-safe) rides asFOLEY_PROVENANCE_FIELD.urlis where the bytes came from (foley:<sound_id>).>>> src = foley_asset_source( ... {"provider": "fsd50k", "id": "222", "title": "Door creak", "license": "cc-by-4.0", ... "attribution": "Door creak by amy", "author": None}, ... {"sha256": "ab", "archived_sha256": "cd", "ai_disclosure": None}, url="foley:fsd-222") >>> src.provider, src.license, src.url, src.author, src.sha256 ('fsd50k', 'cc-by-4.0', 'foley:fsd-222', None, 'ab') >>> src.model_extra["title"], src.model_extra["foley_provenance"]["archived_sha256"] ('Door creak', 'cd')
- Return type:
- an.sound_fetch.foley_fetcher(ref, *, export=None)[source]#
Fetch
foley:<sound_id>from a foley library, with the rights foley records.- export:
(sound_id) -> (bytes, rights, provenance), default foley.export_sound(its default library; bind another withfunctools.partial(foley.export_sound, library=...)). foley is imported on first use:import annever imports it.
The bytes are checked against the digest foley’s provenance names, and the rights become
Fetched.source(foley_asset_source()), the sound’s only rights. It states rights for everyfoley:ref (foley_fetcher.states_rights).- Raises:
SoundError – For a ref that is not
foley:<sound_id>, foley not installed, a sound foley does not hold or will not export (its terms forbid keeping the bytes: a Freesound API pull is stored by reference; its bytes changed since ingest; a failed re-encode), naming the ref and foley’s reason, or bytes that do not match the digest foley names.- Return type:
- export: