Add ComfyUI AudioCraft custom nodes und Game Audio Workflow
- comfyui_audiocraft: eigene MusicGen + AudioGen Nodes - workflow_game_audio.json: vorgefertigter Workflow fuer Dungeon Musik und Sound Effects Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
cc3b2ed942
commit
f3c895ac43
3 changed files with 197 additions and 0 deletions
3
comfyui-audio/comfyui_audiocraft/__init__.py
Normal file
3
comfyui-audio/comfyui_audiocraft/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
from .nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
|
||||
|
||||
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"]
|
||||
92
comfyui-audio/comfyui_audiocraft/nodes.py
Normal file
92
comfyui-audio/comfyui_audiocraft/nodes.py
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
import torch
|
||||
import torchaudio
|
||||
import os
|
||||
import time
|
||||
|
||||
|
||||
class MusicGenNode:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"prompt": ("STRING", {"multiline": True, "default": "dark dungeon ambience, slow, mysterious"}),
|
||||
"duration": ("FLOAT", {"default": 10.0, "min": 1.0, "max": 60.0, "step": 1.0}),
|
||||
"model": (["facebook/musicgen-small", "facebook/musicgen-medium", "facebook/musicgen-large", "facebook/musicgen-stereo-medium"],),
|
||||
"seed": ("INT", {"default": 0, "min": 0, "max": 2**32 - 1}),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("AUDIO_PATH",)
|
||||
RETURN_NAMES = ("audio_file",)
|
||||
FUNCTION = "generate"
|
||||
CATEGORY = "AudioCraft"
|
||||
|
||||
def generate(self, prompt, duration, model, seed):
|
||||
from audiocraft.models import MusicGen
|
||||
from audiocraft.data.audio import audio_write
|
||||
|
||||
torch.manual_seed(seed)
|
||||
|
||||
print(f"[MusicGen] Loading model: {model}")
|
||||
mg = MusicGen.get_pretrained(model)
|
||||
mg.set_generation_params(duration=duration)
|
||||
|
||||
print(f"[MusicGen] Generating: {prompt}")
|
||||
wav = mg.generate([prompt])
|
||||
|
||||
output_dir = "/app/ComfyUI/output/audio"
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
filename = f"musicgen_{int(time.time())}"
|
||||
out_path = os.path.join(output_dir, filename)
|
||||
audio_write(out_path, wav[0].cpu(), mg.sample_rate, strategy="loudness")
|
||||
|
||||
return (out_path + ".wav",)
|
||||
|
||||
|
||||
class AudioGenNode:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"prompt": ("STRING", {"multiline": True, "default": "sword clash metal sound effect"}),
|
||||
"duration": ("FLOAT", {"default": 3.0, "min": 0.5, "max": 30.0, "step": 0.5}),
|
||||
"seed": ("INT", {"default": 0, "min": 0, "max": 2**32 - 1}),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("AUDIO_PATH",)
|
||||
RETURN_NAMES = ("audio_file",)
|
||||
FUNCTION = "generate"
|
||||
CATEGORY = "AudioCraft"
|
||||
|
||||
def generate(self, prompt, duration, seed):
|
||||
from audiocraft.models import AudioGen
|
||||
from audiocraft.data.audio import audio_write
|
||||
|
||||
torch.manual_seed(seed)
|
||||
|
||||
print(f"[AudioGen] Loading model...")
|
||||
ag = AudioGen.get_pretrained("facebook/audiogen-medium")
|
||||
ag.set_generation_params(duration=duration)
|
||||
|
||||
print(f"[AudioGen] Generating: {prompt}")
|
||||
wav = ag.generate([prompt])
|
||||
|
||||
output_dir = "/app/ComfyUI/output/audio"
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
filename = f"audiogen_{int(time.time())}"
|
||||
out_path = os.path.join(output_dir, filename)
|
||||
audio_write(out_path, wav[0].cpu(), ag.sample_rate, strategy="loudness")
|
||||
|
||||
return (out_path + ".wav",)
|
||||
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"MusicGen": MusicGenNode,
|
||||
"AudioGen": AudioGenNode,
|
||||
}
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"MusicGen": "MusicGen (Musik)",
|
||||
"AudioGen": "AudioGen (Sound Effects)",
|
||||
}
|
||||
102
comfyui-audio/workflow_game_audio.json
Normal file
102
comfyui-audio/workflow_game_audio.json
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
{
|
||||
"last_node_id": 4,
|
||||
"last_link_id": 0,
|
||||
"nodes": [
|
||||
{
|
||||
"id": 1,
|
||||
"type": "MusicGen",
|
||||
"pos": [100, 100],
|
||||
"size": {"0": 400, "1": 200},
|
||||
"flags": {},
|
||||
"order": 0,
|
||||
"mode": 0,
|
||||
"inputs": [],
|
||||
"outputs": [
|
||||
{"name": "audio_file", "type": "AUDIO_PATH", "links": [], "slot_index": 0}
|
||||
],
|
||||
"properties": {"Node name for S&R": "MusicGen"},
|
||||
"widgets_values": [
|
||||
"dark dungeon ambience, slow, mysterious, atmospheric, medieval",
|
||||
10.0,
|
||||
"facebook/musicgen-small",
|
||||
0
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"type": "MusicGen",
|
||||
"pos": [100, 380],
|
||||
"size": {"0": 400, "1": 200},
|
||||
"flags": {},
|
||||
"order": 1,
|
||||
"mode": 0,
|
||||
"inputs": [],
|
||||
"outputs": [
|
||||
{"name": "audio_file", "type": "AUDIO_PATH", "links": [], "slot_index": 0}
|
||||
],
|
||||
"properties": {"Node name for S&R": "MusicGen"},
|
||||
"widgets_values": [
|
||||
"epic battle music, drums, dark fantasy, intense, orchestral",
|
||||
15.0,
|
||||
"facebook/musicgen-small",
|
||||
42
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"type": "AudioGen",
|
||||
"pos": [100, 660],
|
||||
"size": {"0": 400, "1": 160},
|
||||
"flags": {},
|
||||
"order": 2,
|
||||
"mode": 0,
|
||||
"inputs": [],
|
||||
"outputs": [
|
||||
{"name": "audio_file", "type": "AUDIO_PATH", "links": [], "slot_index": 0}
|
||||
],
|
||||
"properties": {"Node name for S&R": "AudioGen"},
|
||||
"widgets_values": [
|
||||
"sword slash metal clang sound effect",
|
||||
3.0,
|
||||
0
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"type": "AudioGen",
|
||||
"pos": [100, 880],
|
||||
"size": {"0": 400, "1": 160},
|
||||
"flags": {},
|
||||
"order": 3,
|
||||
"mode": 0,
|
||||
"inputs": [],
|
||||
"outputs": [
|
||||
{"name": "audio_file", "type": "AUDIO_PATH", "links": [], "slot_index": 0}
|
||||
],
|
||||
"properties": {"Node name for S&R": "AudioGen"},
|
||||
"widgets_values": [
|
||||
"footsteps on stone dungeon floor",
|
||||
3.0,
|
||||
1
|
||||
]
|
||||
}
|
||||
],
|
||||
"links": [],
|
||||
"groups": [
|
||||
{
|
||||
"title": "Musik",
|
||||
"bounding": [80, 75, 440, 480],
|
||||
"color": "#8B0000",
|
||||
"font_size": 14
|
||||
},
|
||||
{
|
||||
"title": "Sound Effects",
|
||||
"bounding": [80, 635, 440, 430],
|
||||
"color": "#1a3a4a",
|
||||
"font_size": 14
|
||||
}
|
||||
],
|
||||
"config": {},
|
||||
"extra": {},
|
||||
"version": 0.4
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue