Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions comfy_extras/nodes_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ def __init__(self):

@classmethod
def INPUT_TYPES(s):
return {"required": {"seconds": ("FLOAT", {"default": 47.6, "min": 1.0, "max": 1000.0, "step": 0.1})}}
return {"required": {"seconds": ("FLOAT", {"default": 47.6, "min": 1.0, "max": 1000.0, "step": 0.1}), "batch_size": ("INT", {"default": 1, "min": 1, "max": 16, "step": 1})}}
RETURN_TYPES = ("LATENT",)
FUNCTION = "generate"

CATEGORY = "latent/audio"

def generate(self, seconds):
batch_size = 1
def generate(self, seconds, batch_size):
length = round((seconds * 44100 / 2048) / 2) * 2
latent = torch.zeros([batch_size, 64, length], device=self.device)
return ({"samples":latent, "type": "audio"}, )
Expand Down Expand Up @@ -124,7 +123,8 @@ def __init__(self):
@classmethod
def INPUT_TYPES(s):
return {"required": { "audio": ("AUDIO", ),
"filename_prefix": ("STRING", {"default": "audio/ComfyUI"})},
"filename_prefix": ("STRING", {"default": "audio/ComfyUI"}),
"file_format": (["wav", "flac"],{"default": "flac"})},
"hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"},
}

Expand All @@ -135,7 +135,7 @@ def INPUT_TYPES(s):

CATEGORY = "audio"

def save_audio(self, audio, filename_prefix="ComfyUI", prompt=None, extra_pnginfo=None):
def save_audio(self, audio, filename_prefix="ComfyUI", file_format="flac", prompt=None, extra_pnginfo=None):
filename_prefix += self.prefix_append
full_output_folder, filename, counter, subfolder, filename_prefix = folder_paths.get_save_image_path(filename_prefix, self.output_dir)
results = list()
Expand All @@ -150,12 +150,13 @@ def save_audio(self, audio, filename_prefix="ComfyUI", prompt=None, extra_pnginf

for (batch_number, waveform) in enumerate(audio["waveform"].cpu()):
filename_with_batch_num = filename.replace("%batch_num%", str(batch_number))
file = f"{filename_with_batch_num}_{counter:05}_.flac"
file = f"{filename_with_batch_num}_{counter:05}_.{file_format}"

buff = io.BytesIO()
torchaudio.save(buff, waveform, audio["sample_rate"], format="FLAC")
torchaudio.save(buff, waveform, audio["sample_rate"], format=file_format)

buff = insert_or_replace_vorbis_comment(buff, metadata)
if (file_format == "flac"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python code shouldn't have () parens here

buff = insert_or_replace_vorbis_comment(buff, metadata)

with open(os.path.join(full_output_folder, file), 'wb') as f:
f.write(buff.getbuffer())
Expand Down