From fbb7a1f1b663b170d49718590aa1cb4093586f20 Mon Sep 17 00:00:00 2001 From: comfyanonymous Date: Sat, 29 Jun 2024 01:33:22 -0400 Subject: [PATCH] PreviewAudio node. --- comfy_extras/nodes_audio.py | 16 +++++++++++++++- web/extensions/core/uploadAudio.js | 6 +++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/comfy_extras/nodes_audio.py b/comfy_extras/nodes_audio.py index 6481ed3b..9950d58e 100644 --- a/comfy_extras/nodes_audio.py +++ b/comfy_extras/nodes_audio.py @@ -6,6 +6,7 @@ import os import io import json import struct +import random from comfy.cli_args import args class EmptyLatentAudio: @@ -118,7 +119,6 @@ class SaveAudio: 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 @@ class SaveAudio: 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 @@ NODE_CLASS_MAPPINGS = { "VAEDecodeAudio": VAEDecodeAudio, "SaveAudio": SaveAudio, "LoadAudio": LoadAudio, + "PreviewAudio": PreviewAudio, } diff --git a/web/extensions/core/uploadAudio.js b/web/extensions/core/uploadAudio.js index 12a2a196..0ac9cb80 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"); } }