Machine Learning 6 min read Aug 20, 2026

Speech Recognition Project

R
Rivira Tech Engineering Team
Practical AI, Taught & Built

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.

KKRGENAI 2025 ~10 min read Python Machine Learning Speech Recognition MFCC

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/.

🎤
Collect
Record .wav files by label
🧹
Preprocess
Normalize & denoise audio
📊
Extract
MFCC feature vectors
🌲
Train
Random Forest classifier
🔍
Predict
Classify new audio
📈
Evaluate
Accuracy & F1-scores

Project Structure

The repository is organized into clean, purpose-built directories so you always know where each piece lives.

speech-recognition-project/
├── 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.

  1. Create a Virtual Environment

    Isolate your project dependencies from the system Python installation.

    Bash / macOS / Linux
    $ python -m venv .venv
    $ source .venv/bin/activate
    Windows PowerShell
    PS> python -m venv .venv
    PS> .venv\Scripts\Activate.ps1
  2. Install Libraries

    Install all required Python packages from the requirements file.

    terminal
    $ pip install -r requirements.txt
    ⚠️ On Windows, if PyAudio fails to install, run:
    pip install pipwin && pipwin install pyaudio then re-run pip install -r requirements.txt.
  3. 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.py
    Listening... speak now.
    Recognized text: hello students welcome to speech recognition
    Saved transcript to outputs/live_transcript.txt
  4. 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 5

    Files are saved as: data/raw/start/start_001.wav, data/raw/stop/stop_001.wav, …

  5. Preprocess Audio & Extract Features

    Normalize volume, optionally reduce noise, and compute MFCC feature vectors into a CSV.

    terminal
    $ python src/preprocess_audio.py
    Processed 20 audio files
    Saved features to data/processed/features.csv
  6. 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.py
    Training samples: 16
    Testing samples: 4
    Accuracy: 0.75
    Saved model to models/keyword_model.joblib
  7. 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.wav
    Predicted keyword: start
    Confidence: 0.86
  8. Evaluate the Model

    Generate a full classification report with per-class precision, recall, and F1-score.

    terminal
    $ python src/evaluate.py
    Accuracy: 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

🔇 Record in a quiet room for cleaner signals and higher model accuracy.
🗣️ Keep each keyword short and clear. Avoid trailing sounds.
🎤 Use the same microphone for both training and testing.
📦 Collect 20+ samples per keyword for best results.
📁 Add new folders under data/raw/ to expand your vocabulary.
🔑 Never commit private API keys or GitHub tokens to the repository.

Troubleshooting

Microphone not detected
$ python -m speech_recognition
Audio library install failures
$ python -m pip install --upgrade pip setuptools wheel
$ pip install -r requirements.txt
Low model accuracy — collect more data
$ 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.

Back to All Articles
Share: