Skip to content

Commit 8a6e758

Browse files
committed
Fix serving a detection if it starts a 0 or at the end of the file
1 parent e233379 commit 8a6e758

6 files changed

Lines changed: 19 additions & 12 deletions

File tree

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,3 @@ diagnostics/
180180
.vscode/
181181
assets/birddata.zip
182182
sampling_scripts/
183-
# pixi environments
184-
.pixi/*
185-
!.pixi/config.toml

birdnet_validator/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,8 @@ def run(
8686
"--server.headless", "true",
8787
]
8888

89-
# Use DEVNULL/PIPE for std handles to avoid "invalid handle" errors
90-
# when launched from R/reticulate on Windows (all three handles can be
91-
# invalid in an embedded R session).
89+
# DEVNULL avoids "invalid handle" errors in environments where
90+
# standard handles may not exist (e.g. pythonw.exe, embedded interpreters).
9291
subprocess.run(
9392
cmd,
9493
env=env,

src/s3_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""S3 utilities for reading/writing files from S3 storage."""
22

3-
import io
43
from urllib.parse import urlparse
54

65
import boto3

src/selection_handlers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ def render_local_data_loader():
9595
st.sidebar.info(
9696
"📂 **Paths not configured yet.**\n\n"
9797
"Please provide your audio, results, and output directories.\n\n"
98-
"**Using Python/R?** Pass them to `run()` or `run_validator()`.\n\n"
99-
"**Using `.env` file?** Set `BIRDNET_AUDIO_DIR`, `BIRDNET_RESULTS_DIR`, and `BIRDNET_OUTPUT_DIR`.\n\n"
98+
"**Using Python?** Pass them to `run()`.\n\n"
99+
"**Using `.env` file?** Set `AUDIO_DIR`, `RESULTS_DIR`, and `OUTPUT_DIR`.\n\n"
100100
"🔄 *After updating paths, restart the app to apply changes.*"
101101
)
102102
return False

src/ui_components.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ def render_spectrogram(file_path, start_time, context_before=1, context_after=4,
138138

139139
def render_audio_player(clip):
140140
"""Render audio player widget."""
141+
if clip is None:
142+
st.warning("No audio available for this clip")
143+
return
141144
st.audio(clip, format="audio/wav", sample_rate=48000)
142145

143146

src/utils.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,18 @@ def extract_clip(file_path, start_time, context_before=1, context_after=4, sr=48
9696
else:
9797
audio_data, _ = librosa.load(file_path, sr=sr, mono=True)
9898

99-
start_sample = max(0, int((start_time - context_before) * sr))
100-
end_sample = int((start_time + context_after) * sr)
101-
return audio_data[start_sample:end_sample]
99+
duration = len(audio_data) / sr
100+
clip_start = max(0.0, start_time - context_before)
101+
clip_end = min(duration, start_time + context_after)
102+
103+
start_sample = int(clip_start * sr)
104+
end_sample = int(clip_end * sr)
105+
106+
clip = audio_data[start_sample:end_sample]
107+
if len(clip) < sr // 10: # less than 0.1s — too short
108+
st.warning("Audio clip too short at this position")
109+
return None
110+
return clip
102111
except Exception as e:
103112
st.error(f"Error loading audio file: {e}")
104113
return None

0 commit comments

Comments
 (0)