diff --git a/docs/benchmark.rst b/docs/benchmark.rst index 369b546d..19c3593c 100644 --- a/docs/benchmark.rst +++ b/docs/benchmark.rst @@ -34,6 +34,7 @@ The following Python packages are benchmarked against each other: * audioread_ 2.1.9 * :mod:`audiofile` 1.1.0 * librosa_ 0.9.1 +* pedalboard_ 0.5.3 * scipy_ 1.8.0 * soundfile_ 0.10.3.post1 * sox_ 1.4.1 @@ -126,7 +127,7 @@ Reading files soundfile_ does not support reading MP3 and MP4 files, -audioread_ (mad) only MP3 files. +audioread_ (mad) and pedalboard_ only MP3 files. .. image:: ./benchmark/results/benchmark_mp3-mp4_read.png @@ -135,7 +136,7 @@ Accessing metadata soundfile_ does not support accessing MP3 and MP4 metadata. -sox_ and audioread_ (mad) only for MP3 files. +sox_, audioread_ (mad) and pedalboard_ only for MP3 files. .. image:: ./benchmark/results/benchmark_mp3-mp4_info.png @@ -158,6 +159,7 @@ in the figure. .. _gstreamer: https://gstreamer.freedesktop.org/ .. _librosa: https://github.com/librosa/librosa/ .. _mad: https://sourceforge.net/projects/mad/ +.. _pedalboard: https://github.com/spotify/pedalboard .. _scipy: https://docs.scipy.org/doc/scipy/reference/generated/scipy.io.wavfile.read.html .. _soundfile: https://github.com/bastibe/SoundFile/ .. _sox: https://github.com/rabitt/pysox/ diff --git a/docs/benchmark/benchmark_info.py b/docs/benchmark/benchmark_info.py index ba117422..c3e0793b 100644 --- a/docs/benchmark/benchmark_info.py +++ b/docs/benchmark/benchmark_info.py @@ -60,6 +60,7 @@ def __len__(self): 'aubio', 'audiofile', 'audiofile_sloppy', + 'pedalboard', 'soundfile', 'sox', ] @@ -68,13 +69,18 @@ def __len__(self): print(f"Benchmark metadata {args.ext} with {lib}") for root, dirs, fnames in sorted(os.walk('AUDIO')): for audio_dir in dirs: + # MP4 and MP3 is not supported by all libraries - if lib in ['soundfile', 'sox'] and args.ext == 'mp4': + if ( + lib in ['soundfile', 'sox', 'pedalboard'] + and args.ext == 'mp4' + ): continue if lib in ['soundfile'] and args.ext == 'mp3': continue if lib == 'ar_mad' and args.ext != 'mp3': continue + duration = int(audio_dir) dataset = AudioFolder( os.path.join(root, audio_dir), diff --git a/docs/benchmark/benchmark_read.py b/docs/benchmark/benchmark_read.py index ab880784..8cec446e 100644 --- a/docs/benchmark/benchmark_read.py +++ b/docs/benchmark/benchmark_read.py @@ -66,6 +66,7 @@ def __len__(self): 'aubio', 'audiofile', 'librosa', + 'pedalboard', 'scipy', 'soundfile', ] @@ -82,6 +83,8 @@ def __len__(self): continue if lib == 'soundfile' and args.ext in ['mp3', 'mp4']: continue + if lib == 'pedalboard' and args.ext == 'mp4': + continue duration = int(audio_dir) dataset = AudioFolder( diff --git a/docs/benchmark/loaders.py b/docs/benchmark/loaders.py index 264a9e8e..ecf5b4c8 100644 --- a/docs/benchmark/loaders.py +++ b/docs/benchmark/loaders.py @@ -1,13 +1,14 @@ -from scipy.io import wavfile +import aubio +import audiofile as af import audioread.rawread import audioread.gstdec import audioread.maddec import audioread.ffdec +import pedalboard import soundfile as sf -import audiofile as af -import aubio import numpy as np import librosa +from scipy.io import wavfile import sox """ @@ -90,6 +91,12 @@ def load_audiofile(fp): return sig +def load_pedalboard(fp): + with pedalboard.io.AudioFile(fp) as f: + # Pedalboard output is (num_channels, num_samples) + return f.read(f.frames)[0] + + def _convert_buffer_to_float(buf, n_bytes=2, dtype=np.float32): # taken from librosa.util.utils # Invert the scale of the data @@ -187,3 +194,16 @@ def info_audiofile_sloppy(fp): info['channels'] = af.channels info['sampling_rate'] = af.sampling_rate return info + + +def info_pedalboard(fp): + info = {} + with pedalboard.io.AudioFile(fp) as af: + info["duration"] = af.duration + with pedalboard.io.AudioFile(fp) as af: + info["samples"] = af.frames + with pedalboard.io.AudioFile(fp) as af: + info["channels"] = af.num_channels + with pedalboard.io.AudioFile(fp) as af: + info["sampling_rate"] = af.samplerate + return info diff --git a/docs/benchmark/plot.py b/docs/benchmark/plot.py index f7cb4fc5..ec73909b 100644 --- a/docs/benchmark/plot.py +++ b/docs/benchmark/plot.py @@ -12,6 +12,7 @@ 'ar_ffmpeg': 'audioread (ffmpeg)', 'ar_mad': 'audioread (mad)', 'librosa': 'librosa', + 'pedalboard': 'pedalboard', 'scipy': 'scipy', 'soundfile': 'soundfile', 'sox': 'sox', @@ -44,6 +45,7 @@ MAPPINGS['aubio'], MAPPINGS['librosa'], MAPPINGS['ar_ffmpeg'], + MAPPINGS['pedalboard'], MAPPINGS['scipy'], ] height = 5.6 @@ -53,16 +55,18 @@ MAPPINGS['audiofile'], MAPPINGS['soundfile'], MAPPINGS['aubio'], + MAPPINGS['pedalboard'], ] height = 3.36 aspect = 2.0 elif 'mp3' in exts and package == 'read': lib_order = [ MAPPINGS['audiofile'], - MAPPINGS['librosa'], MAPPINGS['aubio'], + MAPPINGS['librosa'], MAPPINGS['ar_ffmpeg'], MAPPINGS['ar_mad'], + MAPPINGS['pedalboard'], ] height = 3.36 aspect = 2.0 @@ -73,6 +77,7 @@ MAPPINGS['aubio'], MAPPINGS['ar_ffmpeg'], MAPPINGS['ar_mad'], + MAPPINGS['pedalboard'], MAPPINGS['sox'], ] height = 3.7 @@ -91,6 +96,7 @@ MAPPINGS['ar_mad']: '#94785e', MAPPINGS['ar_ffmpeg']: '#94785e', MAPPINGS['sox']: '#db8cc5', + MAPPINGS['pedalboard']: '#cdbb75', } g = sns.catplot( diff --git a/docs/benchmark/requirements.txt b/docs/benchmark/requirements.txt index 84e75f2d..f9927d1c 100644 --- a/docs/benchmark/requirements.txt +++ b/docs/benchmark/requirements.txt @@ -3,6 +3,7 @@ audiofile audioread librosa pandas +pedalboard ==0.5.3 pygobject pymad scipy diff --git a/docs/benchmark/requirements.txt.lock b/docs/benchmark/requirements.txt.lock index f892e40d..9f5682d3 100644 --- a/docs/benchmark/requirements.txt.lock +++ b/docs/benchmark/requirements.txt.lock @@ -56,6 +56,7 @@ numpy==1.21.6 # matplotlib # numba # pandas + # pedalboard # resampy # scikit-learn # scipy @@ -70,6 +71,8 @@ pandas==1.4.2 # via # -r requirements.txt # seaborn +pedalboard==0.5.3 + # via -r requirements.txt pillow==9.1.0 # via matplotlib pooch==1.6.0 diff --git a/docs/benchmark/results/benchmark_info_flac.pickle b/docs/benchmark/results/benchmark_info_flac.pickle index 8b1eab12..6eca8225 100644 Binary files a/docs/benchmark/results/benchmark_info_flac.pickle and b/docs/benchmark/results/benchmark_info_flac.pickle differ diff --git a/docs/benchmark/results/benchmark_info_mp3.pickle b/docs/benchmark/results/benchmark_info_mp3.pickle index b93b4029..7fc3c94d 100644 Binary files a/docs/benchmark/results/benchmark_info_mp3.pickle and b/docs/benchmark/results/benchmark_info_mp3.pickle differ diff --git a/docs/benchmark/results/benchmark_info_mp4.pickle b/docs/benchmark/results/benchmark_info_mp4.pickle index b1467346..9e64676c 100644 Binary files a/docs/benchmark/results/benchmark_info_mp4.pickle and b/docs/benchmark/results/benchmark_info_mp4.pickle differ diff --git a/docs/benchmark/results/benchmark_info_ogg.pickle b/docs/benchmark/results/benchmark_info_ogg.pickle index f2f449b8..7679d6d2 100644 Binary files a/docs/benchmark/results/benchmark_info_ogg.pickle and b/docs/benchmark/results/benchmark_info_ogg.pickle differ diff --git a/docs/benchmark/results/benchmark_info_wav.pickle b/docs/benchmark/results/benchmark_info_wav.pickle index 63d2b485..13c2a6e6 100644 Binary files a/docs/benchmark/results/benchmark_info_wav.pickle and b/docs/benchmark/results/benchmark_info_wav.pickle differ diff --git a/docs/benchmark/results/benchmark_mp3-mp4_info.png b/docs/benchmark/results/benchmark_mp3-mp4_info.png index dbed0042..89173d75 100644 Binary files a/docs/benchmark/results/benchmark_mp3-mp4_info.png and b/docs/benchmark/results/benchmark_mp3-mp4_info.png differ diff --git a/docs/benchmark/results/benchmark_mp3-mp4_read.png b/docs/benchmark/results/benchmark_mp3-mp4_read.png index 310284fd..46f66832 100644 Binary files a/docs/benchmark/results/benchmark_mp3-mp4_read.png and b/docs/benchmark/results/benchmark_mp3-mp4_read.png differ diff --git a/docs/benchmark/results/benchmark_read_flac.pickle b/docs/benchmark/results/benchmark_read_flac.pickle index 361ecde1..31c53195 100644 Binary files a/docs/benchmark/results/benchmark_read_flac.pickle and b/docs/benchmark/results/benchmark_read_flac.pickle differ diff --git a/docs/benchmark/results/benchmark_read_mp3.pickle b/docs/benchmark/results/benchmark_read_mp3.pickle index d22c2f98..785b7b42 100644 Binary files a/docs/benchmark/results/benchmark_read_mp3.pickle and b/docs/benchmark/results/benchmark_read_mp3.pickle differ diff --git a/docs/benchmark/results/benchmark_read_mp4.pickle b/docs/benchmark/results/benchmark_read_mp4.pickle index 21dddb02..6987c584 100644 Binary files a/docs/benchmark/results/benchmark_read_mp4.pickle and b/docs/benchmark/results/benchmark_read_mp4.pickle differ diff --git a/docs/benchmark/results/benchmark_read_ogg.pickle b/docs/benchmark/results/benchmark_read_ogg.pickle index cf3a9898..372e0df3 100644 Binary files a/docs/benchmark/results/benchmark_read_ogg.pickle and b/docs/benchmark/results/benchmark_read_ogg.pickle differ diff --git a/docs/benchmark/results/benchmark_read_wav.pickle b/docs/benchmark/results/benchmark_read_wav.pickle index 9f1b8efc..74850f3b 100644 Binary files a/docs/benchmark/results/benchmark_read_wav.pickle and b/docs/benchmark/results/benchmark_read_wav.pickle differ diff --git a/docs/benchmark/results/benchmark_wav-flac-ogg_info.png b/docs/benchmark/results/benchmark_wav-flac-ogg_info.png index 1d606ba3..b6e88a4c 100644 Binary files a/docs/benchmark/results/benchmark_wav-flac-ogg_info.png and b/docs/benchmark/results/benchmark_wav-flac-ogg_info.png differ diff --git a/docs/benchmark/results/benchmark_wav-flac-ogg_read.png b/docs/benchmark/results/benchmark_wav-flac-ogg_read.png index 48194b13..65c7b479 100644 Binary files a/docs/benchmark/results/benchmark_wav-flac-ogg_read.png and b/docs/benchmark/results/benchmark_wav-flac-ogg_read.png differ