Skip to content

Commit

Permalink
Fix issue with librosa.load (#114)
Browse files Browse the repository at this point in the history
* Add ability to handle length too small error from librosa

* Bump for 0.17.2
  • Loading branch information
joeweiss authored Apr 24, 2024
1 parent aec4385 commit da7f966
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exclude = [

[project]
name = "birdnetlib"
version = "0.17.1"
version = "0.17.2"
authors = [
{ name="Joe Weiss", email="[email protected]" },
]
Expand Down
20 changes: 12 additions & 8 deletions src/birdnetlib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit da7f966

Please sign in to comment.