From e10e270de49e81daed463ec7d8713e97d2bdeefe Mon Sep 17 00:00:00 2001 From: Kavi Date: Wed, 26 Feb 2025 14:12:09 +0100 Subject: [PATCH] Fix error in get_samplerate when reading io.BytesIO. --- batdetect2/utils/audio_utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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