Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/datasets/features/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,16 +295,22 @@ def _decode_mp3(self, path_or_file):
try: # try torchaudio anyway because sometimes it works (depending on the os and os packages installed)
array, sampling_rate = self._decode_mp3_torchaudio(path_or_file)
except RuntimeError:
warnings.warn(
"\nTo support 'mp3' decoding with `torchaudio>=0.12.0`, please install `ffmpeg4` system package. On Google Colab you can run:\n\n"
"\t!add-apt-repository -y ppa:jonathonf/ffmpeg-4 && apt update && apt install -y ffmpeg\n\n"
"and restart your runtime. Alternatively, you can downgrade `torchaudio`:\n\n"
"\tpip install \"torchaudio<0.12\"`.\n\nOtherwise 'mp3' files will be decoded with `librosa`."
)
try:
# flake8: noqa
import librosa
except ImportError as err:
raise ImportError(
"Your version of `torchaudio` (>=0.12.0) doesn't support decoding 'mp3' files on your machine. "
"To support 'mp3' decoding with `torchaudio>=0.12.0`, please install `ffmpeg>=4` system package "
'or downgrade `torchaudio` to <0.12: `pip install "torchaudio<0.12"`. '
"To support decoding 'mp3' audio files without `torchaudio`, please install `librosa`: "
"`pip install librosa`. Note that decoding will be extremely slow in that case."
"To support 'mp3' decoding with `torchaudio>=0.12.0`, please install `ffmpeg4` system package. On Google Colab you can run:\n\n"
"\t!add-apt-repository -y ppa:jonathonf/ffmpeg-4 && apt update && apt install -y ffmpeg\n\n"
"and restart your runtime. Alternatively, you can downgrade `torchaudio`:\n\n"
"\tpip install \"torchaudio<0.12\"`.\n\nOtherwise 'mp3' files will be decoded with `librosa`:\n\n"
"\tpip install librosa\n\nNote that decoding will be extremely slow in that case."
) from err
# try to decode with librosa for torchaudio>=0.12.0 as a workaround
warnings.warn("Decoding mp3 with `librosa` instead of `torchaudio`, decoding is slow.")
Expand Down