Last active
May 11, 2022 19:02
-
-
Save HudsonHuang/f527aa7d6155936d36408d8741d0908a to your computer and use it in GitHub Desktop.
wave file IO benchmark(soundfile and librosa)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## linux + HDD | |
# soundfile r: 111.3170223236084 | |
# soundfile w: 21.47102665901184 | |
# librosa r: 27.82967972755432 | |
# librosa w: 24.776712656021118 | |
## windows + SSD | |
# soundfile r: 12.918063640594482 | |
# soundfile w: 11.726674318313599 | |
# librosa r: 16.433390378952026 | |
# librosa w: 0.5162301063537598 | |
## linux(WHL) + SSD | |
# soundfile r: 14.984661340713501 | |
# soundfile w: 10.617738246917725 | |
# librosa r: 14.605595827102661 | |
# librosa w: 0.49469470977783203 | |
import librosa | |
import time | |
import soundfile | |
p = librosa.util.example_audio_file() | |
def check_read_speed(backend): | |
start = time.time() | |
for i in range(100): | |
if backend == "soundfile": | |
y, sr = soundfile.read(p) | |
else: | |
y, sr = librosa.load(p,sr=None) | |
print(backend, "r:", time.time() - start) | |
def check_write_speed(backend): | |
y, sr = librosa.load(p,sr=None) | |
start = time.time() | |
for i in range(100): | |
if backend == "soundfile": | |
soundfile.write("1.wav",y,sr) | |
else: | |
librosa.output.write_wav("1.wav",y,sr) | |
print(backend, "w:", time.time() - start) | |
for a in ["soundfile","librosa"]: | |
check_read_speed(a) | |
check_write_speed(a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you specify a sample rate other than None to librosa (even if it's the native SR of the audio), speeds seem to be comparabe (MacOS, SSD)
Using humpback recording and sr=22050:
soundfile r: 3.250004768371582 librosa r: 3.225004196166992