Skip to content

Commit

Permalink
PreviewAudio node.
Browse files Browse the repository at this point in the history
  • Loading branch information
comfyanonymous committed Jun 29, 2024
1 parent c39cf7f commit fbb7a1f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
16 changes: 15 additions & 1 deletion comfy_extras/nodes_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io
import json
import struct
import random
from comfy.cli_args import args

class EmptyLatentAudio:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -214,4 +227,5 @@ def VALIDATE_INPUTS(s, audio):
"VAEDecodeAudio": VAEDecodeAudio,
"SaveAudio": SaveAudio,
"LoadAudio": LoadAudio,
"PreviewAudio": PreviewAudio,
}
6 changes: 3 additions & 3 deletions web/extensions/core/uploadAudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
},
Expand Down Expand Up @@ -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")
}
Expand All @@ -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");
}
}
Expand Down

0 comments on commit fbb7a1f

Please sign in to comment.