Use audio_open(path, backends=None) to open an audio file. If backends is not provided, the function automatically attempts to use all available backends on your system.
To improve performance when opening many files, call available_backends() once and pass the resulting list to subsequent audio_open() calls to avoid repeated backend discovery costs.
import audioread
# Automatically try all available backends
with audioread.audio_open('example.mp3') as f:
print(f.filesize)
# Optimized approach for multiple files
backends = audioread.available_backends()
for path in ['file1.mp3', 'file2.wav', 'file3.m4a']:
try:
with audioread.audio_open(path, backends=backends) as f:
# process file
pass
except audioread.NoBackendError:
print(f"Could not decode {path}")