foley.sources.stable_audio_3.adapter#
Stable Audio 3 Small-SFX generate adapter: Stability’s TFLite CPU build, run as a process.
The model is not a pip package: Stability ships it as optimized/tflite in
Stability-AI/stable-audio-3 (a script plus a requirements file, weights fetched on
first use from the ungated stabilityai/stable-audio-3-optimized). The adapter drives
that checkout’s scripts/sa3_tflite.py with the checkout’s own virtualenv Python, so
foley takes on no model dependency (the process and venv helpers are ps.isolated’s,
stdlib-only). The checkout is pinned to repo_commit (sa3_runtime(), #298). Setup is two commands
(setup_hint()); a missing checkout raises SourceConfigurationError with them,
which the generation order treats as “skip this backend”.
Seam:
runner=(runner(cmd, *, cwd, env, timeout) -> (returncode, output)) is the process boundary,ps.isolated.run_process()by default; a test injects a fake that writes the--outfile.envholds only the variables foley adds; the default runner layers them over the host’s environment minusPYTHONPATH,PYTHONHOMEandVIRTUAL_ENV, returns stdout and stderr interleaved, and on timeout kills the whole process tree.Offline: the process runs with
HF_HUB_OFFLINE=1when the runtime forbids external egress, and a failure then raisesModelNotCached(foley never downloads weights insidefoley.offline(), #86).Seed: always passed (a random one when none is given) and recorded, so every clip is reproducible from its provenance.
Distilled: CFG 1;
prompt_influenceis noted and not applied (#70), and a negative prompt only acts when CFG is above 1, so it is dropped with a note.
Module Attributes
Registry convention (arioso): the loader imports |
Functions
|
Whether the checkout and its virtualenv are in place (weights download on first use). |
|
Where the Stability checkout lives: |
|
The Stability checkout as a |
|
The commands that install the runtime and fetch the weights (never run by foley). |
Classes
Registry convention (arioso): the loader imports |
|
|
Local Stable Audio 3 Small-SFX adapter (a |
- foley.sources.stable_audio_3.adapter.Adapter#
Registry convention (arioso): the loader imports
adapter.Adapter.
- class foley.sources.stable_audio_3.adapter.StableAudio3Adapter(config=None, *, runner=None, home=None)[source]#
Bases:
objectLocal Stable Audio 3 Small-SFX adapter (a
GenerateAdapter).- Parameters:
config (
Optional[dict]) – TheSOURCE_CONFIG(the registry passes it positionally).runner (
Optional[Callable[...,Tuple[int,str]]]) – The process boundary (ps.isolated.Runner); defaults tops.isolated.run_process()(stdin closed, so a prompting script fails instead of waiting).home (
Optional[Path]) – The Stability checkout; defaults tosa3_home().
- generate(prompt, *, duration_s=None, prompt_influence=None, negative_prompt=None, steps=None, seed=None, loop=False, output_format='wav', provider_params=None, **kw)[source]#
Generate a sound for
prompton the CPU; return its bytes + provisional candidate.duration_sis clamped to the model’s 1..120 s (default 10 s); the model renders whole latent frames, so the clip may differ from it by a few milliseconds.seed=Nonedraws a random seed, recorded in the clip’s provenance (the script always takes one). Throughfoley.generate()the dispatch layer has already drawn it (foley.sources._dispatch.draws_seed(), #206); this draw serves a direct call.provider_params(#61) are native script flags merged over the translated ones (seconds,steps,cfg,seed; any other key is passed as--<key> <value>) and recorded ingeneration_params; the config’sprovider_paramspolicy refuses the prompt, output path and model flags.- Return type:
- invoke_native(prompt, native)[source]#
Run the script with native flags into a temp file; return the WAV bytes it wrote.
The public entry below foley’s translation (#61): each
nativekey (the script’sseconds/steps/cfg/seed, or any other flag) becomes a--<key> <value>flag, followed by foley’s own--dit/--decoder/--prompt/--out. No licence record is built and no dispatch-layer check runs (cost, egress): a caller owns those.- Return type:
- foley.sources.stable_audio_3.adapter.runtime_ready(config=None, *, home=None)[source]#
Whether the checkout and its virtualenv are in place (weights download on first use).
- Return type:
- foley.sources.stable_audio_3.adapter.sa3_home(config=None)[source]#
Where the Stability checkout lives:
$FOLEY_SA3_DIR, else the config’s default.- Return type:
- foley.sources.stable_audio_3.adapter.sa3_runtime(config=None, *, home=None)[source]#
The Stability checkout as a
ps.isolated.Runtimepinned torepo_commit.An explicit
homeis the caller’s own installation, so it is not checked against the pin (as for a root named by$FOLEY_SA3_DIR, which only warns).- Return type:
Runtime