# lxaw/pronunciationtrainer architecture

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

- Interactive diagram: https://gitdiagram.com/lxaw/pronunciationtrainer
- Repository: https://github.com/lxaw/pronunciationtrainer

## Overview

##### Main Components

A. User Interface Layer (Built with Pygame)
- Component for showing words
- Waveform visualization component
- Animation handling
- User input controls

B. Audio Processing Core
- Audio recording system
- Waveform generation system
- Audio playback system
- File management system

C. Storage Layer
- Reference audio files (wav_refs directory)
- Generated waveform images (wav_img_refs directory)
- Audio-image database

##### Component Relationships and Data Flow

**[User Interface Layer]**
- ↕
**[Audio Processing Core]**
- ↕
**[Storage Layer]**

##### Detailed Component Breakdown

A. User Interface Layer (Purple):
- Subcomponents:
- Manager (sprites.py)
- Animation Controller
- Input Handler

B. Audio Processing Core (Green):
- Subcomponents:
- AudioConverter (audio_converter.py)
- AudioManager (audio_manager.py)
- WaveformGenerator
- RecordingController

C. Storage Layer (Blue):
- Include:
- Database Controller (aud_img_database.py)
- File System Interface
- Reference Audio Storage
- Waveform Image Cache

##### Key Interactions to Highlight

- User input → Audio Recording
- Audio Recording → Waveform Generation
- Waveform Generation → Display
- Reference Audio → Waveform Comparison
- Database → UI Display

##### Technical Elements

Integration with key libraries:
- Pygame (UI rendering)
- NumPy (waveform processing)
- Pydub (audio processing)
- Sounddevice (audio recording)
- Matplotlib (waveform visualization)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph UI["User Interface Layer"]
        direction TB
        Display["Display Component"]
        Colors["Color Management"]
        AnimCtrl["Animation Controller"]
        InputHandler["Input Handler"]
    end

    subgraph Core["Audio Processing Core"]
        direction TB
        AudioConv["Audio Converter"]
        AudioMgr["Audio Manager"]
        WaveGen["Waveform Generator"]
        RecCtrl["Recording Controller"]
    end

    subgraph Storage["Storage Layer"]
        direction TB
        DB[(Audio-Image Database)]
        FSInterface["File System Interface"]
        RefAudio[("Reference Audio")]
        WaveCache[("Waveform Image Cache")]
    end

    subgraph Libraries["External Libraries"]
        direction TB
        Pygame["Pygame"]
        NumPy["NumPy"]
        Pydub["Pydub"]
        SoundDev["Sounddevice"]
        MatPlot["Matplotlib"]
    end

    %% Main Application Components
    MainApp["Main Application"]
    WordPair["Word Pairing System"]

    %% Relationships
    MainApp --> UI
    MainApp --> Core
    MainApp --> Storage
    WordPair --> UI
    WordPair --> Storage

    Display --> AnimCtrl
    InputHandler --> RecCtrl
    AudioConv --> WaveGen
    AudioMgr --> AudioConv
    RecCtrl --> AudioMgr
    WaveGen --> WaveCache
    DB --> FSInterface
    RefAudio --> AudioConv

    %% Library Dependencies
    Pygame --> Display
    NumPy --> WaveGen
    Pydub --> AudioConv
    SoundDev --> RecCtrl
    MatPlot --> WaveGen

    %% Click Events
    click Display "https://github.com/lxaw/PronunciationTrainer/blob/main/sprites.py"
    click Colors "https://github.com/lxaw/PronunciationTrainer/blob/main/basic_colors.py"
    click AudioConv "https://github.com/lxaw/PronunciationTrainer/blob/main/audio_converter.py"
    click AudioMgr "https://github.com/lxaw/PronunciationTrainer/blob/main/audio_manager.py"
    click DB "https://github.com/lxaw/PronunciationTrainer/blob/main/aud_img_database.py"
    click RefAudio "https://github.com/lxaw/PronunciationTrainer/tree/main/wav_refs/"
    click WaveCache "https://github.com/lxaw/PronunciationTrainer/tree/main/wav_img_refs/"
    click MainApp "https://github.com/lxaw/PronunciationTrainer/blob/main/main.py"
    click WordPair "https://github.com/lxaw/PronunciationTrainer/blob/main/pair.py"

    %% Styling
    classDef ui fill:#E6E6FA,stroke:#9370DB
    classDef core fill:#90EE90,stroke:#3CB371
    classDef storage fill:#87CEEB,stroke:#4682B4
    classDef lib fill:#D3D3D3,stroke:#808080
    classDef main fill:#FFB6C1,stroke:#FF69B4

    class Display,Colors,AnimCtrl,InputHandler ui
    class AudioConv,AudioMgr,WaveGen,RecCtrl core
    class DB,FSInterface,RefAudio,WaveCache storage
    class Pygame,NumPy,Pydub,SoundDev,MatPlot lib
    class MainApp,WordPair main
```
