Skip to content

cristim67/audio-analysis-platform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

37 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Audio Analysis Platform - Real-Time Signal Processing

Real-time audio analysis platform using ESP32, FastAPI, and React. The system captures audio data from a microphone connected to ESP32, processes the signal in real-time, and displays detailed analysis in a modern web dashboard.

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         ESP32 Device                            β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Microphone β†’ ADC β†’ FFT Analysis β†’ WebSocket             β”‚   β”‚
β”‚  β”‚  - Sample Rate: 16kHz                                    β”‚   β”‚
β”‚  β”‚  - FFT Samples: 128                                      β”‚   β”‚
β”‚  β”‚  - Frequency Bands: 9 (0-8kHz)                           β”‚   β”‚
β”‚  β”‚  - Real-time filtering & SNR calculation                 β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚ WebSocket (WSS)
                             β”‚ Port 443
                             β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    FastAPI Backend Server                      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  WebSocket Manager                                       β”‚  β”‚
β”‚  β”‚  - /ws (ESP32 endpoint)                                  β”‚  β”‚
β”‚  β”‚  - /ws-dashboard (Frontend endpoint)                     β”‚  β”‚
β”‚  β”‚  - Real-time data broadcasting                           β”‚  β”‚
β”‚  β”‚  - Connection management                                 β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  REST API                                                β”‚  β”‚
β”‚  β”‚  - /api/info (System information)                        β”‚  β”‚
β”‚  β”‚  - CORS enabled                                          β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚ WebSocket (WSS)
                             β”‚ HTTP/HTTPS
                             β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    React Frontend (Vite)                       β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  Real-Time Dashboard                                     β”‚  β”‚
β”‚  β”‚  - Waveform Charts (RAW & FILTERED)                      β”‚  β”‚
β”‚  β”‚  - Spectrogram Visualization                             β”‚  β”‚
β”‚  β”‚  - Frequency Bands Display                               β”‚  β”‚
β”‚  β”‚  - Signal Quality Metrics (SNR)                          β”‚  β”‚
β”‚  β”‚  - Filter Controls (Low/High/Band-Pass)                  β”‚  β”‚
β”‚  β”‚  - Measurement Log                                       β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“¦ Components

ESP32 Firmware (arduino/microphone_websocket.ino)

  • Hardware Setup: ESP32 + Pre-Amplifier + Electret Microphone

Hardware Setup

  • Features:
    • Audio capture at 16kHz
    • FFT analysis with 9 frequency bands
    • Real-time filtering (Low-Pass, High-Pass, Band-Pass)
    • Signal quality metrics: SNR, MSE, and PSNR calculations
    • Noise gate and automatic calibration
    • WebSocket communication with backend

Backend Server (server/)

  • Framework: FastAPI (Python)
  • Features:
    • WebSocket server for ESP32 and Dashboard
    • Real-time broadcast to all dashboards
    • Connection management
    • REST API for system information
    • Structured logging

Backend Swagger UI

http://localhost:8000/docs

Frontend Dashboard (client/)

  • Framework: React + TypeScript + Vite
  • UI: Tailwind CSS
  • Features:
    • Real-time visualizations (waveform, spectrogram)
    • Audio filter controls (cutoff frequencies, voice boost)
    • Signal quality metrics (SNR, MSE, PSNR)
    • Measurement log
    • Connection status (Dashboard & ESP32)

Frontend Dashboard

Frontend Dashboard 2

πŸš€ Running with Docker

Prerequisites

  • Docker
  • Docker Compose

Full Setup

# Clone the repository
git clone <repository-url>
cd psad-project

# Run all services
docker-compose up -d

# Check status
docker-compose ps

# View logs
docker-compose logs -f

Access

Stop

docker-compose down

πŸ”§ Manual Configuration

Backend (FastAPI)

cd server
python -m venv venv
source venv/bin/activate  # Linux/Mac
# or
venv\Scripts\activate  # Windows

pip install -r requirements.txt
uvicorn app:app --host 0.0.0.0 --port 8000 --reload

Frontend (React)

cd client
npm install
npm run dev

