diff --git a/README.md b/README.md index 063d8f4..708cd1b 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,8 @@ python install.py The nodes can be found in "TangoFlux" category as `TangoFluxLoader`, `TangoFluxSampler`, `TangoFluxVAEDecodeAndPlay`. +The `audio` output of the `TangoFluxVAEDecodeAndPlay` can be used as audio input for the[ComfyUI-VideoHelperSuite](https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite) `VideoCombine` node. ***(This will not sync audio to the video)*** + ![teacache_options](https://github.com/user-attachments/assets/29e676d9-902b-4ea2-9f72-18d3607996e8) > [TeaCache](https://github.com/LiewFeng/TeaCache) can speedup TangoFlux 2x without much audio quality degradation, in a training-free manner. diff --git a/nodes.py b/nodes.py index d469ecb..6e4c90b 100644 --- a/nodes.py +++ b/nodes.py @@ -5,6 +5,8 @@ import random import torch import torchaudio import re +import subprocess +import shutil from diffusers import AutoencoderOobleck, FluxTransformer2DModel @@ -226,7 +228,8 @@ class TangoFluxVAEDecodeAndPlay: }, } - RETURN_TYPES = () + RETURN_TYPES = ("AUDIO",) + RETURN_NAMES = ("audio",) OUTPUT_NODE = True CATEGORY = "TangoFlux" @@ -279,6 +282,38 @@ class TangoFluxVAEDecodeAndPlay: torch.cuda.empty_cache() log.warning("OOM encountered. Falling back to tiled decoding.") return self.decode_tiled(vae, latents, tile_size) + + def load_audio_for_vhs(self, file, sample_rate): + try: + from imageio_ffmpeg import get_ffmpeg_exe + ffmpeg_path = get_ffmpeg_exe() + except: + pass + + ffmpeg_path = shutil.which("ffmpeg") + if not ffmpeg_path: + if os.path.isfile("ffmpeg"): + ffmpeg_path = os.path.abspath("ffmpeg") + elif os.path.isfile("ffmpeg.exe"): + ffmpeg_path = os.path.abspath("ffmpeg.exe") + + if not ffmpeg_path: + log.error("No valid ffmpeg found") + return None + + args = [ffmpeg_path, "-i", file] + + try: + res = subprocess.run(args + ["-f", "f32le", "-"], + capture_output=True, check=True) + audio = torch.frombuffer(bytearray(res.stdout), dtype=torch.float32) + except subprocess.CalledProcessError: + log.error("Couldn't export audio") + return None + + audio = audio.reshape((-1, 2)).transpose(0, 1).unsqueeze(0) + + return {"waveform": audio, "sample_rate": sample_rate} def play( self, @@ -339,9 +374,13 @@ class TangoFluxVAEDecodeAndPlay: audios.append({"filename": file, "subfolder": subfolder, "type": type}) pbar.update(1) + + first_file = os.path.join(full_output_folder, audios[0]["filename"]) + audio_for_vhs = self.load_audio_for_vhs(first_file, 44100) return { "ui": {"audios": audios}, + "result": (audio_for_vhs,) } diff --git a/pyproject.toml b/pyproject.toml index 320d614..d60a12f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "comfyui-tangoflux" description = "ComfyUI Custom Nodes for 'TangoFlux: Super Fast and Faithful Text to Audio Generation with Flow Matching'. This generates high-quality 44.1kHz audio up to 30 seconds using just a text prompt." -version = "1.1.1" +version = "1.2.0" license = {file = "LICENSE"} dependencies = ["torchaudio", "diffusers", "accelerate", "tqdm"]