How jnr-10/speechemotionassistant-audioml works
1. Overall shape
- This repository has two main planes: an offline ML training/evaluation pipeline and an online Flask-based inference/assistant application.
- The offline side produces serialized TensorFlow/Keras models and preprocessing artifacts stored under models/.
- The online side serves a browser UI, accepts audio, runs emotion inference, and optionally calls Gemini for natural-language responses.
2. User-facing application layer
- app.py is the central web entrypoint.
- templates/index.html provides the main browser interface: audio capture/upload, live emotion display, language selection, and session/report interactions.
- The README indicates WebSocket-style real-time updates and live visualization, so the frontend is not just a static form; it supports streaming-style interaction with the backend.
3. Audio ingestion boundary
- Audio enters the system in two ways:
- Microphone/live recording through the voice assistant flow.
- Uploaded audio files via the analysis API.
- voice_assistant.py likely handles microphone/audio conversion and related orchestration.
- This is the first major boundary: raw audio is normalized before any ML processing.
4. Signal preprocessing and feature extraction
- data_loader.py is responsible for loading audio and transforming it into mel spectrogram features.
- The repo’s documented pipeline is: raw audio → resampling to 22,050 Hz → mel spectrogram with 128 bands and ~130 frames → model input.
- The preprocessing stage is a critical architectural boundary because every model variant expects the same feature representation, with saved scalers/encoders used for consistent inference.
5. Emotion inference subsystem
- model.py defines the CNN-LSTM architecture used for speech emotion recognition.
- Pre-trained variants are already packaged in models/:
- CNN
- LSTM
- CNN-LSTM hybrid
- Associated artifacts include .keras weights plus label_encoder.pkl, scaler.pkl, and model-specific config/encoder/scaler files. These artifacts form the inference bundle.
6. Prediction outputs
- The model outputs one of the supported emotion classes: neutral, calm, happy, sad, angry, fearful, disgust, surprised.
- The backend uses these predictions to drive:
- per-chunk emotion analysis
- confidence display
- session emotion trends
- summary statistics for reports
7. LLM / assistant integration
- llm_service.py is the boundary to Google Gemini API.
- Emotion results are passed into the LLM layer to generate context-aware, empathetic responses.
- This is a separate subsystem from emotion recognition: the ML model classifies speech, while Gemini turns that classification into conversational assistance.
8. Reporting subsystem
- report_generator.py produces PDF session reports.
- Based on the README, reports include charts, emotion breakdowns, and session insights.
- This subsystem consumes accumulated session data rather than single inference results, so it sits downstream of the analysis pipeline.
9. API surface
- The backend exposes endpoints for:
- audio analysis
- chat/assistant interaction
- system status
- supported languages
- PDF report generation
- These endpoints are the integration layer between the frontend, the emotion model, the LLM service, and the report generator.
10. Training and evaluation pipeline
- train.py is the local training entrypoint.
- The notebooks under notebooks/ and the top-level .ipynb files are the research/training environment for model development and benchmarking.
- This offline workflow uses combined emotion datasets such as RAVDESS and CREMA-D, plus augmentation, to produce the artifacts stored in models/.
11. Configuration and environment
- config.py centralizes audio/model parameters such as sample rate, clip duration, mel band count, epochs, and batch size.
- .env.example shows that runtime secrets, especially the Gemini API key, are injected through environment variables rather than hardcoded.
- requirements.txt defines the Python stack, with TensorFlow and Flask as the main runtime dependencies.
12. Data/artifact flow for architecture diagrams
- The key flow to draw is:
- browser or uploaded audio → Flask endpoint / voice assistant layer → preprocessing (data_loader.py) → emotion model (model.py + saved artifacts) → emotion result
- then optionally → llm_service.py for Gemini response
- and/or → report_generator.py for PDF output
- Training is a separate flow:
- dataset files/notebooks → feature extraction/preprocessing → train.py / notebook training → saved model artifacts in models/
13. Important architectural boundary
- The repository mixes runtime inference and research/training assets in one codebase, but they should be drawn as separate subsystems.
- The runtime application depends on prebuilt artifacts; it does not require retraining to function.
- The notebooks and plots are supporting assets for experimentation, evaluation, and documentation rather than part of the production request path.
Main entry points: app.py App · train.py Training · model.py SER Model · config.py Config
Components 16
Runtime App
Online Flask app, audio ingestion, inference, assistant responses, and reports.
- App · Central web entrypoint for the browser UI and API surface.
app.py - Web UI · Browser interface for audio capture, emotion display, language selection, and reports.
templates/index.html - Voice Assistant · Handles microphone/live recording and audio normalization for the online flow.
voice_assistant.py - Gemini Layer · Wraps the Gemini API to turn emotion results into conversational responses.
llm_service.py - Reports · Produces session reports with charts, emotion breakdowns, and insights.
report_generator.py - Config · Centralizes audio, model, and training parameters.
config.py - Python Stack · Declared runtime dependencies for Flask, TensorFlow, and supporting libraries.
requirements.txt
ML Pipeline
Preprocessing and emotion classification used by runtime inference and offline training.
- Feature Loader · Loads audio and converts it into mel-spectrogram features for inference and training.
data_loader.py - SER Model · Defines the speech emotion recognition architecture.
model.py - Model Bundles · Serialized Keras models plus encoders, scalers, and configs used at runtime.
models
Research & Artifacts
Training notebooks, datasets, and saved model bundles.
- Training · Local training entrypoint for building and evaluating emotion models.
train.py - Colab Train · Research notebook for model training in Colab.
SER_Training_Colab.ipynb - Optimized Models · Notebook for model optimization and benchmarking.
SER_Optimized_Models.ipynb - Multi-Dataset · Notebook covering multi-dataset training experiments.
notebooks/SER_Multi_Dataset_Training.ipynb - Training Colab · Notebook for training workflows in Colab.
notebooks/SER_Training_Colab.ipynb - Feature Data · Precomputed dataset metadata and derived feature assets.
features/ravdess_mel_metadata.csv
Connections 20
- Web UI → App: user input · Browser interactions are handled by the Flask app.
- Voice Assistant → App: audio upload · Live audio is routed into the application backend.
- App → Feature Loader: preprocess · Incoming audio is normalized into model features.
- Feature Loader → SER Model: features · Mel features are fed into the emotion model.
- SER Model → Model Bundles: weights · The runtime uses packaged model artifacts and encoders.
- SER Model → App: predictions · Emotion labels and confidence scores return to the web app.
- App → Gemini Layer: context · Predicted emotion is sent to Gemini for assistant responses.
- Gemini Layer → App: reply · Generated text is returned for display in the assistant flow.
- App → Reports: session data · Accumulated analysis results are converted into PDF reports.
- Reports → App: pdf · Generated reports are exposed through the application.
- Config → Voice Assistant: audio params · Recording and normalization use shared audio settings.
- Config → Feature Loader: feature params · Feature extraction uses shared sample-rate and mel settings.
- Config → Training: train params · Training uses shared epochs, batch size, and clip settings.
- Training → Feature Data: data · Training and evaluation consume dataset metadata and derived features.
- Training → SER Model: builds · Training produces the SER architecture and learned parameters.
- Colab Train → Training: experiments · Notebook workflows mirror or extend the training entrypoint.
- Optimized Models → Training: benchmarks · Optimization experiments inform the packaged model variants.
- Multi-Dataset → Training: datasets · Multi-dataset experiments feed model development.
- Training Colab → Training: colab flow · Notebook-based training supports the offline pipeline.
- Python Stack → App: runtime deps · The Flask application depends on the declared Python stack.