🙏 Special thanks to my neighbor's dog for the relentless QA testing. 🐕
Real-time dog bark detection running on a Raspberry Pi. Uses Google's YAMNet audio classifier to identify barks, records smart audio clips when triggered, and publishes events to Supabase for storage and monitoring.
Mic → YAMNet (TFLite) → BarkRecorder → EventPublisher
├── audio_store() → local WAV + Supabase Storage
└── event_publish() → Supabase events table
- Runs 24/7 on a Raspberry Pi with no cloud dependency for detection
- YAMNet classifies 8 dog sound types: bark, yip, howl, bow-wow, growl, whimper, etc.
- Smart recording: 30-second minimum clip, extends by 30 s whenever a bark is detected in the last 10 s
- All clips saved locally as WAV files — Supabase upload is best-effort
- Two-primitive event API:
event_publishfor any event,audio_storefor audio clips - Heartbeat event every 60 s for uptime monitoring
- SSH-based deploy and sync scripts — no Docker required
# From your laptop, inside the repo
export PI_USER=pi
export PI_HOST=raspberrypi.local # or the Pi's IP address
./deploy_to_pi.shThis rsyncs the code, installs system packages, creates a venv, downloads the
YAMNet model, and sets up the recordings/ directory.
ssh pi@raspberrypi.local
cd ~/dog-bark
cp .env.example .env
nano .env # add SUPABASE_URL and SUPABASE_KEY./run.sh./sync_to_pi.sh # fast rsync, does not reinstall packagescreate table events (
id bigserial primary key,
created_at timestamptz default now(),
device_id text,
event_type text not null,
payload jsonb default '{}'
);Create a bucket called bark-clips (or set STORAGE_BUCKET in .env).
Recommended settings: private, 500 MB file limit, audio/wav MIME type.
event_type |
When | Example payload fields |
|---|---|---|
audio_stored |
Bark recording saved | duration, confidence, bark_count, filename, clip_url |
heartbeat |
Every 60 s while running | status: "running" |
Add your own by calling publisher.event_publish("my_event", {...}) anywhere.
dog-bark/
├── src/
│ ├── main.py # Entry point — detection loop
│ ├── config/settings.py # All config, env-var overrides
│ ├── audio/
│ │ ├── stream.py # Continuous 16 kHz capture (circular buffer)
│ │ └── recorder.py # Smart recording with extend-on-bark logic
│ ├── detection/
│ │ └── yamnet.py # YAMNet TFLite wrapper (falls back to dummy)
│ └── storage/
│ └── supabase_client.py # EventPublisher: event_publish + audio_store
├── tests/
├── deploy_to_pi.sh # Full initial deployment via rsync + setup
├── sync_to_pi.sh # Fast code-only rsync
├── setup_pi.sh # Pi-side setup (venv, deps, YAMNet model)
├── run.sh # Start the detector
├── .env.example # Environment variable template
└── requirements.txt
All settings are controlled via environment variables in .env.
See .env.example for the full list with descriptions.
| Variable | Default | Description |
|---|---|---|
SUPABASE_URL |
— | Required. Supabase project URL |
SUPABASE_KEY |
— | Required. Anon or service role key |
DEVICE_ID |
— | Optional label written to every event row |
DETECTION_THRESHOLD |
0.7 |
Confidence threshold for triggering recording |
STORAGE_BUCKET |
bark-clips |
Supabase Storage bucket name |
TABLE_NAME |
events |
Supabase table for events |
LOCAL_BACKUP_DIR |
recordings |
Local WAV backup directory |
YAMNET_MODEL_PATH |
yamnet.tflite |
Path to the TFLite model file |
bark detected (conf > threshold)
│
└─ start recording
│
▼
[ 0 s – 20 s ] minimum recording window
│
▼
[ 20 s – 30 s ] extension window — checks for recent bark
│
├─ bark in last 10 s? → extend end time by 30 s, repeat
│
└─ silence? → stop, save clip
Tested on Raspberry Pi 4 (2 GB) with a USB microphone. Pi 3B+ also works but inference is slower (~2–3 s per chunk vs ~0.5 s on Pi 4).
If the YAMNet model is not found at startup the detector falls back to an energy-based dummy detector so the recording pipeline can be tested without the model file.
MIT