Skip to content

Commit ade8315

Browse files
committed
Release v0.3.3: navigation progress, reload saved audio, simplify load path
Made-with: Cursor
1 parent c8d4df6 commit ade8315

3 files changed

Lines changed: 64 additions & 6 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "helvox"
7-
version = "0.3.2"
7+
version = "0.3.3"
88
description = "A simple recording tool for Swiss German speech data."
99
readme = "README.md"
1010
requires-python = ">=3.10"

src/helvox/app.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,12 @@ def _apply_sample_fields(self) -> None:
626626
self._thumb_choice = "up"
627627
self._sync_thumb_buttons()
628628

629+
self.recorder.load_saved_clip_for_sample(id_str)
630+
if self.recorder.full_audio is None:
631+
self.clear_waveform_canvas()
632+
else:
633+
self.update_waveform()
634+
629635
self.update_progress()
630636
self.update_navigation_controls()
631637

@@ -655,12 +661,27 @@ def show_done_state(self) -> None:
655661

656662
def update_progress(self) -> None:
657663
total_count = len(self.recorder.input_data)
658-
done_count = len(self.recorder.output_data) + len(self.recorder.skipped_ids)
659-
done_count = min(done_count, total_count)
660-
self.progress_text.set(f"Progress: {done_count} / {total_count}")
664+
if total_count == 0:
665+
self.progress_text.set("Progress: 0 / 0")
666+
self.progress_bar["maximum"] = 1
667+
self.progress_bar["value"] = 0
668+
return
661669

662-
self.progress_bar["maximum"] = max(total_count, 1)
663-
self.progress_bar["value"] = done_count
670+
if self.current_id is not None:
671+
ids_ordered = [str(s["id"]) for s in self.recorder.input_data]
672+
try:
673+
line_no = ids_ordered.index(str(self.current_id)) + 1
674+
except ValueError:
675+
line_no = 0
676+
self.progress_text.set(f"Line {line_no} / {total_count}")
677+
self.progress_bar["maximum"] = total_count
678+
self.progress_bar["value"] = line_no
679+
else:
680+
done_count = len(self.recorder.output_data) + len(self.recorder.skipped_ids)
681+
done_count = min(done_count, total_count)
682+
self.progress_text.set(f"Progress: {done_count} / {total_count}")
683+
self.progress_bar["maximum"] = max(total_count, 1)
684+
self.progress_bar["value"] = done_count
664685

665686
def update_navigation_controls(self) -> None:
666687
has_current = self.current_id is not None

src/helvox/utils/recorder.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ def start_recording(self):
134134

135135
self.recording = True
136136
self.audio_data = []
137+
self.full_audio = None
138+
self.trimmed_audio = None
137139

138140
def callback(indata: np.ndarray, frames, time, status: CallbackFlags):
139141
if status:
@@ -182,6 +184,41 @@ def save_audio(self, filename: str) -> float:
182184

183185
return self.get_duration_trimmed_audio()
184186

187+
def load_saved_clip_for_sample(self, sample_id: Union[int, str]) -> None:
188+
"""Load trimmed FLAC from disk when this line was saved; else clear buffers."""
189+
id_str = str(sample_id)
190+
self.audio_data = []
191+
192+
if id_str not in self.output_index:
193+
self.full_audio = None
194+
self.trimmed_audio = None
195+
return
196+
197+
audio_name = self.output_index[id_str].get("audio", "")
198+
if not audio_name:
199+
self.full_audio = None
200+
self.trimmed_audio = None
201+
return
202+
203+
path = self.output_folder / self.speaker_id / "audio" / Path(audio_name).name
204+
if not path.is_file():
205+
self.full_audio = None
206+
self.trimmed_audio = None
207+
return
208+
209+
try:
210+
data, _ = sf.read(str(path), always_2d=True, dtype="float32")
211+
except OSError:
212+
self.full_audio = None
213+
self.trimmed_audio = None
214+
return
215+
216+
if data.shape[1] > 1:
217+
data = np.mean(data, axis=1, keepdims=True)
218+
219+
self.trimmed_audio = np.ascontiguousarray(data)
220+
self.full_audio = self.trimmed_audio.copy()
221+
185222
def play_audio_data_full_audio(self):
186223
self.play_audio_data(self.full_audio)
187224

0 commit comments

Comments
 (0)