diff --git a/comfy_extras/nodes_audio.py b/comfy_extras/nodes_audio.py index 6481ed3ba83..9950d58ed00 100644 --- a/comfy_extras/nodes_audio.py +++ b/comfy_extras/nodes_audio.py @@ -6,6 +6,7 @@ import io import json import struct +import random from comfy.cli_args import args class EmptyLatentAudio: @@ -118,7 +119,6 @@ def __init__(self): self.output_dir = folder_paths.get_output_directory() self.type = "output" self.prefix_append = "" - self.compress_level = 4 @classmethod def INPUT_TYPES(s): @@ -168,6 +168,19 @@ def save_audio(self, audio, filename_prefix="ComfyUI", prompt=None, extra_pnginf return { "ui": { "audio": results } } +class PreviewAudio(SaveAudio): + def __init__(self): + self.output_dir = folder_paths.get_temp_directory() + self.type = "temp" + self.prefix_append = "_temp_" + ''.join(random.choice("abcdefghijklmnopqrstupvxyz") for x in range(5)) + + @classmethod + def INPUT_TYPES(s): + return {"required": + {"audio": ("AUDIO", ), }, + "hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"}, + } + class LoadAudio: SUPPORTED_FORMATS = ('.wav', '.mp3', '.ogg', '.flac', '.aiff', '.aif') @@ -214,4 +227,5 @@ def VALIDATE_INPUTS(s, audio): "VAEDecodeAudio": VAEDecodeAudio, "SaveAudio": SaveAudio, "LoadAudio": LoadAudio, + "PreviewAudio": PreviewAudio, } diff --git a/web/extensions/core/uploadAudio.js b/web/extensions/core/uploadAudio.js index 12a2a196b49..0ac9cb807f0 100644 --- a/web/extensions/core/uploadAudio.js +++ b/web/extensions/core/uploadAudio.js @@ -70,7 +70,7 @@ async function uploadFile( app.registerExtension({ name: "Comfy.AudioWidget", async beforeRegisterNodeDef(nodeType, nodeData) { - if (["LoadAudio", "SaveAudio"].includes(nodeType.comfyClass)) { + if (["LoadAudio", "SaveAudio", "PreviewAudio"].includes(nodeType.comfyClass)) { nodeData.input.required.audioUI = ["AUDIO_UI"] } }, @@ -103,7 +103,7 @@ app.registerExtension({ if (!audios) return const audio = audios[0] audioUIWidget.element.src = api.apiURL( - getResourceURL(audio.subfolder, audio.filename, "output") + getResourceURL(audio.subfolder, audio.filename, audio.type) ) audioUIWidget.element.classList.remove("empty-audio-widget") } @@ -118,7 +118,7 @@ app.registerExtension({ if ("audio" in output) { const audioUIWidget = node.widgets.find((w) => w.name === "audioUI"); const audio = output.audio[0]; - audioUIWidget.element.src = api.apiURL(getResourceURL(audio.subfolder, audio.filename, "output")); + audioUIWidget.element.src = api.apiURL(getResourceURL(audio.subfolder, audio.filename, audio.type)); audioUIWidget.element.classList.remove("empty-audio-widget"); } }