PreviewAudio node.
This commit is contained in:
parent
c39cf7fff0
commit
fbb7a1f1b6
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue