This project is an educational implementation of an Environmental Sound Classification system using the ESC-50 dataset. The main goal of the project is to build an end-to-end audio classification pipeline, starting from raw audio files and ending with model inference on an unseen audio file.
The project covers the following stages:
- Dataset inspection and analysis
- Audio preprocessing and data splitting
- Audio feature extraction
- Feature scaling
- Spectrogram generation
- Training and evaluation of multiple machine learning models
- CNN-based audio classification
- Model comparison
- Final model inference
The project uses the ESC-50 dataset, a dataset containing environmental audio recordings organized into 50 classes.
The dataset contains:
- 50 environmental sound classes
- 2,000 audio recordings
- 40 recordings per class
- 5-second audio clips
- 44.1 kHz sample rate The dataset is divided into training, validation, and test sets for model development and evaluation.
The overall pipeline of the project is: Raw Audio ↓ Dataset Inspection ↓ Audio Preprocessing ↓ Train / Validation / Test Split ↓ Feature Extraction ↓ Feature Scaling ↓ Machine Learning Models ↓ Spectrogram Generation ↓ CNN Model ↓ Model Evaluation ↓ Model Comparison ↓ Inference
For the traditional machine learning models, several audio features are extracted from each audio file.
The extracted features include:
- RMS Energy
- Zero Crossing Rate (ZCR)
- MFCC
- Spectral Centroid
- Spectral Bandwidth
- Spectral Rolloff
- Spectral Contrast
- MFCC Delta
- MFCC Delta-Delta
Statistical representations such as mean, standard deviation, minimum, maximum, and selected percentiles are calculated over the time dimension. The final feature representation contains 249 features per audio sample.
A separate representation based on Mel spectrograms is used for the CNN model.
The generated spectrogram representation has the shape: 128 × 126 × 1 These spectrograms are normalized using statistics calculated from the training set before being provided to the CNN.
Several classification models were implemented and evaluated.
- Logistic Regression
- Support Vector Machine (SVM)
- Random Forest
- K-Nearest Neighbors (KNN)
- Convolutional Neural Network (CNN)
The traditional machine learning models use the extracted and scaled feature vectors, while the CNN operates on spectrogram representations.
The models were evaluated on the test set using classification accuracy.
| Model | Test Accuracy |
|---|---|
| Logistic Regression | 60.75% |
| Random Forest | 60.25% |
| CNN | 58.00% |
| SVM | 54.25% |
| KNN | 44.75% |
Based on the test accuracy, Logistic Regression achieved the best performance among the evaluated models with an accuracy of 60.75%. Random Forest performed very closely with 60.25%, while the CNN achieved 58.00%.
The best-performing model in the current implementation is Logistic Regression. Test Accuracy: 60.75%
The project includes an inference pipeline that can load a trained model and scaler, extract features from a new audio file, apply the same feature scaling used during training, and generate a predicted environmental sound class.
The inference pipeline performs the following steps:
- Load the trained Logistic Regression model.
- Load the fitted StandardScaler.
- Load the input audio file.
- Extract the same 249-dimensional feature representation used during training.
- Scale the extracted features.
- Generate the predicted class.
- Map the predicted class to the corresponding ESC-50 category.
Example:
Audio file: 1-100032-A-0.wav
Sample rate: 44100
Duration: 5.00 seconds
Feature shape: (249,)
Scaled feature shape: (1, 249)
Predicted class: 0
Prediction: class= 0 -> category= dog