A student-friendly machine learning project for building real-time voice-to-text and keyword classification workflows — powered by MFCC features and a Random Forest model.
📋 Table of Contents
What Is This Project?
This is a student-friendly machine learning project prepared by KKRGENAI for building speech recognition workflows from scratch. No prior ML experience is required — just Python 3.10+ and a working microphone.
You will walk through two complete paths: first, see real-time speech-to-text in action using the Google Web Speech API; then, learn the underlying ML pipeline by recording, preprocessing, and training your own keyword model using MFCC features and a Random Forest classifier.
What You Will Build
Two practical, end-to-end speech recognition paths — both runnable from the command line.
Real-Time Voice-to-Text
Speak into your microphone and watch speech convert to text instantly via Google Web Speech API.
Keyword Recognition Model
Record short commands (yes, no, start, stop), extract MFCC features, and train a Random Forest classifier.
MFCC Feature Extraction
Convert raw audio signals into numerical Mel-Frequency Cepstral Coefficients the model can learn from.
Keyword Prediction
Feed a .wav file to your trained model and get the predicted keyword with a confidence score.
Model Evaluation
Generate a full classification report with precision, recall, and F1-score for every keyword label.
Audio Preprocessing
Normalize volume, optionally reduce noise, and save clean signals ready for feature extraction.
How the Pipeline Works
The keyword recognition path follows a six-stage ML pipeline, each stage handled by a dedicated script in src/.
Project Structure
The repository is organized into clean, purpose-built directories so you always know where each piece lives.
├── data/ │ ├── raw/ # Student-recorded audio files by label │ └── processed/ # Cleaned audio and extracted feature files ├── docs/ │ └── student_guide.md # Beginner step-by-step guide ├── models/ # Trained model files (.joblib) ├── outputs/ # Example transcripts and predictions ├── src/ │ ├── collect_audio.py # Record labeled training audio │ ├── preprocess_audio.py # Clean audio & extract MFCC features │ ├── train_model.py # Train keyword recognition model │ ├── predict.py # Predict keyword from an audio file │ ├── realtime_transcribe.py# Real-time speech-to-text │ └── evaluate.py # Evaluate trained model ├── requirements.txt └── README.md
Requirements
Python 3.10+
Required for all scripts. Check with python --version.
Microphone
Needed for recording training audio and real-time transcription.
Internet Connection
Required for Google Web Speech API during live transcription.
Terminal
Bash, Git Bash, macOS Terminal, Linux Terminal, or Windows PowerShell.
Step-by-Step Setup
Follow these eight steps to go from a fresh clone to a fully trained keyword recognition model.
-
Create a Virtual Environment
Isolate your project dependencies from the system Python installation.
Bash / macOS / Linux$ python -m venv .venv $ source .venv/bin/activateWindows PowerShellPS> python -m venv .venv PS> .venv\Scripts\Activate.ps1 -
Install Libraries
Install all required Python packages from the requirements file.
terminal$ pip install -r requirements.txtOn Windows, if PyAudio fails to install, run:
pip install pipwin && pipwin install pyaudiothen re-runpip install -r requirements.txt. -
Try Real-Time Voice-to-Text
Speak clearly after the prompt appears. Your speech will be transcribed and saved automatically.
terminal$ python src/realtime_transcribe.pyListening... speak now.
Recognized text: hello students welcome to speech recognition
Saved transcript to outputs/live_transcript.txt -
Record Training Audio
Create a small labeled dataset. Record at least 5 samples per keyword in a quiet room.
terminal$ python src/collect_audio.py --label start --count 5 $ python src/collect_audio.py --label stop --count 5 $ python src/collect_audio.py --label yes --count 5 $ python src/collect_audio.py --label no --count 5Files are saved as:
data/raw/start/start_001.wav,data/raw/stop/stop_001.wav, … -
Preprocess Audio & Extract Features
Normalize volume, optionally reduce noise, and compute MFCC feature vectors into a CSV.
terminal$ python src/preprocess_audio.pyProcessed 20 audio files
Saved features to data/processed/features.csv -
Train the Keyword Recognition Model
The Random Forest classifier is trained on the extracted MFCC features and saved to disk.
terminal$ python src/train_model.pyTraining samples: 16
Testing samples: 4
Accuracy: 0.75
Saved model to models/keyword_model.joblib -
Predict a Keyword from Audio
Point the predictor at any .wav file and get the predicted keyword plus a confidence score.
terminal$ python src/predict.py --audio data/raw/start/start_001.wavPredicted keyword: start
Confidence: 0.86 -
Evaluate the Model
Generate a full classification report with per-class precision, recall, and F1-score.
terminal$ python src/evaluate.pyAccuracy: 0.82
Classification report:
precision recall f1-score support
no 0.80 1.00 0.89 4
start 1.00 0.75 0.86 4
stop 0.75 0.75 0.75 4
yes 0.80 0.80 0.80 5
Tips for Students
data/raw/ to expand your vocabulary.Troubleshooting
$ python -m speech_recognition
$ python -m pip install --upgrade pip setuptools wheel
$ pip install -r requirements.txt
$ python src/collect_audio.py --label start --count 20
$ python src/preprocess_audio.py
$ python src/train_model.py
About KKRGENAI
KKR Gen AI Innovations provides AI-driven solutions, data analytics, software development, app and web development, cloud management, digital services, and AI training for professionals and young learners worldwide.