From da7f966d7852e4370f951a9a74265246e73e59a5 Mon Sep 17 00:00:00 2001 From: Joe Weiss Date: Wed, 24 Apr 2024 11:47:00 -0400 Subject: [PATCH] Fix issue with librosa.load (#114) * Add ability to handle length too small error from librosa * Bump for 0.17.2 --- pyproject.toml | 2 +- src/birdnetlib/utils.py | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 4cc3252..9a6c076 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ exclude = [ [project] name = "birdnetlib" -version = "0.17.1" +version = "0.17.2" authors = [ { name="Joe Weiss", email="joe.weiss@gmail.com" }, ] diff --git a/src/birdnetlib/utils.py b/src/birdnetlib/utils.py index 0853c82..bbd744e 100644 --- a/src/birdnetlib/utils.py +++ b/src/birdnetlib/utils.py @@ -30,14 +30,18 @@ def read_audio_segments( start_sample = 0 while True: - audio_chunk, _ = librosa.load( - file_path, - sr=sr, - mono=True, - offset=start_sample / sr, - duration=chunk_duration, - res_type="kaiser_fast", - ) + try: + audio_chunk, _ = librosa.load( + file_path, + sr=sr, + mono=True, + offset=start_sample / sr, + duration=chunk_duration, + res_type="kaiser_fast", + ) + except ValueError: + # Specifically to catch "ValueError: Input signal length=0 is too small to resample" + break # Check if the chunk is empty, indicating the end of the file if not audio_chunk.any():