# kelvinwch/keyboard-acoustic-side-channel-attack architecture

> Architecture diagram of the GitHub repository kelvinwch/keyboard-acoustic-side-channel-attack, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kelvinwch/keyboard-acoustic-side-channel-attack
- Repository: https://github.com/kelvinwch/keyboard-acoustic-side-channel-attack

## Overview

This is an end-to-end acoustic keystroke classification project: record labeled key sounds, isolate individual presses, convert clips to spectrogram images, train a CoAtNet classifier, then classify live microphone input. The inference script can optionally send predicted characters to Ollama for text correction. The README documents the offline stage handoffs; the sampled scripts show the model-loading, audio-processing, and optional HTTP integration. Generated data and model directories are described in the README but are not present in the supplied tree.

Main entry points: [`4_infer/infer.py`](https://github.com/kelvinwch/keyboard-acoustic-side-channel-attack/blob/main/4_infer/infer.py) (Predicted characters), [`1_collect/record.py`](https://github.com/kelvinwch/keyboard-acoustic-side-channel-attack/blob/main/1_collect/record.py) (Keystroke recorder), [`2_preprocess/isolate.py`](https://github.com/kelvinwch/keyboard-acoustic-side-channel-attack/blob/main/2_preprocess/isolate.py) (Press isolator), [`2_preprocess/spectrogram.py`](https://github.com/kelvinwch/keyboard-acoustic-side-channel-attack/blob/main/2_preprocess/spectrogram.py) (Spectrogram generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Audio capture"]
  node_recorder["Keystroke recorder<br/>[record.py]"]
  node_raw_audio["Raw recordings"]
end

subgraph group_prep["Signal preparation"]
  node_isolator["Press isolator<br/>[isolate.py]"]
  node_isolated_audio["Press clips"]
  node_spectrogrammer["Spectrogram generator<br/>[spectrogram.py]"]
  node_spectrogram_images["Spectrogram images"]
end

subgraph group_learning["Model training"]
  node_trainer["CoAtNet trainer<br/>[train.py]"]
  node_classifier["Trained classifier"]
end

subgraph group_live["Live inference"]
  node_live_inference["Live key inference<br/>[infer.py]"]
  node_predicted_text["Predicted characters<br/>[infer.py]"]
  node_corrected_text["Corrected text<br/>[infer.py]"]
end

node_operator(("Keyboard operator"))
node_microphone(("Microphone"))
node_ollama["Ollama Gemma"]

node_operator -->|"enters key presses"| node_recorder
node_microphone -->|"supplies audio"| node_recorder
node_recorder -->|"saves recordings"| node_raw_audio
node_raw_audio -->|"reads recordings"| node_isolator
node_isolator -->|"writes press clips"| node_isolated_audio
node_isolated_audio -->|"reads clips"| node_spectrogrammer
node_spectrogrammer -->|"writes images"| node_spectrogram_images
node_spectrogram_images -->|"trains from images"| node_trainer
node_trainer -->|"saves checkpoint"| node_classifier
node_microphone -->|"streams audio"| node_live_inference
node_classifier -->|"loads checkpoint"| node_live_inference
node_live_inference -->|"predicts keys"| node_predicted_text
node_predicted_text -.->|"optionally requests correction"| node_ollama
node_ollama -.->|"returns correction"| node_corrected_text
node_predicted_text -->|"uses raw text if unavailable"| node_corrected_text

click node_recorder "https://github.com/kelvinwch/keyboard-acoustic-side-channel-attack/blob/main/1_collect/record.py"
click node_isolator "https://github.com/kelvinwch/keyboard-acoustic-side-channel-attack/blob/main/2_preprocess/isolate.py"
click node_spectrogrammer "https://github.com/kelvinwch/keyboard-acoustic-side-channel-attack/blob/main/2_preprocess/spectrogram.py"
click node_trainer "https://github.com/kelvinwch/keyboard-acoustic-side-channel-attack/blob/main/3_train/train.py"
click node_live_inference "https://github.com/kelvinwch/keyboard-acoustic-side-channel-attack/blob/main/4_infer/infer.py"
click node_predicted_text "https://github.com/kelvinwch/keyboard-acoustic-side-channel-attack/blob/main/4_infer/infer.py"
click node_corrected_text "https://github.com/kelvinwch/keyboard-acoustic-side-channel-attack/blob/main/4_infer/infer.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_recorder,node_raw_audio toneBlue
class node_isolator,node_isolated_audio,node_spectrogrammer,node_spectrogram_images toneAmber
class node_trainer,node_classifier toneMint
class node_live_inference,node_predicted_text,node_corrected_text toneRose
class node_operator,node_microphone,node_ollama toneIndigo
```

## Components

### Audio capture

- [Keystroke recorder](https://github.com/kelvinwch/keyboard-acoustic-side-channel-attack/blob/main/1_collect/record.py): `1_collect/record.py`
- **Raw recordings**

### Signal preparation

- [Press isolator](https://github.com/kelvinwch/keyboard-acoustic-side-channel-attack/blob/main/2_preprocess/isolate.py): `2_preprocess/isolate.py`
- **Press clips**
- [Spectrogram generator](https://github.com/kelvinwch/keyboard-acoustic-side-channel-attack/blob/main/2_preprocess/spectrogram.py): `2_preprocess/spectrogram.py`
- **Spectrogram images**

### Model training

- [CoAtNet trainer](https://github.com/kelvinwch/keyboard-acoustic-side-channel-attack/blob/main/3_train/train.py): `3_train/train.py`
- **Trained classifier**

### Live inference

- [Live key inference](https://github.com/kelvinwch/keyboard-acoustic-side-channel-attack/blob/main/4_infer/infer.py): `4_infer/infer.py`
- [Predicted characters](https://github.com/kelvinwch/keyboard-acoustic-side-channel-attack/blob/main/4_infer/infer.py): `4_infer/infer.py`
- [Corrected text](https://github.com/kelvinwch/keyboard-acoustic-side-channel-attack/blob/main/4_infer/infer.py): `4_infer/infer.py`

### Other components

- **Keyboard operator**
- **Microphone**
- **Ollama Gemma**

## Connections

- Keyboard operator → Keystroke recorder: enters key presses (evidence: `README.md`)
- Microphone → Keystroke recorder: supplies audio (evidence: `1_collect/record.py`)
- Keystroke recorder → Raw recordings: saves recordings (evidence: `1_collect/record.py`)
- Raw recordings → Press isolator: reads recordings (evidence: `README.md`)
- Press isolator → Press clips: writes press clips (evidence: `README.md`)
- Press clips → Spectrogram generator: reads clips (evidence: `README.md`)
- Spectrogram generator → Spectrogram images: writes images (evidence: `README.md`)
- Spectrogram images → CoAtNet trainer: trains from images (evidence: `README.md`)
- CoAtNet trainer → Trained classifier: saves checkpoint (evidence: `3_train/train.py`)
- Microphone → Live key inference: streams audio (evidence: `4_infer/infer.py`)
- Trained classifier → Live key inference: loads checkpoint (evidence: `4_infer/infer.py`)
- Live key inference → Predicted characters: predicts keys (evidence: `4_infer/infer.py`)
- Predicted characters → Ollama Gemma: optionally requests correction (evidence: `4_infer/infer.py`)
- Ollama Gemma → Corrected text: returns correction (evidence: `4_infer/infer.py`)
- Predicted characters → Corrected text: uses raw text if unavailable (evidence: `4_infer/infer.py`)
