mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-08-14 10:30:05 +08:00
Change duration to Float (allows sub seconds)
This commit is contained in:
parent
95383513e2
commit
4905fb93d5
@ -371,8 +371,8 @@ class TrimAudioDuration:
|
|||||||
return {
|
return {
|
||||||
"required": {
|
"required": {
|
||||||
"audio": ("AUDIO",),
|
"audio": ("AUDIO",),
|
||||||
"start_index": ("INT", {"default": 0, "min": -0xffffffffffffffff, "max": 0xffffffffffffffff, "tooltip": "Start time in seconds, can be negative to count from the end."}),
|
"start_index": ("FLOAT", {"default": 0.0, "min": -0xffffffffffffffff, "max": 0xffffffffffffffff, "step": 0.01, "tooltip": "Start time in seconds, can be negative to count from the end (supports sub-seconds)."}),
|
||||||
"duration": ("INT", {"default": 60, "tooltip": "Duration in seconds."}),
|
"duration": ("FLOAT", {"default": 60.0, "min": 0.0, "step": 0.01, "tooltip": "Duration in seconds"}),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,12 +387,12 @@ class TrimAudioDuration:
|
|||||||
audio_length = waveform.shape[-1]
|
audio_length = waveform.shape[-1]
|
||||||
|
|
||||||
if start_index < 0:
|
if start_index < 0:
|
||||||
start_frame = audio_length + start_index * sample_rate
|
start_frame = audio_length + int(round(start_index * sample_rate))
|
||||||
else:
|
else:
|
||||||
start_frame = start_index * sample_rate
|
start_frame = int(round(start_index * sample_rate))
|
||||||
start_frame = max(0, min(start_frame, audio_length - 1))
|
start_frame = max(0, min(start_frame, audio_length - 1))
|
||||||
|
|
||||||
end_frame = start_frame + duration * sample_rate
|
end_frame = start_frame + int(round(duration * sample_rate))
|
||||||
end_frame = max(0, min(end_frame, audio_length))
|
end_frame = max(0, min(end_frame, audio_length))
|
||||||
|
|
||||||
if start_frame >= end_frame:
|
if start_frame >= end_frame:
|
||||||
@ -560,7 +560,7 @@ class EmptyAudio:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(s):
|
def INPUT_TYPES(s):
|
||||||
return {"required": {
|
return {"required": {
|
||||||
"duration": ("INT", {"default": 60, "min": 0, "max": 0xffffffffffffffff, "tooltip": "Duration of the empty audio clip in seconds."}),
|
"duration": ("FLOAT", {"default": 60.0, "min": 0.0, "max": 0xffffffffffffffff, "step": 0.01, "tooltip": "Duration of the empty audio clip in seconds"}),
|
||||||
"sample_rate": ("INT", {"default": 44100, "tooltip": "Sample rate of the empty audio clip."}),
|
"sample_rate": ("INT", {"default": 44100, "tooltip": "Sample rate of the empty audio clip."}),
|
||||||
"channels": ("INT", {"default": 2, "min": 1, "max": 2, "tooltip": "Number of audio channels (1 for mono, 2 for stereo)."}),
|
"channels": ("INT", {"default": 2, "min": 1, "max": 2, "tooltip": "Number of audio channels (1 for mono, 2 for stereo)."}),
|
||||||
}}
|
}}
|
||||||
@ -570,7 +570,8 @@ class EmptyAudio:
|
|||||||
CATEGORY = "audio"
|
CATEGORY = "audio"
|
||||||
|
|
||||||
def create_empty_audio(self, duration, sample_rate, channels):
|
def create_empty_audio(self, duration, sample_rate, channels):
|
||||||
waveform = torch.zeros((1, channels, duration * sample_rate), dtype=torch.float32)
|
num_samples = int(round(duration * sample_rate))
|
||||||
|
waveform = torch.zeros((1, channels, num_samples), dtype=torch.float32)
|
||||||
return ({"waveform": waveform, "sample_rate": sample_rate},)
|
return ({"waveform": waveform, "sample_rate": sample_rate},)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user