Skip to content

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

_ui.py import torchaudio safety check (#9234)

Jedrzej Kosinski42974a448c39
diff --git a/comfy_api/latest/_ui.py b/comfy_api/latest/_ui.py
index 6b8a39d58..61597038f 100644
--- a/comfy_api/latest/_ui.py
+++ b/comfy_api/latest/_ui.py
@@ -9,7 +9,11 @@ from typing import Type
import av
import numpy as np
import torch
-import torchaudio
+try:
+ import torchaudio
+ TORCH_AUDIO_AVAILABLE = True
+except ImportError:
+ TORCH_AUDIO_AVAILABLE = False
from PIL import Image as PILImage
from PIL.PngImagePlugin import PngInfo
@@ -302,6 +306,8 @@ class AudioSaveHelper:
# Resample if necessary
if sample_rate != audio["sample_rate"]:
+ if not TORCH_AUDIO_AVAILABLE:
+ raise Exception("torchaudio is not available; cannot resample audio.")
waveform = torchaudio.functional.resample(waveform, audio["sample_rate"], sample_rate)
# Create output with specified format