From 0191baf8f318d727f5e1f8359f8aa1495d232187 Mon Sep 17 00:00:00 2001 From: MuziekMagie Date: Thu, 17 Apr 2025 15:20:06 +0200 Subject: [PATCH] Add bit_depth option to SaveAudio for 16-bit/24-bit FLAC support --- comfy_extras/nodes_audio.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/comfy_extras/nodes_audio.py b/comfy_extras/nodes_audio.py index 136ad6159b8c..ed5ca9d8d31e 100644 --- a/comfy_extras/nodes_audio.py +++ b/comfy_extras/nodes_audio.py @@ -153,7 +153,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"}), + "bit_depth": ([16, 24], )}, "hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"}, } @@ -164,7 +165,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", bit_depth=16, 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[FileLocator] = [] @@ -182,7 +183,7 @@ def save_audio(self, audio, filename_prefix="ComfyUI", prompt=None, extra_pnginf file = f"{filename_with_batch_num}_{counter:05}_.flac" buff = io.BytesIO() - torchaudio.save(buff, waveform, audio["sample_rate"], format="FLAC") + torchaudio.save(buff, waveform, audio["sample_rate"], format="FLAC", bits_per_sample=bit_depth) buff = insert_or_replace_vorbis_comment(buff, metadata)