"docs/vscode:/vscode.git/clone" did not exist on "15b1511a15dfb1d56048847da755213632c07b29"
Unverified Commit 18b1c772 authored by Yiyang "Ian" Liu's avatar Yiyang "Ian" Liu Committed by GitHub
Browse files

fix: handle ImportError in load_audio (#39473)


Signed-off-by: default avatarYiyang Liu <37043548+ianliuy@users.noreply.github.com>
Co-authored-by: default avatarCopilot <223556219+Copilot@users.noreply.github.com>
parent 1e4748c6
...@@ -9,11 +9,14 @@ import numpy.typing as npt ...@@ -9,11 +9,14 @@ import numpy.typing as npt
import pybase64 import pybase64
import torch import torch
from vllm.logger import init_logger
from vllm.utils.import_utils import PlaceholderModule from vllm.utils.import_utils import PlaceholderModule
from vllm.utils.serial_utils import tensor2base64 from vllm.utils.serial_utils import tensor2base64
from .base import MediaIO from .base import MediaIO
logger = init_logger(__name__)
try: try:
import av import av
except ImportError: except ImportError:
...@@ -139,6 +142,12 @@ def load_audio( ...@@ -139,6 +142,12 @@ def load_audio(
): ):
try: try:
return load_audio_soundfile(path, sr=sr, mono=mono) return load_audio_soundfile(path, sr=sr, mono=mono)
except ImportError as exc:
# soundfile (or resampy) is not installed — fall through to pyav.
# NOTE: this clause must stay BEFORE ``soundfile.LibsndfileError``
# because when soundfile is a PlaceholderModule, evaluating
# ``soundfile.LibsndfileError`` itself raises ImportError.
logger.error("Failed to load audio via soundfile: %r", exc)
except soundfile.LibsndfileError as exc: except soundfile.LibsndfileError as exc:
# Only fall back for known format-detection failures. # Only fall back for known format-detection failures.
# Re-raise anything else (e.g. corrupt but recognised format). # Re-raise anything else (e.g. corrupt but recognised format).
...@@ -150,6 +159,8 @@ def load_audio( ...@@ -150,6 +159,8 @@ def load_audio(
path.seek(0) path.seek(0)
try: try:
return load_audio_pyav(path, sr=sr, mono=mono) return load_audio_pyav(path, sr=sr, mono=mono)
except ImportError:
raise # Let PlaceholderModule's message ("install vllm[audio]") propagate.
except Exception as pyav_exc: except Exception as pyav_exc:
raise ValueError("Invalid or unsupported audio file.") from pyav_exc raise ValueError("Invalid or unsupported audio file.") from pyav_exc
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment