# sreosham/wake-up-word- architecture

> Architecture diagram of the GitHub repository sreosham/wake-up-word-, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sreosham/wake-up-word-
- Repository: https://github.com/sreosham/wake-up-word-

## Overview

##### Main Components

- Data Collection Module:
- Represented by the prepare.py script.
- Uses the sounddevice framework to capture audio samples.
- Collects both wakeup words and noise to form a binary classification dataset.

- Preprocessing Module:
- Though not explicitly represented by a file named preprocess.py in the file tree, the README suggests that a preprocessing step exists.
- Uses the Librosa library to extract MFCC features from the collected audio data.
- This module prepares data for model training.

- Model Training Module:
- Represented by train.py.
- The neural network training process feeds on the preprocessed features to learn to distinguish the wakeup word from noise.
- The trained model is saved in the saved_model directory (specifically WWD.h5), along with additional data such as CSV files (audio_data.csv) stored under saved_model/final_audio_wakeup.

- Model Inference Module:
- Represented by inference.py.
- In real-time prediction, a temporary audio file (predict.wav) is generated from user input.
- This audio file is then sent through the trained model to determine if it is the wakeup word.

- Auxiliary/Supporting Files:
- requirements.txt: Lists the project’s dependencies.
- prediction.wav: Likely a sample or generated file used during confirmation or debugging of the prediction process.

##### Relationships and Data Flow

- The data flow begins with data collection (prepare.py) that captures raw audio.
- The raw audio data then moves to the preprocessing module (using Librosa) to extract MFCC features.
- Preprocessed data feeds into the training module (train.py), where a neural network is trained.
- The trained model is stored (saved_model/WWD.h5), and logged data (e.g., CSV in final_audio_wakeup) may be used for evaluation or debugging.
- At runtime, the inference module (inference.py) takes a real-time audio sample (stored as predict.wav) and uses the saved model to classify whether the wakeup word is present.

##### Architectural Patterns and Design Principles

- Separation of Concerns:
- Each step (collection, preprocessing, training, inference) is encapsulated in its own script, clarifying the responsibilities.

- Modular Pipeline:
- The architecture follows a data pipeline with distinct stages which can be diagrammed as separate modules with clear interconnections.

- Real-Time Processing:
- Emphasis on real-time prediction which requires minimal delay between capturing audio (via microphone) and inference.

- Extensibility:
- The saved model and supporting data structure suggest that future updates (e.g., enhanced preprocessing or additional wakeup words) can be integrated without overhauling the system.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Requirements["Dependencies (requirements.txt)"]:::file
    D1["Data Collection (prepare.py)"]:::python
    Pre["Audio Preprocessing (Librosa,MFCC Extraction)"]:::python
    Train["Model Training (train.py)"]:::python

    subgraph "Model Storage"
        SavedH5["Saved Model (WWD.h5)"]:::datastore
        SavedCSV["Audio Data CSV (final_audio_wakeup)"]:::datastore
    end

    subgraph "Real-Time Inference"
        InferenceModule["Inference Module (inference.py)"]:::python
        PredictionFile["Prediction Audio (prediction.wav)"]:::data
    end

    Requirements --> D1
    D1 --> Pre
    Pre --> Train
    Train --> SavedH5
    Train --> SavedCSV
    SavedH5 --> InferenceModule
    SavedCSV --> InferenceModule
    InferenceModule --> PredictionFile

    click Requirements "https://github.com/sreosham/wake-up-word-/blob/main/requirements.txt"
    click D1 "https://github.com/sreosham/wake-up-word-/blob/main/prepare.py"
    click Train "https://github.com/sreosham/wake-up-word-/blob/main/train.py"
    click SavedH5 "https://github.com/sreosham/wake-up-word-/blob/main/saved_model/WWD.h5"
    click SavedCSV "https://github.com/sreosham/wake-up-word-/blob/main/saved_model/final_audio_wakeup/audio_data.csv"
    click InferenceModule "https://github.com/sreosham/wake-up-word-/blob/main/inference.py"
    click PredictionFile "https://github.com/sreosham/wake-up-word-/blob/main/prediction.wav"

    classDef python fill:#B3E5FC,stroke:#0277BD,stroke-width:2px;
    classDef datastore fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef file fill:#FFCCBC,stroke:#D84315,stroke-width:2px;
    classDef data fill:#FFF9C4,stroke:#F9A825,stroke-width:2px;
```
