# sagnik-barman/morse-cw-decoder architecture

> Architecture diagram of the GitHub repository sagnik-barman/morse-cw-decoder, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sagnik-barman/morse-cw-decoder
- Repository: https://github.com/sagnik-barman/morse-cw-decoder

## Overview

This is a deep-learning Morse CW decoder, with a classical DSP decoder for comparison. Its main workflow trains acoustic models on procedurally generated, impaired audio, then transcribes recordings into text; evaluation compares model and baseline errors on synthetic and real audio. Real-data tooling also aligns beacon recordings to a schedule and produces labelled clips with SNR estimates. The graph preserves the documented training, decoding, language-model, and benchmark branches. Source excerpts and README statements support the shown links; unsampled implementations are represented only where documented.

Main entry points: [`morse/infer.py`](https://github.com/sagnik-barman/morse-cw-decoder/blob/main/morse/infer.py) (Inference Helpers), [`scripts/benchmark_real.py`](https://github.com/sagnik-barman/morse-cw-decoder/blob/main/scripts/benchmark_real.py) (Real-audio Benchmark), [`scripts/evaluate.py`](https://github.com/sagnik-barman/morse-cw-decoder/blob/main/scripts/evaluate.py) (Synthetic Evaluation), [`scripts/decode_wav.py`](https://github.com/sagnik-barman/morse-cw-decoder/blob/main/scripts/decode_wav.py) (WAV Transcription)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_training["Synthetic Training"]
  node_textgen["Label Text<br/>[text_gen.py]"]
  node_synth["Audio Synthesis<br/>[synth.py]"]
  node_data["Training Data<br/>[data.py]"]
  node_trainer["Model Training<br/>[train.py]"]
end

subgraph group_decoding["Transcription"]
  node_model["CTC Acoustic Model<br/>[model.py]"]
  node_infer["Inference Helpers<br/>[infer.py]"]
  node_decode["CTC Decoding<br/>[decode.py]"]
  node_baseline["DSP Baseline<br/>[baseline.py]"]
  node_wavdecode["WAV Transcription<br/>[decode_wav.py]"]
  node_alphabet["Morse Vocabulary<br/>[alphabet.py]"]
end

subgraph group_realdata["Real Data"]
  node_beacons["Beacon Schedule &amp; SNR<br/>[beacons.py]"]
  node_record["Beacon Recording<br/>[record_beacons.py]"]
  node_slice["Beacon Clip Labelling<br/>[slice_beacons.py]"]
  node_realmanifest["Real-data Loader<br/>[realdata.py]"]
end

subgraph group_evaluation["Evaluation"]
  node_metrics["CER / WER Metrics<br/>[metrics.py]"]
  node_evaluate["Synthetic Evaluation<br/>[evaluate.py]"]
  node_benchmark["Real-audio Benchmark<br/>[benchmark_real.py]"]
  node_lm["Character LM Builder<br/>[build_lm.py]"]
end

node_operator(("Operator"))
node_audio["Audio Recording"]
node_text["Decoded Text"]

node_operator -->|"trains"| node_trainer
node_textgen -->|"supplies labels"| node_synth
node_synth -->|"generates clips"| node_data
node_data -->|"feeds batches"| node_trainer
node_trainer -->|"trains"| node_model
node_operator -->|"provides"| node_audio
node_audio -->|"transcribes"| node_wavdecode
node_wavdecode -->|"uses"| node_infer
node_infer -->|"runs inference"| node_model
node_infer -->|"decodes output"| node_decode
node_infer -->|"offers baseline"| node_baseline
node_decode -->|"maps symbols"| node_alphabet
node_wavdecode -->|"returns transcript"| node_text
node_operator -->|"records beacon"| node_record
node_record -->|"uses schedule"| node_beacons
node_record -->|"records and slices"| node_slice
node_slice -->|"aligns and measures"| node_beacons
node_slice -->|"writes labelled clips"| node_realmanifest
node_operator -->|"evaluates"| node_evaluate
node_evaluate -->|"uses synthetic sets"| node_data
node_evaluate -->|"runs systems"| node_infer
node_evaluate -->|"computes errors"| node_metrics
node_operator -->|"benchmarks recordings"| node_benchmark
node_benchmark -->|"loads real sets"| node_realmanifest
node_benchmark -->|"transcribes clips"| node_infer
node_benchmark -->|"compares baseline"| node_baseline
node_benchmark -->|"scores outputs"| node_metrics
node_operator -->|"builds language model"| node_lm
node_lm -->|"builds LM for"| node_decode

click node_textgen "https://github.com/sagnik-barman/morse-cw-decoder/blob/main/morse/text_gen.py"
click node_synth "https://github.com/sagnik-barman/morse-cw-decoder/blob/main/morse/synth.py"
click node_data "https://github.com/sagnik-barman/morse-cw-decoder/blob/main/morse/data.py"
click node_trainer "https://github.com/sagnik-barman/morse-cw-decoder/blob/main/scripts/train.py"
click node_model "https://github.com/sagnik-barman/morse-cw-decoder/blob/main/morse/model.py"
click node_infer "https://github.com/sagnik-barman/morse-cw-decoder/blob/main/morse/infer.py"
click node_decode "https://github.com/sagnik-barman/morse-cw-decoder/blob/main/morse/decode.py"
click node_baseline "https://github.com/sagnik-barman/morse-cw-decoder/blob/main/morse/baseline.py"
click node_wavdecode "https://github.com/sagnik-barman/morse-cw-decoder/blob/main/scripts/decode_wav.py"
click node_alphabet "https://github.com/sagnik-barman/morse-cw-decoder/blob/main/morse/alphabet.py"
click node_beacons "https://github.com/sagnik-barman/morse-cw-decoder/blob/main/morse/beacons.py"
click node_record "https://github.com/sagnik-barman/morse-cw-decoder/blob/main/scripts/record_beacons.py"
click node_slice "https://github.com/sagnik-barman/morse-cw-decoder/blob/main/scripts/slice_beacons.py"
click node_realmanifest "https://github.com/sagnik-barman/morse-cw-decoder/blob/main/morse/realdata.py"
click node_metrics "https://github.com/sagnik-barman/morse-cw-decoder/blob/main/morse/metrics.py"
click node_evaluate "https://github.com/sagnik-barman/morse-cw-decoder/blob/main/scripts/evaluate.py"
click node_benchmark "https://github.com/sagnik-barman/morse-cw-decoder/blob/main/scripts/benchmark_real.py"
click node_lm "https://github.com/sagnik-barman/morse-cw-decoder/blob/main/scripts/build_lm.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_textgen,node_synth,node_data,node_trainer toneBlue
class node_model,node_infer,node_decode,node_baseline,node_wavdecode,node_alphabet toneAmber
class node_beacons,node_record,node_slice,node_realmanifest toneMint
class node_metrics,node_evaluate,node_benchmark,node_lm toneRose
class node_operator,node_audio,node_text toneIndigo
```

## Components

### Synthetic Training

- [Label Text](https://github.com/sagnik-barman/morse-cw-decoder/blob/main/morse/text_gen.py): `morse/text_gen.py`
- [Audio Synthesis](https://github.com/sagnik-barman/morse-cw-decoder/blob/main/morse/synth.py): `morse/synth.py`
- [Training Data](https://github.com/sagnik-barman/morse-cw-decoder/blob/main/morse/data.py): `morse/data.py`
- [Model Training](https://github.com/sagnik-barman/morse-cw-decoder/blob/main/scripts/train.py): `scripts/train.py`

### Transcription

- [CTC Acoustic Model](https://github.com/sagnik-barman/morse-cw-decoder/blob/main/morse/model.py): `morse/model.py`
- [Inference Helpers](https://github.com/sagnik-barman/morse-cw-decoder/blob/main/morse/infer.py): `morse/infer.py`
- [CTC Decoding](https://github.com/sagnik-barman/morse-cw-decoder/blob/main/morse/decode.py): `morse/decode.py`
- [DSP Baseline](https://github.com/sagnik-barman/morse-cw-decoder/blob/main/morse/baseline.py): `morse/baseline.py`
- [WAV Transcription](https://github.com/sagnik-barman/morse-cw-decoder/blob/main/scripts/decode_wav.py): `scripts/decode_wav.py`
- [Morse Vocabulary](https://github.com/sagnik-barman/morse-cw-decoder/blob/main/morse/alphabet.py): `morse/alphabet.py`

### Real Data

- [Beacon Schedule & SNR](https://github.com/sagnik-barman/morse-cw-decoder/blob/main/morse/beacons.py): `morse/beacons.py`
- [Beacon Recording](https://github.com/sagnik-barman/morse-cw-decoder/blob/main/scripts/record_beacons.py): `scripts/record_beacons.py`
- [Beacon Clip Labelling](https://github.com/sagnik-barman/morse-cw-decoder/blob/main/scripts/slice_beacons.py): `scripts/slice_beacons.py`
- [Real-data Loader](https://github.com/sagnik-barman/morse-cw-decoder/blob/main/morse/realdata.py): `morse/realdata.py`

### Evaluation

- [CER / WER Metrics](https://github.com/sagnik-barman/morse-cw-decoder/blob/main/morse/metrics.py): `morse/metrics.py`
- [Synthetic Evaluation](https://github.com/sagnik-barman/morse-cw-decoder/blob/main/scripts/evaluate.py): `scripts/evaluate.py`
- [Real-audio Benchmark](https://github.com/sagnik-barman/morse-cw-decoder/blob/main/scripts/benchmark_real.py): `scripts/benchmark_real.py`
- [Character LM Builder](https://github.com/sagnik-barman/morse-cw-decoder/blob/main/scripts/build_lm.py): `scripts/build_lm.py`

### Other components

- **Operator**
- **Audio Recording**
- **Decoded Text**

## Connections

- Operator → Model Training: trains (evidence: `README.md`)
- Label Text → Audio Synthesis: supplies labels (evidence: `morse/synth.py`)
- Audio Synthesis → Training Data: generates clips (evidence: `morse/data.py`)
- Training Data → Model Training: feeds batches (evidence: `scripts/train.py`)
- Model Training → CTC Acoustic Model: trains (evidence: `scripts/train.py`)
- Operator → Audio Recording: provides (evidence: `README.md`)
- Audio Recording → WAV Transcription: transcribes (evidence: `README.md`)
- WAV Transcription → Inference Helpers: uses (evidence: `scripts/decode_wav.py`)
- Inference Helpers → CTC Acoustic Model: runs inference (evidence: `morse/infer.py`)
- Inference Helpers → CTC Decoding: decodes output (evidence: `morse/infer.py`)
- Inference Helpers → DSP Baseline: offers baseline (evidence: `morse/infer.py`)
- CTC Decoding → Morse Vocabulary: maps symbols (evidence: `morse/decode.py`)
- WAV Transcription → Decoded Text: returns transcript (evidence: `README.md`)
- Operator → Beacon Recording: records beacon (evidence: `README.md`)
- Beacon Recording → Beacon Schedule & SNR: uses schedule (evidence: `scripts/record_beacons.py`)
- Beacon Recording → Beacon Clip Labelling: records and slices (evidence: `README.md`)
- Beacon Clip Labelling → Beacon Schedule & SNR: aligns and measures (evidence: `scripts/slice_beacons.py`)
- Beacon Clip Labelling → Real-data Loader: writes labelled clips (evidence: `README.md`)
- Operator → Synthetic Evaluation: evaluates (evidence: `README.md`)
- Synthetic Evaluation → Training Data: uses synthetic sets (evidence: `scripts/evaluate.py`)
- Synthetic Evaluation → Inference Helpers: runs systems (evidence: `scripts/evaluate.py`)
- Synthetic Evaluation → CER / WER Metrics: computes errors (evidence: `scripts/evaluate.py`)
- Operator → Real-audio Benchmark: benchmarks recordings (evidence: `README.md`)
- Real-audio Benchmark → Real-data Loader: loads real sets (evidence: `scripts/benchmark_real.py`)
- Real-audio Benchmark → Inference Helpers: transcribes clips (evidence: `scripts/benchmark_real.py`)
- Real-audio Benchmark → DSP Baseline: compares baseline (evidence: `scripts/benchmark_real.py`)
- Real-audio Benchmark → CER / WER Metrics: scores outputs (evidence: `scripts/benchmark_real.py`)
- Operator → Character LM Builder: builds language model (evidence: `README.md`)
- Character LM Builder → CTC Decoding: builds LM for (evidence: `scripts/build_lm.py`)
