saansho/speech_emotion_recognition
Speech Emotion Recognition

A simple speech emotion recognition project that predicts the emotional state of a speaker from a WAV audio file.
The app uses:
- A pre-trained TensorFlow/Keras model stored in
models/final_industry_ser_model.keras - Audio preprocessing and MFCC feature extraction in
src/ - A Streamlit user interface in
app/app.py
What this project does
- Loads an audio file in WAV format.
- Trims silence and normalizes the audio.
- Extracts MFCC features from the audio signal.
- Runs the features through a trained model.
- Shows the predicted emotion and confidence score in the web interface.
Project structure
app/— Streamlit interface and file uploadermodels/— Pre-trained TensorFlow/Keras model filesrc/— Python modules for preprocessing, feature extraction, and predictiondataset/— optional audio dataset for testing or experimentationoutputs/— generated graphs, reports, or other output filesrequirements.txt— project dependenciesmain.py— experimental pipeline script for batch processing audio files
Supported emotions
The model predicts one of these emotions:
angryfearfulhappyneutralsad
Requirements
This project is tested with:
- Python 3.10+ or 3.11
tensorflow==2.16.2streamlit==1.57.0librosa==0.11.0numpy==1.26.4pandas==3.0.3scikit-learn==1.8.0soundfile==0.13.1
Note: For Hugging Face Spaces and Linux deployment, usetensorflow==2.16.2. Mac-specific packages liketensorflow-macosandtensorflow-metalare not required for Spaces.
Setup
- Create and activate a virtual environment:
python3.11 -m venv venv
source venv/bin/activate- Install dependencies:
python -m pip install --upgrade pip setuptools wheel
pip install -r requirements.txtRun the app
Start the Streamlit interface:
streamlit run app/app.pyThen open the URL shown by Streamlit in your browser.
Deploy to Hugging Face Spaces
This repository supports two deployment options.
Option 1: Native Streamlit Space
- Create a new Hugging Face Space.
- Choose
Streamlitas the SDK. - Push this repository to the Space.
- Ensure
requirements.txt,app.py, andmodels/final_industry_ser_model.kerasare included.
Hugging Face should detect the root app.py wrapper and run the Streamlit app automatically.
Option 2: Docker Space
- Create a new Hugging Face Space.
- Choose
Dockeras the SDK. - Push this repository to the Space.
The provided Dockerfile installs ffmpeg and runs Streamlit on port 7860, so no further Docker configuration is required.
Deploy-ready commands
Use this sequence to push the repository and deploy it on Hugging Face Spaces:
git add .
git commit -m "Deploy Speech Emotion Recognition to Hugging Face Spaces"
git push origin mainThen create a new Hugging Face Space and choose one of these options:
StreamlitSDK: the rootapp.pywrapper will be detected automaticallyDockerSDK: the existingDockerfileinstallsffmpegand runs the app on port7860
If you want to build locally first, make sure Docker Desktop is running and then use:
docker build -t ser-app .
docker run -p 7860:7860 ser-appIf the Docker daemon is not running, the build will fail with a socket connection error.
How to use the app
- Upload a
.wavaudio file using the file uploader. - Click the Predict Emotion button.
- View the predicted emotion and confidence score.
Notes for developers
src/preprocessing.pyhandles audio loading, trimming, normalization, and length standardization.src/feature_extraction.pyextracts MFCC features from the audio.src/prediction.pyloads the model and returns the predicted emotion and confidence.main.pyis an experimental script for batch processing audio files fromdataset/.
Future improvements
- Add support for more audio file formats (MP3, FLAC)
- Add real-time microphone recording
- Expand emotion labels beyond the current five classes
- Add model evaluation and result logging
License
This project is available under the MIT License.
