# ruapotato/voice-command architecture

> Architecture diagram of the GitHub repository ruapotato/voice-command, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ruapotato/voice-command
- Repository: https://github.com/ruapotato/voice-command

## Overview

##### Main Components
- Voice Input & Speech Processing:
- Component: speech/whisper_processor.py
- Function: Converts voice input into text using the Whisper model.
- Core Voice System:
- Component: core/voice_system.py
- Function: Manages the overall voice command processing workflow.
- Command Processing:
- Component: commands/command_processor.py
- Function: Interprets the transcribed voice command and delegates it to the correct command handler.
- Sub-components:
- commands/click_command.py – handles “Click [text]” commands using OCR-based screen text identification.
- commands/type_command.py – handles “Type [text]” commands via keyboard emulation.
- commands/read_command.py – handles “Read” commands, triggering text-to-speech.
- commands/computer_command.py – handles “Computer [query]” commands; interacts with a local LLM.
- Graphical User Interface (GUI):
- Components: gui/application.py, gui/window.py
- Function: Provides a visual interface including microphone buttons, status indicators, and basic controls for toggling continuous listening or stopping actions.
- Supporting and Entry-Point:
- main.py serves as the application’s entry point.
- Additional scripts such as print_project.py aid in debugging/printing the project structure.

##### Relationships and Interactions
- Input Flow:
- The speech component (whisper_processor.py) captures and processes the audio.
- Core Processing:
- The resulting text is passed to core/voice_system.py that manages overall command interpretation.
- This then calls the commands/command_processor.py, which examines the text for keywords (“Click”, “Type”, “Read”, “Computer”) and forwards control to the specific command handler in the commands directory.
- Command Execution:
- Each command handler (e.g., click_command.py, type_command.py) takes the processed command and performs dedicated operations—clicking on-screen elements, simulating keyboard actions, synthesizing speech (via external system dependencies like espeak), or querying the local LLM for “Computer” commands.
- GUI Feedback:
- Throughout this process, the GUI components (in gui/application.py and gui/window.py) display system status, allow toggling of modes, and provide user feedback regarding command actions.

##### Architectural Patterns and Design Principles
- Modularity: The project is split into separate modules (speech, core, commands, gui) that each focus on a distinct aspect of the system.
- Separation of Concerns (SoC): Voice processing, command interpretation, and GUI are completely separated to keep the system maintainable.
- Extensibility: New command handlers can be added easily in the commands/ directory following a similar design pattern.

##### Important Technologies and External Dependencies
- Python libraries (as listed in requirements.txt) for interfacing with system commands and handling voice/GUI interactions.
- OpenAI’s Whisper model for speech recognition.
- Local LLM integration via Ollama for natural language queries.
- External command-line tools: xdotool (for interacting with GUI elements), espeak (for text-to-speech), xclip and tesseract-ocr (for OCR functionality).

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["main.py - Application Entry Point"]:::entry
    subgraph "GUI Layer"
        B1["application.py - Main GUI"]:::gui
        B2["window.py - Window Component"]:::gui
    end
    C["User Voice Input (activated via UI or shortcuts)"]:::input
    D["whisper_processor.py - Speech Recognition"]:::speech
    E["voice_system.py - Core Voice System"]:::speech
    F["command_processor.py - Command Interpreter"]:::commands
    subgraph "Command Handlers"
        G["click_command.py - Handle Click Commands"]:::commands
        H["type_command.py - Handle Type Commands"]:::commands
        I["read_command.py - Handle Read Commands"]:::commands
        J["computer_command.py - Handle Computer Commands"]:::commands
    end
    K["External Dependencies: xdotool,espeak,tesseract-ocr,OllamaLLM"]:::external
    L["print_project.py - Debugging Tools"]:::entry

    A -->|"starts"| B1
    B1 -->|"initializes"| B2
    B2 -->|"triggers"| C
    C -->|"captures audio"| D
    D -->|"transcribes to text"| E
    E -->|"manages workflow"| F
    F -->|"delegates to"| G
    F -->|"delegates to"| H
    F -->|"delegates to"| I
    F -->|"delegates to"| J
    G -->|"executes action"| K
    H -->|"executes action"| K
    I -->|"executes action"| K
    J -->|"executes action"| K
    K -->|"feedback to"| B1
    A -->|"debug info"| L

    classDef entry fill:#ffcccc,stroke:#ff0000,stroke-width:2px;
    classDef gui fill:#ffd700,stroke:#b8860b,stroke-width:2px;
    classDef speech fill:#add8e6,stroke:#00008b,stroke-width:2px;
    classDef commands fill:#90ee90,stroke:#006400,stroke-width:2px;
    classDef external fill:#f9e79f,stroke:#d35400,stroke-width:2px;
    classDef input fill:#e0ffff,stroke:#008b8b,stroke-width:2px;

    click A "https://github.com/ruapotato/voice-command/blob/main/main.py"
    click B1 "https://github.com/ruapotato/voice-command/blob/main/gui/application.py"
    click B2 "https://github.com/ruapotato/voice-command/blob/main/gui/window.py"
    click D "https://github.com/ruapotato/voice-command/blob/main/speech/whisper_processor.py"
    click E "https://github.com/ruapotato/voice-command/blob/main/core/voice_system.py"
    click F "https://github.com/ruapotato/voice-command/blob/main/commands/command_processor.py"
    click G "https://github.com/ruapotato/voice-command/blob/main/commands/click_command.py"
    click H "https://github.com/ruapotato/voice-command/blob/main/commands/type_command.py"
    click I "https://github.com/ruapotato/voice-command/blob/main/commands/read_command.py"
    click J "https://github.com/ruapotato/voice-command/blob/main/commands/computer_command.py"
    click L "https://github.com/ruapotato/voice-command/blob/main/print_project.py"
```
