PreviewAudio node.
This commit is contained in:
parent
c39cf7fff0
commit
fbb7a1f1b6
|
@ -6,6 +6,7 @@ import os
|
||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
import struct
|
import struct
|
||||||
|
import random
|
||||||
from comfy.cli_args import args
|
from comfy.cli_args import args
|
||||||
|
|
||||||
class EmptyLatentAudio:
|
class EmptyLatentAudio:
|
||||||
|
@ -118,7 +119,6 @@ class SaveAudio:
|
||||||
self.output_dir = folder_paths.get_output_directory()
|
self.output_dir = folder_paths.get_output_directory()
|
||||||
self.type = "output"
|
self.type = "output"
|
||||||
self.prefix_append = ""
|
self.prefix_append = ""
|
||||||
self.compress_level = 4
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(s):
|
def INPUT_TYPES(s):
|
||||||
|
@ -168,6 +168,19 @@ class SaveAudio:
|
||||||
|
|
||||||
return { "ui": { "audio": results } }
|
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:
|
class LoadAudio:
|
||||||
SUPPORTED_FORMATS = ('.wav', '.mp3', '.ogg', '.flac', '.aiff', '.aif')
|
SUPPORTED_FORMATS = ('.wav', '.mp3', '.ogg', '.flac', '.aiff', '.aif')
|
||||||
|
|
||||||
|
@ -214,4 +227,5 @@ NODE_CLASS_MAPPINGS = {
|
||||||
"VAEDecodeAudio": VAEDecodeAudio,
|
"VAEDecodeAudio": VAEDecodeAudio,
|
||||||
"SaveAudio": SaveAudio,
|
"SaveAudio": SaveAudio,
|
||||||
"LoadAudio": LoadAudio,
|
"LoadAudio": LoadAudio,
|
||||||
|
"PreviewAudio": PreviewAudio,
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ async function uploadFile(
|
||||||
app.registerExtension({
|
app.registerExtension({
|
||||||
name: "Comfy.AudioWidget",
|
name: "Comfy.AudioWidget",
|
||||||
async beforeRegisterNodeDef(nodeType, nodeData) {
|
async beforeRegisterNodeDef(nodeType, nodeData) {
|
||||||
if (["LoadAudio", "SaveAudio"].includes(nodeType.comfyClass)) {
|
if (["LoadAudio", "SaveAudio", "PreviewAudio"].includes(nodeType.comfyClass)) {
|
||||||
nodeData.input.required.audioUI = ["AUDIO_UI"]
|
nodeData.input.required.audioUI = ["AUDIO_UI"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -103,7 +103,7 @@ app.registerExtension({
|
||||||
if (!audios) return
|
if (!audios) return
|
||||||
const audio = audios[0]
|
const audio = audios[0]
|
||||||
audioUIWidget.element.src = api.apiURL(
|
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")
|
audioUIWidget.element.classList.remove("empty-audio-widget")
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ app.registerExtension({
|
||||||
if ("audio" in output) {
|
if ("audio" in output) {
|
||||||
const audioUIWidget = node.widgets.find((w) => w.name === "audioUI");
|
const audioUIWidget = node.widgets.find((w) => w.name === "audioUI");
|
||||||
const audio = output.audio[0];
|
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");
|
audioUIWidget.element.classList.remove("empty-audio-widget");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue