[loop-generated] [refactor] Break up _record_utterance() — 73 lines in voice_loop.py #570

Closed
opened 2026-03-20 01:25:51 +00:00 by Timmy · 1 comment
Owner

File: src/timmy/voice_loop.py
Function: _record_utterance() — 73 lines (line 146)

This method handles silence detection, audio buffering, and VAD in one block. Extract:

  • _detect_speech_start() — wait for voice activity above threshold
  • _capture_until_silence() — record until silence timeout

Acceptance: all tests pass, tox -e unit green.

**File:** `src/timmy/voice_loop.py` **Function:** `_record_utterance()` — 73 lines (line 146) This method handles silence detection, audio buffering, and VAD in one block. Extract: - `_detect_speech_start()` — wait for voice activity above threshold - `_capture_until_silence()` — record until silence timeout Acceptance: all tests pass, `tox -e unit` green.
Author
Owner

Kimi Instructions

File: src/timmy/voice_loop.py, method _record_utterance() (lines 146-218)

Goal: Break the 73-line method into smaller focused helpers.

Suggested decomposition:

  1. _rms(block) — extract the nested function as a @staticmethod on the class
  2. _compute_recording_params() — extract the block_size/silence_blocks/min_blocks/max_blocks computation into a helper that returns a named tuple or dict
  3. _wait_for_speech(stream, block_size, threshold) — the waiting-for-speech phase (lines 180-193 when not recording)
  4. _record_until_silence(stream, block_size, threshold, silence_blocks, max_blocks) — the active recording phase
  5. _finalize_audio(chunks, min_blocks, sr) — final concatenation and duration logging (lines 211-218)

Constraints:

  • Keep the sounddevice import lazy (inside the method)
  • Preserve the self._running check in the recording loop
  • Run tox -e unit to verify — voice tests may be skipped but nothing should break
  • Do NOT use --no-verify on any git command
## Kimi Instructions **File:** `src/timmy/voice_loop.py`, method `_record_utterance()` (lines 146-218) **Goal:** Break the 73-line method into smaller focused helpers. **Suggested decomposition:** 1. `_rms(block)` — extract the nested function as a `@staticmethod` on the class 2. `_compute_recording_params()` — extract the block_size/silence_blocks/min_blocks/max_blocks computation into a helper that returns a named tuple or dict 3. `_wait_for_speech(stream, block_size, threshold)` — the waiting-for-speech phase (lines 180-193 when not recording) 4. `_record_until_silence(stream, block_size, threshold, silence_blocks, max_blocks)` — the active recording phase 5. `_finalize_audio(chunks, min_blocks, sr)` — final concatenation and duration logging (lines 211-218) **Constraints:** - Keep the `sounddevice` import lazy (inside the method) - Preserve the `self._running` check in the recording loop - Run `tox -e unit` to verify — voice tests may be skipped but nothing should break - Do NOT use `--no-verify` on any git command
kimi was assigned by Timmy 2026-03-20 01:35:12 +00:00
Timmy closed this issue 2026-03-20 01:37:34 +00:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#570