ComfyUI AudioCraft: OUTPUT_NODE Fix, API Support, HuggingFace Cache
- OUTPUT_NODE = True fuer MusicGen und AudioGen (ComfyUI API funktioniert jetzt) - generate_via_api.py: Audio direkt ueber ComfyUI REST API generieren - docker-compose.yml: hf_cache Volume fuer persistente Modelle nach Neustart - Menü Musik und alle Krieger Attacken-Sounds generiert Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
f3c895ac43
commit
458be01cde
3 changed files with 89 additions and 0 deletions
|
|
@ -20,6 +20,7 @@ class MusicGenNode:
|
|||
RETURN_NAMES = ("audio_file",)
|
||||
FUNCTION = "generate"
|
||||
CATEGORY = "AudioCraft"
|
||||
OUTPUT_NODE = True
|
||||
|
||||
def generate(self, prompt, duration, model, seed):
|
||||
from audiocraft.models import MusicGen
|
||||
|
|
@ -58,6 +59,7 @@ class AudioGenNode:
|
|||
RETURN_NAMES = ("audio_file",)
|
||||
FUNCTION = "generate"
|
||||
CATEGORY = "AudioCraft"
|
||||
OUTPUT_NODE = True
|
||||
|
||||
def generate(self, prompt, duration, seed):
|
||||
from audiocraft.models import AudioGen
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ services:
|
|||
- ./output:/app/ComfyUI/output
|
||||
- ./input:/app/ComfyUI/input
|
||||
- ./custom_nodes:/app/ComfyUI/custom_nodes
|
||||
- ./hf_cache:/root/.cache/huggingface
|
||||
environment:
|
||||
- NVIDIA_VISIBLE_DEVICES=all
|
||||
deploy:
|
||||
|
|
|
|||
86
comfyui-audio/generate_via_api.py
Normal file
86
comfyui-audio/generate_via_api.py
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
"""
|
||||
Game Audio Generator via ComfyUI API
|
||||
Aufruf: python generate_via_api.py
|
||||
Voraussetzung: ComfyUI Container läuft auf localhost:8188
|
||||
"""
|
||||
import json
|
||||
import requests
|
||||
import time
|
||||
import urllib.request
|
||||
import os
|
||||
|
||||
COMFY_URL = "http://localhost:8188"
|
||||
OUTPUT_DIR = os.path.join(os.path.dirname(__file__), "output", "audio")
|
||||
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
||||
|
||||
TRACKS = [
|
||||
# (typ, prompt, dauer, dateiname)
|
||||
("music", "dark fantasy main menu music, epic orchestral, dramatic, mysterious, dark medieval atmosphere, slow build, no vocals", 40, "menu_music"),
|
||||
("sfx", "fast sword swing whoosh attack sound effect", 1, "attack_autoattack"),
|
||||
("sfx", "heavy powerful sword strike crushing impact metal clang", 2, "attack_heavy_strike"),
|
||||
("sfx", "massive ground slam earthquake shockwave stone cracking impact", 2, "attack_tektonischer_schlag"),
|
||||
("sfx", "warrior battle cry rage grunt determination short", 2, "attack_durchbeissen"),
|
||||
("sfx", "blade slash wet blood hit dark melee attack", 2, "attack_blutrausch"),
|
||||
("sfx", "fast spinning whirlwind sword multiple swings whoosh", 2, "attack_wirbelwind"),
|
||||
("sfx", "chains rattling metal binding restraint whoosh throw", 2, "attack_zornfesseln"),
|
||||
("sfx", "berserker rage roar battle fury intense warrior scream", 3, "attack_berserker"),
|
||||
]
|
||||
|
||||
def build_prompt(typ, prompt_text, duration, filename):
|
||||
node_type = "MusicGen" if typ == "music" else "AudioGen"
|
||||
widgets = [prompt_text, duration, "facebook/musicgen-small", 0] if typ == "music" else [prompt_text, duration, 0]
|
||||
return {
|
||||
"prompt": {
|
||||
"1": {
|
||||
"class_type": node_type,
|
||||
"inputs": {
|
||||
"prompt": prompt_text,
|
||||
"duration": duration,
|
||||
**({"model": "facebook/musicgen-small", "seed": 0} if typ == "music" else {"seed": 0})
|
||||
}
|
||||
}
|
||||
},
|
||||
"extra_data": {"extra_pnginfo": {"filename_hint": filename}}
|
||||
}
|
||||
|
||||
def queue_prompt(payload):
|
||||
r = requests.post(f"{COMFY_URL}/api/prompt", json=payload)
|
||||
r.raise_for_status()
|
||||
return r.json()["prompt_id"]
|
||||
|
||||
def wait_for_completion(prompt_id, timeout=300):
|
||||
start = time.time()
|
||||
while time.time() - start < timeout:
|
||||
r = requests.get(f"{COMFY_URL}/api/history/{prompt_id}")
|
||||
data = r.json()
|
||||
if prompt_id in data:
|
||||
return data[prompt_id]
|
||||
time.sleep(2)
|
||||
raise TimeoutError(f"Timeout nach {timeout}s")
|
||||
|
||||
def get_output_files():
|
||||
r = requests.get(f"{COMFY_URL}/api/history")
|
||||
return r.json()
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"Verbinde mit ComfyUI: {COMFY_URL}")
|
||||
try:
|
||||
requests.get(f"{COMFY_URL}/api/system_stats").raise_for_status()
|
||||
print("ComfyUI erreichbar\n")
|
||||
except Exception as e:
|
||||
print(f"ComfyUI nicht erreichbar: {e}")
|
||||
exit(1)
|
||||
|
||||
for typ, prompt, duration, filename in TRACKS:
|
||||
print(f"[{typ.upper()}] {filename}: {prompt[:55]}...")
|
||||
payload = build_prompt(typ, prompt, duration, filename)
|
||||
try:
|
||||
prompt_id = queue_prompt(payload)
|
||||
print(f" queued: {prompt_id}")
|
||||
result = wait_for_completion(prompt_id)
|
||||
print(f" fertig!")
|
||||
except Exception as e:
|
||||
print(f" Fehler: {e}")
|
||||
|
||||
print(f"\nAlle Jobs abgeschickt. Output unter: {OUTPUT_DIR}")
|
||||
print(f"Oder direkt in ComfyUI unter output/audio/")
|
||||
Loading…
Add table
Reference in a new issue