[loop-generated] [refactor] Split voice_loop.py — 572 lines, complex voice processing logic #1379

Closed
opened 2026-03-24 10:28:59 +00:00 by Timmy · 6 comments
Owner

Problem

src/timmy/voice_loop.py is 572 lines with multiple responsibilities:

  • Voice activation detection (VAD)
  • Audio capture/playback
  • Whisper STT integration
  • Piper TTS integration
  • Chat session management
  • Audio processing pipeline

Proposed Split

  1. Extract audio I/O into src/timmy/voice/audio_io.py
  2. Extract STT/TTS into src/timmy/voice/speech_engines.py
  3. Extract VAD logic into src/timmy/voice/activation.py
  4. Keep voice_loop.py as orchestrator only

Benefits

  • Easier testing of individual voice components
  • Better separation of concerns
  • Reusable audio/TTS modules for other features
  • Reduced complexity per module

Acceptance Criteria

  • No module exceeds 200 lines after split
  • All existing voice functionality preserved
  • All tests pass (tox -e unit)
  • Voice loop still works end-to-end

Files

  • src/timmy/voice_loop.py (primary, 572 lines)

Lines of code is a liability. Delete as much as you create.

## Problem `src/timmy/voice_loop.py` is 572 lines with multiple responsibilities: - Voice activation detection (VAD) - Audio capture/playback - Whisper STT integration - Piper TTS integration - Chat session management - Audio processing pipeline ## Proposed Split 1. Extract audio I/O into `src/timmy/voice/audio_io.py` 2. Extract STT/TTS into `src/timmy/voice/speech_engines.py` 3. Extract VAD logic into `src/timmy/voice/activation.py` 4. Keep `voice_loop.py` as orchestrator only ## Benefits - Easier testing of individual voice components - Better separation of concerns - Reusable audio/TTS modules for other features - Reduced complexity per module ## Acceptance Criteria - [ ] No module exceeds 200 lines after split - [ ] All existing voice functionality preserved - [ ] All tests pass (`tox -e unit`) - [ ] Voice loop still works end-to-end ## Files - `src/timmy/voice_loop.py` (primary, 572 lines) Lines of code is a liability. Delete as much as you create.
Author
Owner

Task for Kimi: Please split this 572-line voice processing module into focused components.

Specific Instructions:

  1. Create src/timmy/voice/ package directory
  2. Extract audio I/O functions → audio_io.py (~150 lines)
  3. Extract Whisper/Piper integration → speech_engines.py (~200 lines)
  4. Extract VAD logic → activation.py (~100 lines)
  5. Keep voice_loop.py as thin orchestrator (~120 lines)

Verification: Run tox -e unit — all tests must pass. Voice loop functionality must remain intact.

Priority: Medium — this improves voice system maintainability and testability.

**Task for Kimi**: Please split this 572-line voice processing module into focused components. **Specific Instructions**: 1. Create `src/timmy/voice/` package directory 2. Extract audio I/O functions → `audio_io.py` (~150 lines) 3. Extract Whisper/Piper integration → `speech_engines.py` (~200 lines) 4. Extract VAD logic → `activation.py` (~100 lines) 5. Keep `voice_loop.py` as thin orchestrator (~120 lines) **Verification**: Run `tox -e unit` — all tests must pass. Voice loop functionality must remain intact. **Priority**: Medium — this improves voice system maintainability and testability.
kimi was assigned by Timmy 2026-03-24 10:29:15 +00:00
kimi was unassigned by Timmy 2026-03-24 18:26:15 +00:00
Author
Owner

Kimi Task: Split voice_loop.py

Branch:

What to do:

  1. Create package with
  2. Extract to :
    • function
    • , , methods → standalone functions taking config params
    • method → standalone function
    • , → into speech_engines.py
  3. Extract to :
    • and as standalone functions
    • and as standalone functions
    • as standalone function
  4. Extract to :
    • , as standalone functions
    • function
    • constant
  5. Keep as thin orchestrator importing from the new modules
  6. Update import if needed (it imports VoiceConfig, VoiceLoop)

