Deep learning system for emotion recognition from speech, achieving 50.5% accuracy on 8-class classification using transformer architecture and real-time analysis
2
stars
29
commits
Python
primary language
Apr 22, 2025
updated
This project demonstrates:
This challenging project involves classifying speech into 8 distinct emotions. While commercial systems often focus on 3-4 emotions, this system achieves impressive results across all 8 emotion classes, outperforming random chance (12.5%) by 4× with 50.5% accuracy.
Confusion matrix showing the model's performance across 8 emotion classes. Note the strong performance on Neutral (72%) and Calm (63%) emotions, with most confusion occurring between acoustically similar emotions like Happy/Surprised.
Training progression showing steady improvement from 22.3% in epoch 1 to the final 50.5% accuracy over 50 epochs, demonstrating stable learning without overfitting.
Distribution of emotions in the RAVDESS dataset, showing balanced representation across all 8 emotion classes.
| Model | Accuracy | F1-Score | Training Time | Key Features |
|---|---|---|---|---|
| Simplified (Best) | 50.5% | 0.48 | ~1h | Error-resistant architecture, 4 transformer layers |
| Ultimate | 33.3% | 0.32 | ~5h | Complex transformer architecture |
| Enhanced | 31.5% | 0.30 | ~3h | Attention mechanisms |
| Base | 29.7% | 0.28 | ~2h | Initial CNN implementation |
Confusion Matrix Highlights:
• Neutral emotions recognized with highest accuracy (72%)
• Most confusion between Calm/Neutral and Happy/Surprised pairs
• Angry and Sad emotions identified with moderate accuracy
• Disgust most frequently misclassified
Classification Report:
precision recall f1-score support
neutral 0.67 0.72 0.69 40
calm 0.58 0.63 0.60 40
happy 0.53 0.51 0.52 40
sad 0.61 0.57 0.59 40
angry 0.48 0.52 0.50 40
fearful 0.45 0.41 0.43 40
disgust 0.39 0.41 0.40 40
surprised 0.42 0.38 0.40 40
accuracy 0.505 320
macro avg 0.52 0.52 0.52 320
weighted avg 0.52 0.51 0.50 320
This project features a comprehensive series of Jupyter notebooks documenting the iterative model development process:
Initial CNN-based approach established a strong baseline with:
Building on the base model, incorporated:
Complex architecture that pushed the boundaries with:
Best-performing model proved that focused architectural design beats complexity:
Each notebook contains comprehensive documentation, visualizations, and performance analyses that demonstrate the research process and technical insights.
The system can recognize the following 8 emotions from speech:
# Clone the repository
git clone https://github.com/vatsalmehta/speech-emotion-recognition.git
cd speech-emotion-recognition
# Install dependencies
pip install -r requirements.txt

