diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..974a890 --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ +# Python +__pycache__/ +*.py[cod] +*$py.class +*.so +.Python + +# Distribution / packaging +dist/ +build/ +*.egg-info/ + +# Testing +.pytest_cache/ +.coverage +htmlcov/ + +# IDEs +.vscode/ +.idea/ +*.swp +*.swo +*~ diff --git a/wsds/ws_audio.py b/wsds/ws_audio.py index 650ae9d..ba9d2e7 100644 --- a/wsds/ws_audio.py +++ b/wsds/ws_audio.py @@ -1,11 +1,14 @@ from __future__ import annotations import io +import logging import typing from dataclasses import dataclass import pyarrow as pa +logger = logging.getLogger(__name__) + def to_filelike(src: typing.Any) -> typing.BinaryIO: """Coerces files, byte-strings and PyArrow binary buffers into file-like objects.""" @@ -127,7 +130,8 @@ def get_reader(self, sample_rate=None): if self.reader is None or sample_rate_switch: try: from torchcodec.decoders import AudioDecoder - except Exception: + except (ImportError, OSError, RuntimeError) as e: + logger.warning("Failed to import torchcodec AudioDecoder, falling back to torchaudio: %s", e) AudioDecoder = CompatAudioDecoder reader = AudioDecoder(to_filelike(self.src), sample_rate=sample_rate)