32 lines
1.3 KiB
Python
32 lines
1.3 KiB
Python
"""
|
|||
|
|
Stable Audio 3 Small-SFX CLI: generate a sound effect/ambience clip from a
|
||
|
|
text description. Runs on CPU by design - this checkpoint is the
|
||
|
|
"lightweight, no GPU required" model in Stable Audio 3's lineup, so it
|
||
|
|
never contends with ComfyUI/other models for VRAM (unlike generate_sfx.py's
|
||
|
|
MOSS-SoundEffect, which needs the 3090 and ComfyUI's memory freed first).
|
||
|
|
"""
|
||
|
|
|
||
|
|
import argparse
|
||
|
|
|
||
|
|
import torchaudio
|
||
|
|
from stable_audio_3 import StableAudioModel
|
||
|
|
|
||
|
|
|
||
|
|
def main() -> None:
|
||
|
|
parser = argparse.ArgumentParser(description="Stable Audio 3 Small-SFX text-to-sound-effect")
|
||
|
|
parser.add_argument("--text", required=True, help="Description of the sound effect/ambience")
|
||
|
|
parser.add_argument("--output", required=True, help="Output wav path")
|
||
|
|
parser.add_argument("--duration", type=float, default=10.0, help="Clip duration in seconds (max 120)")
|
||
|
|
parser.add_argument("--seed", type=int, default=-1, help="Random seed, or -1 for random")
|
||
|
|
args = parser.parse_args()
|
||
|
|
|
||
|
|
model = StableAudioModel.from_pretrained("small-sfx", device="cpu")
|
||
|
|
sample_rate = model.model.sample_rate
|
||
|
|
|
||
|
|
audio = model.generate(prompt=args.text, duration=args.duration, seed=args.seed)
|
||
|
|
torchaudio.save(args.output, audio[0].cpu(), sample_rate)
|
||
|
|
print(f"[INFO] Saved {args.output}")
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|