Upload edit\gen_audio.py with huggingface_hub
Browse files- edit//gen_audio.py +57 -0
edit//gen_audio.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Generate SFX (and music) via ElevenLabs. Reads key from video-use/.env."""
|
| 2 |
+
import json, os, sys, time
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
import requests
|
| 5 |
+
|
| 6 |
+
def load_key():
|
| 7 |
+
env = Path(r"C:\Users\palas\.claude\skills\video-use\.env")
|
| 8 |
+
for line in env.read_text().splitlines():
|
| 9 |
+
if line.startswith("ELEVENLABS_API_KEY"):
|
| 10 |
+
return line.split("=",1)[1].strip().strip('"').strip("'")
|
| 11 |
+
sys.exit("no key")
|
| 12 |
+
|
| 13 |
+
KEY = load_key()
|
| 14 |
+
H = {"xi-api-key": KEY}
|
| 15 |
+
|
| 16 |
+
def sfx(text, out, dur=None, influence=0.4):
|
| 17 |
+
if out.exists():
|
| 18 |
+
print(f" cached sfx: {out.name}"); return
|
| 19 |
+
body = {"text": text, "prompt_influence": influence}
|
| 20 |
+
if dur: body["duration_seconds"] = dur
|
| 21 |
+
r = requests.post("https://api.elevenlabs.io/v1/sound-generation",
|
| 22 |
+
headers=H, json=body, timeout=120)
|
| 23 |
+
if r.status_code != 200:
|
| 24 |
+
print(f" SFX FAIL {out.name}: {r.status_code} {r.text[:200]}"); return
|
| 25 |
+
out.write_bytes(r.content)
|
| 26 |
+
print(f" sfx -> {out.name} ({len(r.content)/1024:.0f} KB)")
|
| 27 |
+
|
| 28 |
+
def music(prompt, out, length_ms):
|
| 29 |
+
if out.exists():
|
| 30 |
+
print(f" cached music: {out.name}"); return
|
| 31 |
+
# Eleven Music API
|
| 32 |
+
body = {"prompt": prompt, "music_length_ms": length_ms}
|
| 33 |
+
r = requests.post("https://api.elevenlabs.io/v1/music",
|
| 34 |
+
headers=H, json=body, timeout=300)
|
| 35 |
+
if r.status_code != 200:
|
| 36 |
+
print(f" MUSIC FAIL {out.name}: {r.status_code} {r.text[:300]}"); return
|
| 37 |
+
out.write_bytes(r.content)
|
| 38 |
+
print(f" music -> {out.name} ({len(r.content)/1024:.0f} KB)")
|
| 39 |
+
|
| 40 |
+
SFX_DIR = Path(r"D:\PromptEngineer48\In-Progress\P11-Editor\edit\assets\sfx")
|
| 41 |
+
MUS_DIR = Path(r"D:\PromptEngineer48\In-Progress\P11-Editor\edit\assets\music")
|
| 42 |
+
SFX_DIR.mkdir(parents=True, exist_ok=True)
|
| 43 |
+
MUS_DIR.mkdir(parents=True, exist_ok=True)
|
| 44 |
+
|
| 45 |
+
if __name__ == "__main__":
|
| 46 |
+
mode = sys.argv[1] if len(sys.argv) > 1 else "sfx"
|
| 47 |
+
if mode in ("sfx","all"):
|
| 48 |
+
print("=== SFX ===")
|
| 49 |
+
sfx("fast clean cinematic whoosh transition swoosh, modern, crisp", SFX_DIR/"whoosh.mp3", dur=1.0)
|
| 50 |
+
sfx("deep punchy bass impact boom hit, cinematic trailer, short", SFX_DIR/"impact.mp3", dur=1.5)
|
| 51 |
+
sfx("short rising synth riser building tension, electronic, tech", SFX_DIR/"riser.mp3", dur=2.0)
|
| 52 |
+
sfx("subtle clean UI click pop, soft digital notification", SFX_DIR/"pop.mp3", dur=0.5)
|
| 53 |
+
sfx("bright positive notification chime ding, success, short", SFX_DIR/"ding.mp3", dur=0.8)
|
| 54 |
+
if mode in ("music","all"):
|
| 55 |
+
print("=== MUSIC ===")
|
| 56 |
+
music("Uplifting energetic electronic tech intro, driving beat, modern motivational, bright synths, instrumental, no vocals, loopable",
|
| 57 |
+
MUS_DIR/"intro.mp3", 33000)
|