From eab211bb1e79fbda0b8eef00e44249993c040ae0 Mon Sep 17 00:00:00 2001 From: comfyanonymous Date: Mon, 24 Jun 2024 16:55:20 -0400 Subject: [PATCH] Resample audio to 44100 when VAE encoding it. --- comfy_extras/nodes_audio.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/comfy_extras/nodes_audio.py b/comfy_extras/nodes_audio.py index 5f4bd354..57d0a20a 100644 --- a/comfy_extras/nodes_audio.py +++ b/comfy_extras/nodes_audio.py @@ -31,7 +31,13 @@ class VAEEncodeAudio: CATEGORY = "_for_testing/audio" def encode(self, vae, audio): - t = vae.encode(audio["waveform"].movedim(1, -1)) + sample_rate = audio["sample_rate"] + if 44100 != sample_rate: + waveform = torchaudio.functional.resample(audio["waveform"], sample_rate, 44100) + else: + waveform = audio["waveform"] + + t = vae.encode(waveform.movedim(1, -1)) return ({"samples":t}, ) class VAEDecodeAudio: