ComfyScript
ComfyScript copied to clipboard
How to get value from the output of a node and perform math or other operations
Hello! I have this code here
async def extend_audio(params: AudioWorkflow):
async with Workflow(wait=True) as wf:
model, model_sr = MusicgenLoader()
audio, sr, duration = LoadAudio(params.snd_filename)
audio = ConvertAudio(audio, sr, model_sr, 1)
audio = ClipAudio(audio, duration - 10.0, duration, model_sr) # I would like to perform this math
raw_audio = MusicgenGenerate(model, audio, 4, duration + params.duration, params.cfg, params.top_k, params.top_p, params.temperature, params.seed or random.randint(0, 2**32 - 1))
audio = ClipAudio(audio, 0.0, duration - 10.0, model_sr)
audio = ConcatAudio(audio, raw_audio)
spectrogram_image = SpectrogramImage(audio, 1024, 256, 1024, 0.4)
spectrogram_image = ImageResize(spectrogram_image, ImageResize.mode.resize, True, ImageResize.resampling.lanczos, 2, 512, 128)
video = CombineImageWithAudio(spectrogram_image, audio, model_sr, CombineImageWithAudio.file_format.webm, "final_output")
await wf.queue()._wait()
results = await video._wait()
return await get_data(results)
And I would like to perform math on the resulting duration from LoadAudio. If I try to use it raw, it will just throw the error TypeError: unsupported operand type(s) for -: 'Float' and 'float'
Is it possible to get the result here?