whisper to prompt travel

This commit is contained in:
RyanOnTheInside
2024-12-22 13:37:01 -05:00
parent 9c24327548
commit e6eb6d9f39
2 changed files with 43 additions and 0 deletions
+2
View File
@@ -278,6 +278,7 @@ from .nodes.preprocessors.pose import PoseInterpolator
from .nodes.doom.doom import Doom
from .nodes.misc.misc_nodes import WhisperToPromptTravel
HAS_ADVANCED_LIVE_PORTRAIT = os.path.exists(os.path.join(os.path.dirname(os.path.dirname(__file__)), "ComfyUI-AdvancedLivePortrait"))
@@ -304,6 +305,7 @@ NODE_CLASS_MAPPINGS = {
#"PoseInterpolator": PoseInterpolator,
"Doom": Doom,
"WhisperToPromptTravel": WhisperToPromptTravel,
"ManualFeaturePipe": ManualFeaturePipe,
"ManualFeatureFromPipe": ManualFeatureFromPipe,
+41
View File
@@ -0,0 +1,41 @@
import json
class WhisperToPromptTravel:
"""Converts Whisper alignment data to prompt travel format"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"segments_alignment": ("STRING", {"multiline": True}), # JSON string of segment alignments
"fps": ("FLOAT", {"default": 24.0, "min": 0.1, "max": 120.0}),
}
}
RETURN_TYPES = ("STRING",)
FUNCTION = "convert"
CATEGORY = "misc"
def convert(self, segments_alignment, fps):
import json
# Parse the alignment data
try:
segments = json.loads(segments_alignment)
except json.JSONDecodeError:
raise ValueError("Invalid segments_alignment JSON format")
# Create frame-to-prompt mapping
prompt_travel = {}
for segment in segments:
# Convert time to frame number
frame = int(segment["start"] * fps)
prompt_travel[str(frame)] = segment["value"]
# Convert to string format
result = "{\n"
for frame, prompt in sorted(prompt_travel.items(), key=lambda x: int(x[0])):
result += f'"{frame}":"{prompt}",\n'
result = result.rstrip(",\n") + "\n}"
return (result,)