feat: add external audio node based on VHS node

This commit is contained in:
bennykok 2025-02-07 21:42:44 +08:00
parent ce939fbe1b
commit 3d6a554f7f
2 changed files with 99 additions and 0 deletions

View File

@ -0,0 +1,96 @@
import os
def get_vhs_load_audio():
try:
vhs_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'ComfyUI-VideoHelperSuite'))
print(vhs_path)
# Add the VHS directory to sys.path temporarily
import sys
sys.path.insert(0, vhs_path)
# Import the module using the package path
from videohelpersuite.nodes import LoadAudio
# Remove the temporary path
sys.path.pop(0)
print("LoadAudio from VHS: ", LoadAudio)
return LoadAudio
except Exception as e:
print(f"Failed to load VideoHelperSuite LoadAudio: {str(e)}")
return None
VHSLoadAudio = get_vhs_load_audio()
if VHSLoadAudio:
class ComfyUIDeployExternalAudio(VHSLoadAudio):
RETURN_TYPES = ("AUDIO",)
# RETURN_NAMES = ("audio",)
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"input_id": (
"STRING",
{"multiline": False, "default": "input_audio"},
),
"audio_file": ("STRING", {"default": ""}),
},
"optional": {
"default_value": ("AUDIO",),
"display_name": (
"STRING",
{"multiline": False, "default": ""},
),
"description": (
"STRING",
{"multiline": False, "default": ""},
),
}
}
@classmethod
def VALIDATE_INPUTS(s, audio_file, **kwargs):
return True
def load_audio(self, input_id, audio_file, default_value=None, display_name=None, description=None):
# Use audio_file for loading audio, ignoring input_id for actual loading
# , start_time=0.0, duration=0.0
if audio_file and audio_file != "":
return super().load_audio(audio_file, seek_seconds=0.0)
else:
return (default_value, )
else:
class ComfyUIDeployExternalAudio:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"input_id": (
"STRING",
{"multiline": False, "default": "input_audio"},
),
},
"optional": {
"default_value": ("AUDIO",),
"display_name": (
"STRING",
{"multiline": False, "default": ""},
),
"description": (
"STRING",
{"multiline": False, "default": ""},
),
}
}
RETURN_TYPES = ("AUDIO",)
RETURN_NAMES = ("audio",)
FUNCTION = "load_audio"
def load_audio(self, input_id, default_value=None, display_name=None, description=None):
raise NotImplementedError("VideoHelperSuite is required for audio loading functionality")
NODE_CLASS_MAPPINGS = {"ComfyUIDeployExternalAudio": ComfyUIDeployExternalAudio}
NODE_DISPLAY_NAME_MAPPINGS = {"ComfyUIDeployExternalAudio": "External Audio (ComfyUI Deploy)"}

View File

@ -386,6 +386,9 @@ def apply_inputs_to_workflow(workflow_api: Any, inputs: Any, sid: str = None):
if value["class_type"] == "ComfyUIDeployExternalFaceModel": if value["class_type"] == "ComfyUIDeployExternalFaceModel":
value["inputs"]["face_model_url"] = new_value value["inputs"]["face_model_url"] = new_value
if value["class_type"] == "ComfyUIDeployExternalAudio":
value["inputs"]["audio_file"] = new_value
def send_prompt(sid: str, inputs: StreamingPrompt): def send_prompt(sid: str, inputs: StreamingPrompt):
# workflow_api = inputs.workflow_api # workflow_api = inputs.workflow_api