Detecting distress sounds passively using Qdrant Edge — no cloud, no raw audio upload, no manual SOS button.
This system continuously monitors in-car audio and detects distress sounds (screams, glass breaking, tire screeches, collisions) using on-device vector similarity search powered by Qdrant Edge. When distress is confirmed, an alert is sent via Telegram.
USB Mic → YAMNet (1024-d embeddings) → Qdrant Edge ANN Search → Telegram Alert
Privacy guarantee: Raw audio never leaves the device. Only outbound call is the Telegram alert.
python3 -m venv venv && source venv/bin/activate
pip install -r requirements.txtcp .env.example .env
# Edit .env with your Telegram bot token and chat IDpython scripts/indexing_sounds.pyThis downloads the ESC-50 dataset, incorporates any custom samples from data/custom/, generates YAMNet embeddings for all distress + negative sounds (with engine noise augmentation for custom samples), and builds the local Qdrant Edge shard (~6 MB).
python scripts/test_detection.pyVerifies Telegram connectivity, loads the shard, and runs synthetic audio through the detector.
python main.pyAll tunable parameters live in .env:
| Variable | Default | Description |
|---|---|---|
TELEGRAM_BOT_TOKEN |
— | Your bot token from @BotFather |
TELEGRAM_CHAT_ID |
— | Your personal or group chat ID |
SIMILARITY_THRESHOLD |
0.80 |
Cosine similarity cutoff (0–1) |
SMOOTHING_HITS_REQUIRED |
3 |
Hits needed within window to alert |
SMOOTHING_WINDOW_SECONDS |
5 |
Time window for hit counting |
ALERT_COOLDOWN_SECONDS |
30 |
Min seconds between consecutive alerts |
CHUNK_DURATION_SECONDS |
1 |
Audio window size |
OVERLAP_SECONDS |
0.5 |
Overlap between windows |
To prevent false alarms in noisy environments, the system uses custom per-class overrides:
- Amplitude Gating: The system strictly ignores low-volume ambient noises (like AC or engine hums) before they even reach the AI model.
- Strict Mode (
car_horn,siren): Broadband noises like wind can mimic sirens/horns. These require a very high similarity score (e.g.,0.90or0.96) to trigger. - Sensitive Mode (
scream,gunshot): Since emergency human screams and gunshots can be brief or muffled, they are highly sensitive (score0.80to0.85) and require fewer consecutive hits to alert you instantly.
Alert sounds (trigger SOS):
scream/crying→ severity: high / medium (includes custom datasets)glass_break→ severity: highcollision/gunshot→ severity: high (includes custom datasets)siren→ severity: highcar_horn→ severity: medium
Negative sounds (do NOT trigger):
- Normal speech, music, engine noise, ambient sounds
| Component | Technology |
|---|---|
| Vector database | Qdrant Edge (qdrant-edge-py) |
| Audio embedding | YAMNet via TF Hub (1024-d) |
| Audio preprocessing | librosa |
| Audio capture | sounddevice |
| Alert delivery | Telegram Bot API |
| Datasets | ESC-50, custom .wav/.mp3 folders |
qdr-edge/
├── main.py # Entry point
├── requirements.txt
├── .env.example # Config template
├── scripts/
│ ├── index_sounds.py # One-time indexing pipeline
│ └── test_detection.py # End-to-end test
└── src/
├── config.py # Environment config
├── audio_capture.py # Real-time mic capture
├── preprocessor.py # Audio normalization
├── embedder.py # YAMNet wrapper
├── vector_store.py # Qdrant Edge interface
├── detector.py # Detection + smoothing
└── alerter.py # Telegram + console alerts