# axololtos/digital-stethoscope-testing architecture

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

- Interactive diagram: https://gitdiagram.com/axololtos/digital-stethoscope-testing
- Repository: https://github.com/axololtos/digital-stethoscope-testing

## Overview

##### Main Components
- ML Model Training & Processing Pipeline:
– Source Code Files: You have training scripts (train.py, train_test.py), a training/ directory with checkpoints and a frozen graph, as well as supporting utilities (accuracy_utils.*, recognize_commands.*, wav_to_features.*, etc.).
– Model Conversion: The presence of freeze.py and TFLite model files indicates that the trained model is frozen and then converted into a mobile-friendly TFLite format.
– Audio Preprocessing: Scripts such as wav_to_features.py, label_wav.py, and their tests show the preprocessing needed for audio data to create features and labels.

- Mobile Application Components:
– Android AI Classifier: This directory (android-ai-classifier) contains an Android application that likely loads the TFLite model (see the assets with TFLite files and labels) and performs inference on audio inputs.
– Android Voice Recorder: This directory (android-voice-recorder) contains another Android app that focuses on recording audio. This captured audio is either used for on-device testing, user input for the AI classifier, or data gathering.

- External Dependency & Framework Integration:
– TensorFlow/TFLite: The README’s reference to TensorFlow audio recognition and the actual *.tflite and TensorFlow-related Java packages in the Android apps confirm reliance on the TensorFlow ecosystem.
– Build Tools & Configurations: Build scripts (gradle files, BUILD file, and .nix configuration) indicate the integration and build management using Gradle for Android, as well as Python/C++ build processes.

##### Relationships and Interactions
- Data Flow:
– Audio data is captured via the “Android Voice Recorder” app.
– Preprocessing is handled by the Python scripts (wav_to_features, label_wav, etc.) which convert raw audio to features for the training phase.
– The training pipeline uses the processed data to train a model, saving checkpoints and ultimately freezing the model.
– The frozen model is then converted to a TFLite format and placed in the assets for the “Android AI Classifier”.
– The “Android AI Classifier” app uses the TFLite model along with native TensorFlow Lite libraries to perform real-time or batch inference on recorded audio.

- Component Interactions:
– There is a clear separation between the back-end machine learning pipeline (training, preprocessing, model conversion) and the front-end mobile applications.
– Utility and test files (both in Python and C++) provide support to ensure function accuracy and possibly end-to-end flow validation.

##### Architectural Patterns & Important Design Principles
- Separation of Concerns: The architecture distinctly separates data collection (voice recording), data processing/training, and on-device inference/classification.
- Modular Design: With distinct directories for training, inference, and mobile apps, the project is built using a modular approach.
- Client-Server or Pipeline Paradigm: Even though there is no explicit server component, the workflow follows an offline pipeline – recording, processing, training, model conversion, and then mobile deployment.
- Integration of Cross-Platform Components: Combining native mobile apps with Python/C++ machine learning logic exemplifies the integration of different technology stacks.

##### Final Elements to Incorporate
– Clear labels for each component (e.g., “Android Voice Recorder”, “Preprocessing Module”, “Training (train.py)”, “Model Freezing & Conversion”, “Android AI Classifier”).

## Diagram (Mermaid)

