A real-time sneeze detection application that listens to your microphone and responds with "bless you" spoken aloud in your chosen language.
Stack: React + TypeScript frontend, Python + FastAPI backend, TensorFlow/Keras CNN for sneeze detection, WebSockets for real-time communication.
- Browser captures microphone audio via AudioWorklet (dedicated audio thread)
- Raw PCM audio streams over WebSocket to the FastAPI backend
- Backend maintains a 1-second sliding window, runs CNN inference every 100ms
- On sneeze detection, backend sends the "bless you" phrase back to the client
- Browser speaks the phrase aloud using the Web Speech API
Latency target: < 200ms from sneeze to spoken response.
- Python 3.11+
- Node.js 20+
- Docker (optional)
Download the ESC-50 dataset and organize it:
cd backend
pip install -r requirements.txt
python scripts/download_dataset.pyThis downloads ESC-50, extracts sneeze and negative samples into data/sneeze/ and data/not_sneeze/.
Optionally, record your own sneezes for better personalization:
python scripts/download_dataset.py --record --n-recordings 10cd backend
python -m app.model_trainerModel saved to app/models/sneeze_model.keras (~1-2MB).
The app also works without a trained model using an energy-based fallback detector (less accurate but functional for demo purposes).
Evaluated on 2,598 test samples (580 sneeze, 2,018 not-sneeze):
| Metric | Not Sneeze | Sneeze |
|---|---|---|
| Precision | 82% | 50% |
| Recall | 90% | 33% |
| F1-Score | 86% | 40% |
Overall accuracy: 78% | Weighted F1: 0.76
Threshold analysis (sneeze class):
| Threshold | Precision | Recall |
|---|---|---|
| 0.5 | 49.9% | 33.1% |
| 0.6 | 58.0% | 18.1% |
| 0.7 (default) | 57.3% | 8.8% |
Status: The model needs improvement — sneeze recall is low, meaning many sneezes go undetected. The dataset (3,880 sneeze samples) is heavily augmented from a small base. Priority areas: more diverse real sneeze recordings, better negative sample curation, and architecture tuning.
cd backend
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000cd frontend
npm install
npm run devOpen http://localhost:5173 in your browser.
docker-compose up --buildThen open http://localhost in your browser.
- Open the app in your browser
- Click "Start Listening" and grant microphone permission
- Select your preferred language from the dropdown (18 languages supported)
- Adjust sensitivity slider if needed (lower = more detections, higher = fewer false positives)
- Sneeze near your microphone
- Hear "bless you" spoken in your chosen language
| Language | Phrase | Literal Translation |
|---|---|---|
| English | Bless you! | Bless you |
| Spanish | Salud! | Health! |
| German | Gesundheit! | Health! |
| French | A vos souhaits ! | To your wishes! |
| Italian | Salute! | Health! |
| Portuguese | Saude! | Health! |
| Japanese | お大事に | Take care of yourself |
| Korean | 에취! 감기 조심하세요 | Be careful of colds |
| Chinese | 有人想你了 | Someone is thinking of you |
| Arabic | يرحمك الله | May God have mercy on you |
| Russian | Будь здоров! | Be healthy! |
| Hindi | सत्य है! | It is truth! |
| Turkish | Cok yasa! | Live long! |
| Dutch | Gezondheid! | Health! |
| Polish | Na zdrowie! | To health! |
| Greek | Γείτσες! | Health! |
| Swahili | Afya! | Health! |
| Hebrew | לבריאות! | To health! |
Browser Server
┌──────────────────┐ ┌──────────────────┐
│ AudioWorklet │ │ FastAPI │
│ (audio thread) │ │ │
│ │ │ │ ┌────────────┐ │
│ ▼ │ WebSocket│ │ Ring Buffer │ │
│ PCM Float32 ───┼───────────►│ │ (1s window) │ │
│ │ │ └──────┬─────┘ │
│ SpeechSynth ◄──┼────────────│ ▼ │
│ (TTS output) │ JSON │ ┌────────────┐ │
│ │ events │ │ CNN Model │ │
│ Canvas │ │ │ (inference) │ │
│ (visualizer) │ │ └──────┬─────┘ │
└──────────────────┘ │ ▼ │
│ sneeze_detected │
└──────────────────┘
cd backend
pytest tests/ -vcd backend
python scripts/evaluate_model.pysneeze-bless-you/
├── backend/
│ ├── app/
│ │ ├── main.py # FastAPI entry point
│ │ ├── websocket_handler.py # WebSocket audio processing
│ │ ├── sneeze_detector.py # CNN model architecture + inference
│ │ ├── model_trainer.py # Training pipeline
│ │ ├── audio_features.py # Mel spectrogram + feature extraction
│ │ ├── bless_you.py # Multi-language phrases
│ │ ├── config.py # App configuration
│ │ └── models/ # Saved trained model
│ ├── data/ # Training data
│ ├── scripts/ # Dataset download, augmentation, evaluation
│ ├── tests/ # Backend tests
│ └── requirements.txt
├── frontend/
│ ├── public/
│ │ └── audio-processor.worklet.js # AudioWorklet (served as static)
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── hooks/ # Custom hooks (audio, WebSocket, TTS)
│ │ ├── utils/ # Language config, audio buffer
│ │ ├── styles/ # CSS
│ │ ├── App.tsx # Main application
│ │ └── main.tsx # Entry point
│ └── package.json
├── docker-compose.yml
└── README.md
- HTTPS requirement:
getUserMediaonly works on HTTPS or localhost. - Browser support: AudioWorklet requires Chrome 66+, Firefox 76+, Safari 14.1+, Edge 79+.
- False positives: Default threshold (0.7) prioritizes precision over recall. Adjust via the sensitivity slider.
- Model size: Custom CNN ~1-2MB. Fits easily in a container image.