Verification: ROOT: No loadable tox.ini or setup.cfg or pyproject.toml or tox.toml found, assuming empty tox.ini at /Users/apayne
ROOT: HandledError| provided environments not found in configuration file:
unit must pass (966 tests). No new test files needed - existing tests should still pass since the public API (VoiceLoop, VoiceConfig) stays the same.

Rules: voice_loop.py should be <150 lines after split. Each extracted module should have clear single responsibility.

**Kimi Task: Split voice_loop.py** Branch: **What to do:** 1. Create package with 2. Extract to : - function - , , methods → standalone functions taking config params - method → standalone function - , → into speech_engines.py 3. Extract to : - and as standalone functions - and as standalone functions - as standalone function 4. Extract to : - , as standalone functions - function - constant 5. Keep as thin orchestrator importing from the new modules 6. Update import if needed (it imports VoiceConfig, VoiceLoop) **Verification:** ROOT: No loadable tox.ini or setup.cfg or pyproject.toml or tox.toml found, assuming empty tox.ini at /Users/apayne ROOT: HandledError| provided environments not found in configuration file: unit must pass (966 tests). No new test files needed - existing tests should still pass since the public API (VoiceLoop, VoiceConfig) stays the same. **Rules:** voice_loop.py should be <150 lines after split. Each extracted module should have clear single responsibility.
kimi was assigned by Timmy 2026-03-24 18:43:37 +00:00
Author
Owner

@kimi Instructions:

Files: src/timmy/voice/speech_engines.py, src/timmy/voice/audio_io.py, src/timmy/voice_loop.py

Split voice_loop.py (572 lines) into focused modules:

  1. Extract speech engine classes to speech_engines.py
  2. Extract audio I/O functions to audio_io.py
  3. Keep voice_loop.py as thin orchestrator importing from both

Verify: tox -e unit passes, tox -e lint clean

@kimi Instructions: Files: src/timmy/voice/speech_engines.py, src/timmy/voice/audio_io.py, src/timmy/voice_loop.py Split voice_loop.py (572 lines) into focused modules: 1. Extract speech engine classes to speech_engines.py 2. Extract audio I/O functions to audio_io.py 3. Keep voice_loop.py as thin orchestrator importing from both Verify: tox -e unit passes, tox -e lint clean
kimi was unassigned by Timmy 2026-03-24 19:18:21 +00:00
Timmy closed this issue 2026-03-24 19:26:55 +00:00
Author
Owner

Completed in PR #1456 (merged). Split voice_loop.py from 572 → 176 lines using mixin pattern. Created 8 new modules in src/timmy/voice/ package. All 966 tests passing. No module exceeds 200 lines.

Completed in PR #1456 (merged). Split voice_loop.py from 572 → 176 lines using mixin pattern. Created 8 new modules in src/timmy/voice/ package. All 966 tests passing. No module exceeds 200 lines.
Author
Owner

Instructions for Kimi

Goal: Split (572 lines) into focused modules.

Files to create/modify:

  1. — Extract speech engine initialization, TTS/STT engine wrappers
  2. — Extract audio input/output handling, microphone management, audio playback
  3. — Keep the main loop orchestration, import from the new modules

Steps:

  1. Read and identify logical groupings
  2. Create the two new files with extracted code
  3. Update imports in to use the new modules
  4. Add to if it doesn't exist
  5. Run ROOT: No loadable tox.ini or setup.cfg or pyproject.toml or tox.toml found, assuming empty tox.ini at /Users/apayne
    ROOT: HandledError| provided environments not found in configuration file:
    format then ROOT: No loadable tox.ini or setup.cfg or pyproject.toml or tox.toml found, assuming empty tox.ini at /Users/apayne
    ROOT: HandledError| provided environments not found in configuration file:
    unit — all 966+ tests must pass
  6. Run ROOT: No loadable tox.ini or setup.cfg or pyproject.toml or tox.toml found, assuming empty tox.ini at /Users/apayne
    ROOT: HandledError| provided environments not found in configuration file:
    lint — must be clean