```mermaid
flowchart TD

  %% Audio Data Collection
  subgraph "Audio Data Collection"
    subgraph "Android Voice Recorder"
      AVR1("MainActivity.java"):::mobile
      AVR2("RecordPlayActivity.java"):::mobile
    end
  end

  %% Audio Preprocessing Module
  subgraph "Audio Preprocessing Module"
    AP1("wav_to_features.py"):::preprocessing
    AP2("label_wav.py"):::preprocessing
    AP3("label_wav_dir.py"):::preprocessing
    APT1("wav_to_features_test.py"):::preprocessing
    APT2("label_wav_test.py"):::preprocessing
  end

  %% ML Training Pipeline
  subgraph "ML Training Pipeline"
    subgraph "Training Scripts"
      T1("train.py"):::ml
      T2("train_test.py"):::ml
    end
    subgraph "Utility Scripts"
      U1("accuracy_utils.py"):::ml
      U2("recognize_commands.py"):::ml
      U3("wav_to_features.py"):::ml
      U4("label_wav.py"):::ml
    end
    subgraph "Test Scripts"
      TT1("train_test.py"):::ml
      TT2("accuracy_utils_test.cc"):::ml
      TT3("wav_to_features_test.py"):::ml
      TT4("label_wav_test.py"):::ml
    end
    subgraph "Model Artifacts"
      MA1("training/"):::ml
      MA2("model/froze_graph.pb"):::ml
    end
  end

  %% Model Conversion to TFLite
  subgraph "Model Conversion to TFLite"
    CS("freeze.py"):::conversion
    CT("freeze_test.py"):::conversion
    TM("model/output.tflite"):::conversion
    SC("model/tf_lite.py"):::conversion
  end

  %% On-device Inference
  subgraph "On-device Inference"
    subgraph "Android AI Classifier"
      AAC1("App"):::mobile
      AAC2("Assets Directory"):::mobile
    end
  end

  %% External Dependency
  TFT("TensorFlow/TFLite"):::external

  %% Data Flow Connections
  AVR1 ---|"raw_audio"| AP1
  AP1 ---|"features"| T1
  MA2 ---|"frozen_model"| CS
  TM ---|"TFLite_model"| AAC2

  %% External Dependencies
  TFT ---|"library"| T1
  TFT ---|"library"| AAC2

  %% Class Definitions
  classDef ml fill:#F5B7B1,stroke:#CB4335,color:#000;
  classDef mobile fill:#AED6F1,stroke:#2471A3,color:#000;
  classDef preprocessing fill:#F9E79F,stroke:#D4AC0D,color:#000;
  classDef conversion fill:#D2B4DE,stroke:#7D3C98,color:#000;
  classDef external fill:#FAD7A0,stroke:#D35400,color:#000;

  %% Click Events for ML Model Training & Processing Pipeline
  click T1 "https://github.com/axololtos/digital-stethoscope-testing/blob/main/train.py"
  click T2 "https://github.com/axololtos/digital-stethoscope-testing/blob/main/train_test.py"
  click U1 "https://github.com/axololtos/digital-stethoscope-testing/blob/main/accuracy_utils.py"
  click U2 "https://github.com/axololtos/digital-stethoscope-testing/blob/main/recognize_commands.py"
  click U3 "https://github.com/axololtos/digital-stethoscope-testing/blob/main/wav_to_features.py"
  click U4 "https://github.com/axololtos/digital-stethoscope-testing/blob/main/label_wav.py"
  click TT1 "https://github.com/axololtos/digital-stethoscope-testing/blob/main/train_test.py"
  click TT2 "https://github.com/axololtos/digital-stethoscope-testing/blob/main/accuracy_utils_test.cc"
  click TT3 "https://github.com/axololtos/digital-stethoscope-testing/blob/main/wav_to_features_test.py"
  click TT4 "https://github.com/axololtos/digital-stethoscope-testing/blob/main/label_wav_test.py"
  click MA1 "https://github.com/axololtos/digital-stethoscope-testing/tree/main/training/"
  click MA2 "https://github.com/axololtos/digital-stethoscope-testing/blob/main/model/froze_graph.pb"

  %% Click Events for Model Conversion to TFLite
  click CS "https://github.com/axololtos/digital-stethoscope-testing/blob/main/freeze.py"
  click CT "https://github.com/axololtos/digital-stethoscope-testing/blob/main/freeze_test.py"
  click TM "https://github.com/axololtos/digital-stethoscope-testing/blob/main/model/output.tflite"
  click SC "https://github.com/axololtos/digital-stethoscope-testing/blob/main/model/tf_lite.py"

  %% Click Events for Audio Preprocessing Module
  click AP1 "https://github.com/axololtos/digital-stethoscope-testing/blob/main/wav_to_features.py"
  click AP2 "https://github.com/axololtos/digital-stethoscope-testing/blob/main/label_wav.py"
  click AP3 "https://github.com/axololtos/digital-stethoscope-testing/blob/main/label_wav_dir.py"
  click APT1 "https://github.com/axololtos/digital-stethoscope-testing/blob/main/wav_to_features_test.py"
  click APT2 "https://github.com/axololtos/digital-stethoscope-testing/blob/main/label_wav_test.py"

  %% Click Events for Android AI Classifier
  click AAC1 "https://github.com/axololtos/digital-stethoscope-testing/tree/main/android-ai-classifier/"
  click AAC2 "https://github.com/axololtos/digital-stethoscope-testing/tree/main/android-ai-classifier/app/src/main/assets"

  %% Click Events for Android Voice Recorder
  click AVR1 "https://github.com/axololtos/digital-stethoscope-testing/blob/main/android-voice-recorder/app/src/main/java/MainActivity.java"
  click AVR2 "https://github.com/axololtos/digital-stethoscope-testing/blob/main/android-voice-recorder/app/src/main/java/RecordPlayActivity.java"
```
