Skip to content

Commit 42974a4

Browse files
authored
_ui.py import torchaudio safety check (Comfy-Org#9234)
* Added safety around torchaudio import in _ui.py * Trusted cursor too much, fixed torchaudio bool
1 parent 05df2df commit 42974a4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

comfy_api/latest/_ui.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
import av
1010
import numpy as np
1111
import torch
12-
import torchaudio
12+
try:
13+
import torchaudio
14+
TORCH_AUDIO_AVAILABLE = True
15+
except ImportError:
16+
TORCH_AUDIO_AVAILABLE = False
1317
from PIL import Image as PILImage
1418
from PIL.PngImagePlugin import PngInfo
1519

@@ -302,6 +306,8 @@ def save_audio(
302306

303307
# Resample if necessary
304308
if sample_rate != audio["sample_rate"]:
309+
if not TORCH_AUDIO_AVAILABLE:
310+
raise Exception("torchaudio is not available; cannot resample audio.")
305311
waveform = torchaudio.functional.resample(waveform, audio["sample_rate"], sample_rate)
306312

307313
# Create output with specified format

0 commit comments

Comments
 (0)