Acceptance criteria:

  • reduced to <200 lines (orchestration only)
  • and contain the extracted logic
  • All existing tests pass unchanged
  • No circular imports
  • ROOT: No loadable tox.ini or setup.cfg or pyproject.toml or tox.toml found, assuming empty tox.ini at /Users/apayne
    ROOT: HandledError| provided environments not found in configuration file:
    lint clean
## Instructions for Kimi **Goal:** Split (572 lines) into focused modules. **Files to create/modify:** 1. — Extract speech engine initialization, TTS/STT engine wrappers 2. — Extract audio input/output handling, microphone management, audio playback 3. — Keep the main loop orchestration, import from the new modules **Steps:** 1. Read and identify logical groupings 2. Create the two new files with extracted code 3. Update imports in to use the new modules 4. Add to if it doesn't exist 5. Run ROOT: No loadable tox.ini or setup.cfg or pyproject.toml or tox.toml found, assuming empty tox.ini at /Users/apayne ROOT: HandledError| provided environments not found in configuration file: format then ROOT: No loadable tox.ini or setup.cfg or pyproject.toml or tox.toml found, assuming empty tox.ini at /Users/apayne ROOT: HandledError| provided environments not found in configuration file: unit — all 966+ tests must pass 6. Run ROOT: No loadable tox.ini or setup.cfg or pyproject.toml or tox.toml found, assuming empty tox.ini at /Users/apayne ROOT: HandledError| provided environments not found in configuration file: lint — must be clean **Acceptance criteria:** - reduced to <200 lines (orchestration only) - and contain the extracted logic - All existing tests pass unchanged - No circular imports - ROOT: No loadable tox.ini or setup.cfg or pyproject.toml or tox.toml found, assuming empty tox.ini at /Users/apayne ROOT: HandledError| provided environments not found in configuration file: lint clean
kimi was assigned by Timmy 2026-03-24 19:36:09 +00:00
Author
Owner

Kimi Instructions (corrected)

Goal: Split src/timmy/voice_loop.py (572 lines) into focused modules.

Files to create/modify:

  1. src/timmy/voice/speech_engines.py - Extract speech engine initialization, TTS/STT engine wrappers
  2. src/timmy/voice/audio_io.py - Extract audio input/output handling, microphone management, audio playback
  3. src/timmy/voice_loop.py - Keep the main loop orchestration, import from the new modules

Steps:

  1. Read src/timmy/voice_loop.py and identify logical groupings
  2. Create the two new files with extracted code
  3. Update imports in voice_loop.py to use the new modules
  4. Add init.py to src/timmy/voice/ if it doesn't exist
  5. Run: tox -e format then tox -e unit -- all 966+ tests must pass
  6. Run: tox -e lint -- must be clean

Acceptance criteria:

  • voice_loop.py reduced to <200 lines (orchestration only)
  • speech_engines.py and audio_io.py contain the extracted logic
  • All existing tests pass unchanged
  • No circular imports
  • tox -e lint clean
## Kimi Instructions (corrected) Goal: Split src/timmy/voice_loop.py (572 lines) into focused modules. Files to create/modify: 1. src/timmy/voice/speech_engines.py - Extract speech engine initialization, TTS/STT engine wrappers 2. src/timmy/voice/audio_io.py - Extract audio input/output handling, microphone management, audio playback 3. src/timmy/voice_loop.py - Keep the main loop orchestration, import from the new modules Steps: 1. Read src/timmy/voice_loop.py and identify logical groupings 2. Create the two new files with extracted code 3. Update imports in voice_loop.py to use the new modules 4. Add __init__.py to src/timmy/voice/ if it doesn't exist 5. Run: tox -e format then tox -e unit -- all 966+ tests must pass 6. Run: tox -e lint -- must be clean Acceptance criteria: - voice_loop.py reduced to <200 lines (orchestration only) - speech_engines.py and audio_io.py contain the extracted logic - All existing tests pass unchanged - No circular imports - tox -e lint clean
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#1379