The project includes an interactive GUI application for real-time speech emotion analysis with the following features:
# Run the real-time GUI
./run_gui.sh
# Or run the terminal-based demo
python src/interactive_demo.py
This launches the interactive application where you can speak and see emotions detected in real-time. The application requires Python with tkinter support.
The project includes a system verification script to check if all necessary components are installed:
# Make the script executable
chmod +x src/check_project.py
# Run the verification
python src/check_project.py
This project uses the RAVDESS dataset (Ryerson Audio-Visual Database of Emotional Speech and Song). Follow these steps precisely:
Download the Dataset Files:
# Create dataset directory
mkdir -p dataset_raw
cd dataset_raw
Option A: Download Everything at Once (Recommended)
unzip 1188976.zip
Option B: Download Individual Files
# Download only the Audio Speech file (208.5 MB)
wget https://zenodo.org/record/1188976/files/Audio_Speech_Actors_01-24.zip
unzip Audio_Speech_Actors_01-24.zip
Verify Dataset Structure: The extracted dataset should have the following structure:
dataset_raw/
└── Audio_Speech_Actors_01-24/
├── Actor_01/
│ ├── 03-01-01-01-01-01-01.wav
│ ├── 03-01-01-01-01-02-01.wav
│ └── ... (more audio files)
├── Actor_02/
│ ├── 03-01-01-01-01-01-02.wav
│ └── ... (more audio files)
└── ... (Actor_03 through Actor_24 folders)
Process the Dataset for Training:
# Return to project root first if needed
cd ..
# Run the dataset preparation script
python src/prepare_ravdess.py \
--dataset_path dataset_raw/Audio_Speech_Actors_01-24 \
--output_path processed_dataset \
--train_ratio 0.7 \
--val_ratio 0.15 \
--test_ratio 0.15
Verify Processed Dataset:
# Check processed dataset structure
ls -la processed_dataset
# You should see train, val, and test directories with organized audio files
# Each file will be labeled with its emotion category
RAVDESS audio files follow this naming convention:
03-01-04-01-02-01-12.wav means:
The processing script handles this naming convention automatically to extract emotions and organize files.
IMPORTANT: The raw dataset (~25.6GB) and processed audio files are deliberately excluded from this repository due to their size. You must follow the steps above to prepare the dataset locally.
Pre-trained models are not included in this repository due to their large size. After training your own models using the instructions below, they will be saved in the models/ directory.
To use a specific model for inference:
# Run inference with your trained model
python src/inference.py --model_path models/ravdess_simple/best_model.pt
The development process involved creating and refining several model architectures, each documented in detail through the project notebooks:
Base Model (29.7% accuracy)
Enhanced Model (31.5% accuracy)
Ultimate Model (33.3% accuracy)
Simplified Model (50.5% accuracy)
The simplified model proved that architectural focus and training stability were more important than complexity for this task.
Analyzing the confusion matrix revealed:
These insights informed targeted improvements in the model architecture.
This project showcases an iterative approach to deep learning model development:
Each iteration provided insights that informed the next development phase, ultimately leading to the best-performing model with a 50.5% accuracy on this challenging 8-class task.
While the current Simplified Model achieves strong results at 50.5% accuracy, this represents an ongoing research effort rather than a final solution. Future work will focus on:
This repository will be regularly updated with newer and better models as research progresses.
# Prepare RAVDESS dataset
python src/prepare_ravdess.py --dataset_path /path/to/ravdess
# Train using the simplified approach (best performance)
python src/train_simplified.py \
--dataset_root data/prepared_dataset \
--epochs 50 \
--batch_size 16 \
--learning_rate 1e-4
# For quick training, use the optimal script
bash train_optimal.sh
If you encounter problems installing PyAudio:
brew install portaudio && pip install pyaudiosudo apt-get install python3-pyaudiopip install pipwin && pipwin install pyaudioIf you're experiencing issues with GPU acceleration:
python -c "import torch; print(torch.cuda.is_available())"--device cpu flag to training scripts--batch_size 8If the project doesn't seem to find certain files or directories:
src/check_project.py to verify the project structureThis project is licensed under the MIT License - see the LICENSE file for details.
29 commits
Python
95.9%
Shell
4.1%
Deep learning system for emotion recognition from speech, achieving 50.5% accuracy on 8-class classification using transformer architecture and real-time analysis
2
stars
29
commits
Python
primary language
Apr 22, 2025
updated
This project demonstrates:
This challenging project involves classifying speech into 8 distinct emotions. While commercial systems often focus on 3-4 emotions, this system achieves impressive results across all 8 emotion classes, outperforming random chance (12.5%) by 4× with 50.5% accuracy.
Confusion matrix showing the model's performance across 8 emotion classes. Note the strong performance on Neutral (72%) and Calm (63%) emotions, with most confusion occurring between acoustically similar emotions like Happy/Surprised.
Training progression showing steady improvement from 22.3% in epoch 1 to the final 50.5% accuracy over 50 epochs, demonstrating stable learning without overfitting.
Distribution of emotions in the RAVDESS dataset, showing balanced representation across all 8 emotion classes.
| Model | Accuracy | F1-Score | Training Time | Key Features |
|---|---|---|---|---|
| Simplified (Best) | 50.5% | 0.48 | ~1h | Error-resistant architecture, 4 transformer layers |
| Ultimate | 33.3% | 0.32 | ~5h | Complex transformer architecture |
| Enhanced | 31.5% | 0.30 | ~3h | Attention mechanisms |
| Base | 29.7% | 0.28 | ~2h | Initial CNN implementation |
Confusion Matrix Highlights:
• Neutral emotions recognized with highest accuracy (72%)
• Most confusion between Calm/Neutral and Happy/Surprised pairs
• Angry and Sad emotions identified with moderate accuracy
• Disgust most frequently misclassified
Classification Report:
precision recall f1-score support
neutral 0.67 0.72 0.69 40
calm 0.58 0.63 0.60 40
happy 0.53 0.51 0.52 40
sad 0.61 0.57 0.59 40
angry 0.48 0.52 0.50 40
fearful 0.45 0.41 0.43 40
disgust 0.39 0.41 0.40 40
surprised 0.42 0.38 0.40 40
accuracy 0.505 320
macro avg 0.52 0.52 0.52 320
weighted avg 0.52 0.51 0.50 320
This project features a comprehensive series of Jupyter notebooks documenting the iterative model development process:
Initial CNN-based approach established a strong baseline with:
Building on the base model, incorporated:
Complex architecture that pushed the boundaries with:
Best-performing model proved that focused architectural design beats complexity:
Each notebook contains comprehensive documentation, visualizations, and performance analyses that demonstrate the research process and technical insights.
The system can recognize the following 8 emotions from speech:
# Clone the repository
git clone https://github.com/vatsalmehta/speech-emotion-recognition.git
cd speech-emotion-recognition
# Install dependencies
pip install -r requirements.txt

