Added support for inputs.audios

This commit is contained in:
Sirshendu Ganguly
2026-04-09 05:02:30 +05:30
parent adc08004c3
commit bf19a2370d
3 changed files with 84 additions and 1 deletions
+56
View File
@@ -10,6 +10,8 @@ const CACHE_SIZE_RANGE = { min: 30, default: 150, max: 4096 };
/** Must match `audioInferenceInputs.MAX_VIDEOS` in modules/audioInferenceInputs.py */
const AUDIO_INFERENCE_INPUTS_MAX_VIDEOS = 4;
/** Must match `audioInferenceInputs.MAX_AUDIOS` in modules/audioInferenceInputs.py */
const AUDIO_INFERENCE_INPUTS_MAX_AUDIOS = 4;
let openDialog = false;
let lastTimeout = false;
@@ -4407,6 +4409,7 @@ function audioInferenceInputsToggleHandler(audioInputsNode) {
const useVideoWidget = audioInputsNode.widgets.find(w => w && w.name === "useVideo");
const videoWidget = audioInputsNode.widgets.find(w => w && w.name === "Video");
const useVideosWidget = audioInputsNode.widgets.find(w => w && w.name === "useVideos");
const useAudiosWidget = audioInputsNode.widgets.find(w => w && w.name === "useAudios");
// Helper function to toggle widget enabled state
function toggleWidgetState(useWidget, paramWidget, paramName) {
@@ -4460,6 +4463,59 @@ function audioInferenceInputsToggleHandler(audioInputsNode) {
toggleWidgetState(useVideoWidget, videoWidget, "Video");
}
// Set up toggle handlers for multiple audios (Audio1 … AudioN; N from widgets, fallback to AUDIO_INFERENCE_INPUTS_MAX_AUDIOS)
if (useAudiosWidget) {
function getAudioInferenceAudioSlotCount() {
let max = 0;
for (const w of audioInputsNode.widgets) {
if (!w?.name) continue;
const m = /^Audio(\d+)$/.exec(w.name);
if (m) max = Math.max(max, parseInt(m[1], 10));
}
return max > 0 ? max : AUDIO_INFERENCE_INPUTS_MAX_AUDIOS;
}
function toggleAudiosEnabled() {
const enabled = useAudiosWidget.value === true;
const slotCount = getAudioInferenceAudioSlotCount();
for (let i = 1; i <= slotCount; i++) {
const audioSlotWidget = audioInputsNode.widgets.find(w => w && w.name === `Audio${i}`);
if (audioSlotWidget) {
if (audioSlotWidget.inputEl) {
audioSlotWidget.inputEl.disabled = !enabled;
audioSlotWidget.inputEl.style.opacity = enabled ? "1" : "0.5";
audioSlotWidget.inputEl.style.cursor = enabled ? "text" : "not-allowed";
audioSlotWidget.inputEl.readOnly = !enabled;
}
audioSlotWidget.disabled = !enabled;
if (!audioSlotWidget.inputEl) {
const nodeElement = audioInputsNode.htmlElements?.widgetsContainer || audioInputsNode.htmlElements;
if (nodeElement) {
const input = nodeElement.querySelector(`input[name="Audio${i}"], textarea[name="Audio${i}"], select[name="Audio${i}"]`);
if (input) {
input.disabled = !enabled;
input.style.opacity = enabled ? "1" : "0.5";
input.style.cursor = enabled ? "text" : "not-allowed";
input.readOnly = !enabled;
}
}
}
}
}
audioInputsNode.setDirtyCanvas(true);
}
appendWidgetCB(useAudiosWidget, () => {
setTimeout(toggleAudiosEnabled, 50);
});
setTimeout(toggleAudiosEnabled, 100);
}
// Set up toggle handlers for multiple videos (Video1 … VideoN; N from widgets, fallback to AUDIO_INFERENCE_INPUTS_MAX_VIDEOS)
if (useVideosWidget) {
function getAudioInferenceVideoSlotCount() {
+27 -1
View File
@@ -6,6 +6,7 @@ class audioInferenceInputs:
"""Audio Inference Inputs node for configuring audio generation inputs"""
MAX_VIDEOS = 4
MAX_AUDIOS = 4
@classmethod
def INPUT_TYPES(cls):
@@ -40,12 +41,24 @@ class audioInferenceInputs:
"default": "",
})
# Multiple audios last so the UI groups useAudios with Audio1…Audio4 (ComfyUI order = dict insertion order)
optionalInputs["useAudios"] = ("BOOLEAN", {
"tooltip": "Enable to include multiple audio inputs in API request (inputs.audios array).",
"default": False,
})
for i in range(1, cls.MAX_AUDIOS + 1):
ordinal = rwUtils.getOrdinal(i)
optionalInputs[f"Audio{i}"] = ("STRING", {
"tooltip": f"Audio URL or mediaUUID for the {ordinal} audio. Only used when 'Use Audios' is enabled.",
"default": "",
})
return {
"required": {},
"optional": optionalInputs
}
DESCRIPTION = "Configure custom inputs for Runware Audio Inference, including optional audio URL/mediaUUID, and single or multiple video inputs for audio extraction or generation."
DESCRIPTION = "Configure custom inputs for Runware Audio Inference, including optional single or multiple audio URL/mediaUUID (inputs.audio or inputs.audios), and single or multiple video inputs for audio extraction or generation."
FUNCTION = "createInputs"
RETURN_TYPES = ("RUNWAREAUDIOINFERENCEINPUTS",)
RETURN_NAMES = ("Audio Inference Inputs",)
@@ -55,6 +68,7 @@ class audioInferenceInputs:
"""Create audio inference inputs from provided parameters"""
useAudio = kwargs.get("useAudio", False)
audio = kwargs.get("Audio", None)
useAudios = kwargs.get("useAudios", False)
useVideo = kwargs.get("useVideo", False)
video = kwargs.get("Video", None)
useVideos = kwargs.get("useVideos", False)
@@ -65,6 +79,18 @@ class audioInferenceInputs:
if useAudio and audio is not None and audio.strip() != "":
inputs["audio"] = audio.strip()
# Handle multiple audios (inputs.audios as array)
if useAudios:
audioList = []
for i in range(1, self.MAX_AUDIOS + 1):
audioKey = f"Audio{i}"
audioUrl = kwargs.get(audioKey)
if audioUrl and audioUrl.strip() != "":
audioList.append(audioUrl.strip())
if len(audioList) > 0:
inputs["audios"] = audioList
# Handle single video (inputs.video)
if useVideo and video is not None and video.strip() != "":
inputs["video"] = video.strip()
File diff suppressed because one or more lines are too long