Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
70 lines
2.5 KiB
Python
70 lines
2.5 KiB
Python
"""Sound effects on Replicate: Stable Audio 2.5 (Stability AI's hosted model).
|
|
|
|
Licence check (2026-10-05):
|
|
|
|
* ``zsxkib/mmaudio`` (video-to-audio) is NOT used: its code is MIT but the
|
|
checkpoints are CC-BY-NC-4.0 (https://github.com/hkchengrex/MMAudio, "The
|
|
checkpoints are released on Hugging Face under the CC-BY-NC 4.0 license"), and
|
|
``mmaudio`` is ``non_commercial`` in routing.license_class, so paid work never
|
|
goes to it.
|
|
* ``stability-ai/stable-audio-2.5`` is Stability AI's official hosted model
|
|
(prompt, duration 1-190 s, steps 4-8, cfg_scale, seed); vendor key
|
|
``stability-ai`` is sellable under the Stability terms in license_class.
|
|
It is text-to-audio: the beat's prompt describes the sound, not the picture.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from app.domains.gateway import replicate_run
|
|
from app.domains.routing.license_class import assert_model_sellable
|
|
|
|
MODEL = "stability-ai/stable-audio-2.5"
|
|
MIN_S, MAX_S = 1, 30
|
|
NEGATIVE = "music, melody, singing, speech, voices"
|
|
|
|
|
|
class SfxError(RuntimeError):
|
|
pass
|
|
|
|
|
|
def is_enabled() -> bool:
|
|
return replicate_run.is_enabled()
|
|
|
|
|
|
def build_input(prompt: str, *, seconds: float, seed: int | None = None) -> dict:
|
|
text = " ".join(str(prompt or "").split())
|
|
if not text:
|
|
raise SfxError("describe the sound")
|
|
inp: dict[str, Any] = {
|
|
"prompt": f"{text[:400]}. Sound effect only, no {NEGATIVE}.",
|
|
"duration": max(MIN_S, min(MAX_S, int(round(float(seconds or MIN_S))))),
|
|
"steps": 8, "cfg_scale": 1,
|
|
}
|
|
if seed is not None:
|
|
inp["seed"] = int(seed)
|
|
return inp
|
|
|
|
|
|
def generate_sfx(prompt: str, *, seconds: float, out_path: str, video_url: str = "", image_url: str = "",
|
|
seed: int | None = None, session: Any = None) -> str:
|
|
"""One sound effect for a beat, saved to ``out_path``.
|
|
|
|
``video_url`` / ``image_url`` are accepted for parity with video-to-audio lanes;
|
|
Stable Audio is text-to-audio, so they are not sent (no non-commercial model is used).
|
|
"""
|
|
_ = (video_url, image_url)
|
|
assert_model_sellable(MODEL)
|
|
try:
|
|
url = replicate_run.run(MODEL, build_input(prompt, seconds=seconds, seed=seed), session=session)
|
|
replicate_run.download(url, out_path, session=session)
|
|
except SfxError:
|
|
raise
|
|
except Exception as exc: # noqa: BLE001 - one error type for the mixer
|
|
raise SfxError(f"the sound effect did not render: {exc}") from exc
|
|
return out_path
|
|
|
|
|
|
__all__ = ["MODEL", "SfxError", "build_input", "generate_sfx", "is_enabled"]
|