The project includes an interactive GUI application for real-time speech emotion analysis with the following features:
# Run the real-time GUI
./run_gui.sh
# Or run the terminal-based demo
python src/interactive_demo.py
This launches the interactive application where you can speak and see emotions detected in real-time. The application requires Python with tkinter support.
The project includes a system verification script to check if all necessary components are installed:
# Make the script executable
chmod +x src/check_project.py
# Run the verification
python src/check_project.py
This project uses the RAVDESS dataset (Ryerson Audio-Visual Database of Emotional Speech and Song). Follow these steps precisely:
Download the Dataset Files:
# Create dataset directory
mkdir -p dataset_raw
cd dataset_raw
Option A: Download Everything at Once (Recommended)
unzip 1188976.zip
Option B: Download Individual Files
# Download only the Audio Speech file (208.5 MB)
wget https://zenodo.org/record/1188976/files/Audio_Speech_Actors_01-24.zip
unzip Audio_Speech_Actors_01-24.zip
Verify Dataset Structure: The extracted dataset should have the following structure:
dataset_raw/
└── Audio_Speech_Actors_01-24/
├── Actor_01/
│ ├── 03-01-01-01-01-01-01.wav
│ ├── 03-01-01-01-01-02-01.wav
│ └── ... (more audio files)
├── Actor_02/
│ ├── 03-01-01-01-01-01-02.wav
│ └── ... (more audio files)
└── ... (Actor_03 through Actor_24 folders)
Process the Dataset for Training:
# Return to project root first if needed
cd ..
# Run the dataset preparation script
python src/prepare_ravdess.py \
--dataset_path dataset_raw/Audio_Speech_Actors_01-24 \
--output_path processed_dataset \
--train_ratio 0.7 \
--val_ratio 0.15 \
--test_ratio 0.15
Verify Processed Dataset:
# Check processed dataset structure
ls -la processed_dataset
# You should see train, val, and test directories with organized audio files
# Each file will be labeled with its emotion category
RAVDESS audio files follow this naming convention:
03-01-04-01-02-01-12.wav means:
The processing script handles this naming convention automatically to extract emotions and organize files.
IMPORTANT: The raw dataset (~25.6GB) and processed audio files are deliberately excluded from this repository due to their size. You must follow the steps above to prepare the dataset locally.
Pre-trained models are not included in this repository due to their large size. After training your own models using the instructions below, they will be saved in the models/ directory.
To use a specific model for inference:
# Run inference with your trained model
python src/inference.py --model_path models/ravdess_simple/best_model.pt
The development process involved creating and refining several model architectures, each documented in detail through the project notebooks:
Base Model (29.7% accuracy)
Enhanced Model (31.5% accuracy)
Ultimate Model (33.3% accuracy)
Simplified Model (50.5% accuracy)
The simplified model proved that architectural focus and training stability were more important than complexity for this task.
Analyzing the confusion matrix revealed:
These insights informed targeted improvements in the model architecture.
This project showcases an iterative approach to deep learning model development:
Each iteration provided insights that informed the next development phase, ultimately leading to the best-performing model with a 50.5% accuracy on this challenging 8-class task.
While the current Simplified Model achieves strong results at 50.5% accuracy, this represents an ongoing research effort rather than a final solution. Future work will focus on:
This repository will be regularly updated with newer and better models as research progresses.
# Prepare RAVDESS dataset
python src/prepare_ravdess.py --dataset_path /path/to/ravdess
# Train using the simplified approach (best performance)
python src/train_simplified.py \
--dataset_root data/prepared_dataset \
--epochs 50 \
--batch_size 16 \
--learning_rate 1e-4
# For quick training, use the optimal script
bash train_optimal.sh
If you encounter problems installing PyAudio:
brew install portaudio && pip install pyaudiosudo apt-get install python3-pyaudiopip install pipwin && pipwin install pyaudioIf you're experiencing issues with GPU acceleration:
python -c "import torch; print(torch.cuda.is_available())"--device cpu flag to training scripts--batch_size 8If the project doesn't seem to find certain files or directories:
src/check_project.py to verify the project structureThis project is licensed under the MIT License - see the LICENSE file for details.
29 commits
Python
95.9%
Shell
4.1%