Return exact audio frame count if num_frames above it
This commit is contained in:
+21
-3
@@ -91,8 +91,8 @@ class MultiTalkWav2VecEmbeds:
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("MULTITALK_EMBEDS", "AUDIO", )
|
||||
RETURN_NAMES = ("multitalk_embeds", "audio", )
|
||||
RETURN_TYPES = ("MULTITALK_EMBEDS", "AUDIO", "INT", )
|
||||
RETURN_NAMES = ("multitalk_embeds", "audio", "num_frames", )
|
||||
FUNCTION = "process"
|
||||
CATEGORY = "WanVideoWrapper"
|
||||
|
||||
@@ -231,12 +231,30 @@ class MultiTalkWav2VecEmbeds:
|
||||
offset += w.shape[-1]
|
||||
out_audio = {"waveform": mixed, "sample_rate": sr}
|
||||
|
||||
# Calculate actual frames based on audio duration
|
||||
actual_num_frames = num_frames
|
||||
if len(audio_outputs) > 0:
|
||||
if multi_audio_type == "para":
|
||||
# For parallel mode, use the longest audio duration
|
||||
max_audio_duration = max([ao["waveform"].shape[-1] / sr for ao in audio_outputs])
|
||||
actual_frames_from_audio = int(max_audio_duration * fps)
|
||||
else: # "add"
|
||||
# For sequential mode, use the total audio duration
|
||||
total_audio_duration = sum([ao["waveform"].shape[-1] / sr for ao in audio_outputs])
|
||||
actual_frames_from_audio = int(total_audio_duration * fps)
|
||||
|
||||
# Use the smaller of requested frames or actual audio frames
|
||||
actual_num_frames = min(num_frames, actual_frames_from_audio)
|
||||
|
||||
if actual_frames_from_audio < num_frames:
|
||||
log.info(f"[MultiTalk] Audio duration ({actual_frames_from_audio} frames) is shorter than requested ({num_frames} frames). Using {actual_num_frames} frames.")
|
||||
|
||||
# Debug: log final mixed audio length and mode
|
||||
total_samples_raw = sum([ao["waveform"].shape[-1] for ao in audio_outputs])
|
||||
log.info(f"[MultiTalk] total raw duration = {total_samples_raw/sr:.3f}s")
|
||||
log.info(f"[MultiTalk] multi_audio_type={multi_audio_type} | final waveform shape={out_audio['waveform'].shape} | length={out_audio['waveform'].shape[-1]} samples | seconds={out_audio['waveform'].shape[-1]/sr:.3f}s (expected {'sum' if multi_audio_type=='add' else 'max'} of raw)")
|
||||
|
||||
return (multitalk_embeds, out_audio)
|
||||
return (multitalk_embeds, out_audio, actual_num_frames)
|
||||
|
||||
|
||||
class WanVideoImageToVideoMultiTalk:
|
||||
|
||||
Reference in New Issue
Block a user