diff --git a/batdetect2/utils/audio_utils.py b/batdetect2/utils/audio_utils.py index 77ba5f5..a31397c 100644 --- a/batdetect2/utils/audio_utils.py +++ b/batdetect2/utils/audio_utils.py @@ -9,6 +9,7 @@ import torch import audioread import os import soundfile as sf +import io from batdetect2.detector import parameters @@ -147,7 +148,10 @@ def generate_spectrogram( def get_samplerate( path: Union[ str, int, os.PathLike[Any], sf.SoundFile, audioread.AudioFile, BinaryIO - ]): + ]): + if isinstance(path, (BinaryIO, io.BytesIO)): + path.seek(0) + with sf.SoundFile(path) as f: return f.samplerate