How bscs24133/psl-to-speech-project works
1. Overall shape
- This repository is a local, end-to-end PSL recognition system with three clear stages: dataset preparation, model training/evaluation, and real-time webcam inference.
- The runtime path is not a generic web service; it is a desktop/edge pipeline that captures hand signs, classifies them, then renders and speaks Urdu output.
2. Two recognition branches
- The project has two model families:
- Alphabet recognition for PSL letters.
- Word recognition for PSL vocabulary signs.
- These are stored as separate artifacts (src/models/alphabet_cnn.h5 and src/models/word_cnn.h5) and are trained/evaluated by separate scripts.
3. Input data sources
- Training data comes from two local datasets:
- UAlpha40 for Urdu alphabet signs, mixing static image signs and dynamic video signs.
- PSL Dictionary Toolkit for 80 word-level video signs.
- The datasets are intentionally kept outside GitHub because they are large and machine-local.
4. Preprocessing boundary
- Raw images/videos are not fed directly into the classifier.
- preprocess.py, collect_webcam.py, and hand_crop_flow.py form the data-ingestion boundary that normalizes input into consistent, model-ready samples.
- hand_landmarker.task indicates the pipeline uses a hand landmark detector to localize the signing hand before feature extraction.
5. Core feature representation: optical flow
- optical_flow.py is the central transformation step.
- It converts a sign video into a temporal motion tensor by sampling 16 frames, generating 15 optical-flow maps, and resizing them to 64x64 with 2 channels (horizontal and vertical motion).
- This is the key architectural choice: the classifier learns motion patterns, not just static hand shapes.
6. Generated artifact layer
- Processed flow arrays are saved as .npy files under Dataset/3_OpticalFlow/.
- This creates a clean separation between:
- raw media (JPG/MP4),
- intermediate motion features (.npy),
- and trained models (.h5).
- That separation makes the training and inference code much simpler and faster.
7. Data augmentation and class balancing
- augment_flow.py and augment_words.py expand small or imbalanced classes using transformations like flipping, brightness changes, and noise.
- This is especially important for the dynamic alphabet subset, where the number of original samples is limited.
8. Training subsystem
- train.py, train_alphabet.py, and finetune.py handle model fitting.
- The architecture is likely a CNN over optical-flow tensors, with one training path tuned for alphabet signs and another for word signs.
- src/models/ is the model boundary: training outputs are serialized there for later inference.
9. Evaluation and verification
- evaluate.py and evaluate_alphabet.py measure performance, likely including accuracy and confusion-matrix style analysis.
- verify_flow.py provides a visual sanity-check layer for ensuring optical-flow generation is correct before training.
- This repo treats feature correctness as a first-class concern, which is important for motion-based recognition.
10. Live inference and user-facing output
- app.py, inference.py, text_builder.py, translator.py, urdu_renderer.py, and tts_engine.py form the runtime experience.
- The live loop is: webcam frame buffer → hand crop/flow features → CNN prediction → text assembly → Urdu translation/rendering → speech synthesis.
- text_builder.py suggests predictions are accumulated into readable phrases rather than shown as isolated labels.
11. Urdu language output layer
- The system does not stop at English class labels; it converts them into Urdu text and speech.
- translator.py handles text translation, urdu_renderer.py handles proper Urdu display, and tts_engine.py handles audio output.
- These components introduce external service dependencies through translation/TTS libraries, unlike the core CV and CNN pipeline which is local.
12. Configuration and portability
- config.example.py centralizes paths and dataset locations, which is important because the repo expects large local datasets and machine-specific directories.
- requirements.txt defines the runtime stack, with the major architecture-relevant dependencies being OpenCV, NumPy, TensorFlow/Keras, MediaPipe, matplotlib, and speech/translation libraries.
- The repository is therefore structured as a portable research system, but only if the external datasets and local model assets are present.
13. Notable repo boundary
- The README uses a few older names (config.py, translate.py), while the current tree shows config.example.py and translator.py.
- For diagramming, treat the actual code tree as authoritative and the README as the conceptual description of the pipeline.
Main entry points: optical_flow.py Optical Flow · word_cnn.h5 Word CNN · inference.py Inference · alphabet_cnn.h5 Alphabet CNN
Components 23
Data Prep
Raw dataset ingestion and feature generation
- Preprocess · Normalizes raw sign data before feature extraction
src/preprocess.py - Webcam Capture · Collects live hand-sign samples from camera input
src/collect_webcam.py - Hand Crop · Locates and crops the signing hand using landmarks
src/hand_crop_flow.py - Hand Landmarker · Hand landmark detector used to localize hands in frames
src/hand_landmarker.task - Optical Flow · Converts sign videos into 16-frame motion tensors of 15 flow maps
src/optical_flow.py - Alpha Flows · Processes alphabet samples into stored optical-flow arrays
src/process_alpha_flows.py - Word Flows · Processes word-sign videos into stored optical-flow arrays
src/process_word_flows.py - Flow Augment · Expands optical-flow samples for balancing and robustness
src/augment_flow.py - Word Augment · Augments word-level samples with visual perturbations
src/augment_words.py
Modeling
Training, finetuning, and evaluation
- Train · Main model fitting entrypoint
src/train.py - Alpha Train · Alphabet-specific training path
src/train_alphabet.py - Finetune · Refines pretrained models on target data
src/finetune.py - Evaluate · Runs model performance checks for the main branch
src/evaluate.py - Alpha Eval · Evaluates alphabet recognition performance
src/evaluate_alphabet.py - Verify Flow · Visual inspection of optical-flow generation correctness
src/verify_flow.py
Runtime
Live webcam inference and user-facing output
- App · Starts the live PSL-to-speech experience
src/app.py - Inference · Runs webcam-based classification over prepared features
src/inference.py - Text Builder · Accumulates predictions into readable text
src/text_builder.py - Translator · Converts predicted text into Urdu output
src/translator.py - Urdu Render · Formats Urdu text for display
src/urdu_renderer.py - TTS Engine · Synthesizes spoken Urdu audio
src/tts_engine.py
Assets
Persisted models and detector artifact
- Alphabet CNN · Serialized alphabet recognition model
src/models/alphabet_cnn.h5 - Word CNN · Serialized word recognition model
src/models/word_cnn.h5
Connections 23
- Hand Landmarker → Hand Crop: landmarks · Uses detected hand landmarks to crop the signing hand
- Preprocess → Optical Flow: normalize · Feeds cleaned samples into optical-flow extraction
- Webcam Capture → Hand Crop: capture · Collects webcam frames for crop and flow preparation
- Hand Crop → Optical Flow: crop frames · Provides hand-centered frames to motion extraction
- Optical Flow → Alpha Flows: alpha features · Produces flow tensors for alphabet dataset processing
- Optical Flow → Word Flows: word features · Produces flow tensors for word dataset processing
- Alpha Flows → Flow Augment: balance · Augments alphabet flow samples
- Word Flows → Word Augment: expand · Augments word-level samples
- Flow Augment → Alpha Train: train set · Supplies augmented alphabet data to alphabet training
- Word Augment → Train: train set · Supplies augmented word data to main training
- Alpha Train → Alphabet CNN: save model · Serializes the alphabet CNN artifact
- Train → Word CNN: save model · Serializes the word CNN artifact
- Finetune → Word CNN: refine · Updates the stored model after transfer learning
- Alphabet CNN → Alpha Eval: evaluate · Evaluates the alphabet model
- Word CNN → Evaluate: evaluate · Evaluates the word model
- Optical Flow → Verify Flow: inspect · Checks correctness of generated flow tensors
- App → Inference: launch · Application entrypoint starts inference loop
- Inference → Text Builder: assemble · Turns class predictions into phrase-like output
- Text Builder → Translator: translate · Passes assembled text into Urdu translation
- Translator → Urdu Render: render · Formats translated text for Urdu display
- Urdu Render → TTS Engine: speak · Feeds rendered Urdu text to speech synthesis
- Alphabet CNN → Inference: alphabet path · Used by live inference when alphabet recognition is active
- Word CNN → Inference: word path · Used by live inference when word recognition is active