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 --out file. env holds only the variables foley adds; the default runner layers them over the host’s environment minus PYTHONPATH, PYTHONHOME and VIRTUAL_ENV, returns stdout and stderr interleaved, and on timeout kills the whole process tree.

  • Offline: the process runs with HF_HUB_OFFLINE=1 when the runtime forbids external egress, and a failure then raises ModelNotCached (foley never downloads weights inside foley.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_influence is 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

Adapter

Registry convention (arioso): the loader imports adapter.Adapter.

Functions

runtime_ready([config, home])

Whether the checkout and its virtualenv are in place (weights download on first use).

sa3_home([config])

Where the Stability checkout lives: $FOLEY_SA3_DIR, else the config's default.

sa3_runtime([config, home])

The Stability checkout as a ps.isolated.Runtime pinned to repo_commit.

setup_hint([config])

The commands that install the runtime and fetch the weights (never run by foley).

Classes

Adapter

Registry convention (arioso): the loader imports adapter.Adapter.

StableAudio3Adapter([config, runner, home])

Local Stable Audio 3 Small-SFX adapter (a GenerateAdapter).

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: object

Local Stable Audio 3 Small-SFX adapter (a GenerateAdapter).

Parameters:
  • config (Optional[dict]) – The SOURCE_CONFIG (the registry passes it positionally).

  • runner (Optional[Callable[..., Tuple[int, str]]]) – The process boundary (ps.isolated.Runner); defaults to ps.isolated.run_process() (stdin closed, so a prompting script fails instead of waiting).

  • home (Optional[Path]) – The Stability checkout; defaults to sa3_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 prompt on the CPU; return its bytes + provisional candidate.

duration_s is 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=None draws a random seed, recorded in the clip’s provenance (the script always takes one). Through foley.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 in generation_params; the config’s provider_params policy refuses the prompt, output path and model flags.

Return type:

GeneratedClip

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 native key (the script’s seconds / 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:

bytes

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:

bool

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:

Path

foley.sources.stable_audio_3.adapter.sa3_runtime(config=None, *, home=None)[source]#

The Stability checkout as a ps.isolated.Runtime pinned to repo_commit.

An explicit home is 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

foley.sources.stable_audio_3.adapter.setup_hint(config=None)[source]#

The commands that install the runtime and fetch the weights (never run by foley).

Return type:

str