ESP32

  1. Open arduino/microphone_websocket.ino in Arduino IDE
  2. Install required libraries:
    • WiFi (built-in)
    • WebSocketsClient (from Links2004)
  3. Configure WiFi credentials in code
  4. Configure WebSocket host/port
  5. Upload to ESP32

πŸ“Š Data and Metrics

Data sent by ESP32

  • volume: RAW amplitude (0-100%)
  • volumeFiltered: Filtered amplitude (0-100%)
  • peakToPeak: Peak-to-peak (ADC units)
  • bands: Array with 9 FFT bands (RAW)
  • bandsFiltered: Array with 9 FFT bands (FILTERED)
  • snrRaw: Signal-to-Noise Ratio RAW (dB)
  • snrFiltered: Signal-to-Noise Ratio FILTERED (dB)
  • mse: Mean Squared Error between RAW and FILTERED bands (lower is better)
  • psnr: Peak Signal-to-Noise Ratio (dB, higher is better)
  • min, max, avg: ADC values

Signal Quality Metrics

  • SNR (Signal-to-Noise Ratio): Measures signal quality by comparing signal energy to noise floor
    • RAW SNR: Quality of unfiltered signal
    • FILTERED SNR: Quality after filtering
  • MSE (Mean Squared Error): Average squared difference between RAW and FILTERED frequency bands
    • Lower values indicate better preservation of original signal characteristics
  • PSNR (Peak Signal-to-Noise Ratio): Logarithmic measure of signal quality
    • Higher values (typically >30 dB) indicate better signal quality
    • Formula: PSNR = 20 Γ— log₁₀(MAX_VALUE / √MSE)

Available Filters

  • Low-Pass: Removes frequencies above cutoff
  • High-Pass: Removes frequencies below cutoff
  • Band-Pass: Keeps frequencies between 2 cutoffs
  • Voice Boost: Amplification for vocal bands (500Hz-2500Hz)

πŸ› οΈ Technologies

  • ESP32: WiFi-enabled microcontroller
  • FastAPI: Modern Python backend
  • React + TypeScript: Reactive frontend
  • WebSocket: Bidirectional real-time communication
  • Tailwind CSS: Modern styling
  • Vite: Fast build tool for frontend
  • Docker: Containerization and deployment

πŸ“ Project Structure

psad-project/
β”œβ”€β”€ arduino/              # ESP32 Firmware
β”‚   └── microphone_websocket.ino
β”œβ”€β”€ server/               # FastAPI Backend
β”‚   β”œβ”€β”€ app.py
β”‚   β”œβ”€β”€ routes/          # API & WebSocket routes
β”‚   β”œβ”€β”€ services/        # Business logic
β”‚   β”œβ”€β”€ config/          # Configuration
β”‚   └── requirements.txt
β”œβ”€β”€ client/              # React Frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/  # React components
β”‚   β”‚   β”œβ”€β”€ hooks/      # Custom hooks
β”‚   β”‚   └── services/   # API utilities
β”‚   └── package.json
β”œβ”€β”€ docker-compose.yml   # Docker orchestration
β”œβ”€β”€ Dockerfile.backend   # Backend container
β”œβ”€β”€ Dockerfile.frontend  # Frontend container
└── README.md

πŸ” Environment Variables

Backend

No environment variables required (configured in code)

Frontend

Create .env in client/:

VITE_API_URL_FASTAPI=wss://your-backend-url.com

πŸ“ˆ Performance

  • Sample Rate: 16kHz
  • FFT Resolution: 128 samples (~125Hz per bin)
  • Update Rate: 350ms (configurable)
  • Frequency Range: 0-8kHz
  • Bands: 9 bands optimized for human voice

πŸ› Troubleshooting

ESP32 not connecting

  • Check WiFi credentials
  • Check WebSocket host/port
  • Verify backend is running

Frontend not receiving data

  • Check WebSocket connection in browser console
  • Verify ESP32 is sending data
  • Check CORS settings in backend

Docker issues

  • Verify ports 3000 and 8000 are available
  • Check logs: docker-compose logs

πŸ“„ License

See LICENSE for details.

About

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors