Dog Barking Detection

Hi all!

Im trying to find a way to detect if my dogs are barking outside. I do have a camera trained on the spot they often bark in, but they also like to hang out in that same spot and sun themselves during the day, so camera detection isnt quite enough.

Other than getting some kind of microphone and “training” it to detect a specific noise, are there any other options ?

No idea, but keen to learn.

Not sure if you have Alexa but you can do this with an alexa routine:

This first part isn’t answering the question directly, but reading this made me think about another entertaining but related post. In this case, a camera with line crossing detection is used, and it’s assumed that when the dogs are in a particular location that they are barking.

Apple’s Siri also has sound recognition and support for detecting barking dogs. Not sure if that will work for you.

While I work in the machine learning field, I haven’t attempted embedded ML models, but have a look at TensorFlow Lite and TinyML that can run on an ESP32. I suspect you might even find pre-trained models. Regardless, there will be some DIY involved.

I’m in the process of doing something similar. My setup is a Raspberry Pi 4 with a 4-channel microphone connected to it. I collected some data, around 30 mins worth of dog bark and trained a simple feed-forward neural network to detect dog barks. The reason for using a 4-channel microphone was to distinguish direction of arrival as well. The problem I’m trying to solve is that we have a neighbor’s dog and when that dog barks, my dog responds back, then they keep barking at each other. To break that cycle, a few dog trainers told us to treat our dog when he doesn’t respond and that works quite well, however when we’re not there, there is no one to reward him and he gets into barking mode. I’m trying to automate this whole thing, detect neighbor’s dog bark using my 4-channel mic, then dispense treats. So far I’ve found this feeder that works with HA: Smart Pet Feeder C1. Once I’m a bit more happy with my setup, I’ll share more details here.

I know you mentioned you’d share this when you were ready but if you have any information that you’re willing to share, I would appreciate it.

I am trying to find a solution to detect and be notified of when my dog is barking, primarily when he is in his kennel. I have a camera set up in his kennel, so the audio stream from that could be used. Just not sure how best to handle the identification of a bark versus other noises. (I have tried solutions using the detected amplitude of the audio, and being notified if over a certain threshold, but would get false notifications.)

I’d certainly be open to setting up a Raspberry Pi to handle the detection if needed.

I’m currently using the Alexa routine method mentioned in a previous reply to this thread, but am hoping for a local solution. Wasn’t sure if what you’re working on could point me in the right direction.

here is my first version: GitHub - mdoulaty/woofalytics: AI Powered Woof Analytics!
it’s not exactly integrated with homeassistant (yet), but should be a good starting point and the integration should be very easy.

While overkill if you just need barking detection, Frigate can now do that if you happen to already have cameras setup.

My use case was slightly different, I needed only the neighbour’s dog’s bark to be detected, and not my own dog’s bark (or any other dogs in the neighbourhood!).

If you use Frigate this is a feature coming in the 0.13 release see the beta release notes for information:

Audio Detectors | Frigate (deploy-preview-6262–frigate-docs.netlify.app)

This is a very interesting discussion, and have the same requirement for detecting my neighbour’s dog’s.
Should it be possible to run Frigate without a camera? So just the audio-bit? Or is this dependent on the camera integration that you know off? (@flyize, @pyrodex)
Any input / ideas on this topic would be warm welcomed!.

Thanks,

I mean if you can create an audio source and present it to Frigate via RTSP I would ASSUME this would work.Its an interesting question to ask over in the Frigate discussions on GH.

I think you need a sound camera which location sounds location,then get which dog is barking

This these have been working well for me. It isn’t AI but it was created with AIs help. Using a max4466 mic and a nodemcu type 8266 with esphome. It picks up short bursts of loud sounds and that’s usually my dog barking. Greta btw. Every level could be changed to suit and or fix for your conditions. So many his/hers FBai/Chatgpt 'cause it was testing code. Much of it may not be needed.

 
globals:

  - id: esphome_sensitivity
    type: float
    initial_value: '36.5'
    restore_value: yes

  - id: esphome_volume
    type: int
 
binary_sensor:

  - platform: ld2410
    has_target:
      name: ld Presence
    has_moving_target:
      name: ld Moving Target
    has_still_target:
      name: ld Still Target
    # out_pin_presence_status:
      # name: out pin presence status 

#his
  - platform: template
    name: "Dog Bark Alert His 90"
    icon: mdi:dog
    lambda: |-
      // Adjust alert threshold (db)
      if (id(esphome_db).state > 90) {
        return true;
      } else {
        return false;
      }
  - platform: template
    name: "Dog Bark Alert His 75"
    icon: mdi:dog
    lambda: |-
      // Adjust alert threshold (db)
      if (id(esphome_db).state > 75) {
        return true;
      } else {
        return false;
      }
  - platform: template
    name: "Dog Bark Alert His 80"
    icon: mdi:dog
    lambda: |-
      // Adjust alert threshold (db)
      if (id(esphome_db).state > 80) {
        return true;
      } else {
        return false;
      }
  - platform: template
    name: "Dog Bark Alert His 95"
    icon: mdi:dog
    lambda: |-
      // Adjust alert threshold (db)
      if (id(esphome_db).state > 95) {
        return true;
      } else {
        return false;
      }
  - platform: template
    name: "Dog Bark Alert His 105"
    icon: mdi:dog
    lambda: |-
      // Adjust alert threshold (db)
      if (id(esphome_db).state > 105) {
        return true;
      } else {
        return false;
      }
  
#hers

  - platform: template
    name: "Dog Bark Detected Hers 75"
    device_class: sound
    lambda: |-
      if (id(esphome_db).state > 75.0) {  // Adjust threshold as needed
        return true;
      } else {
        return false;
      }
    #update_interval: 5s  

  - platform: template
    name: "Dog Bark Detected Hers 80"
    device_class: sound
    lambda: |-
      if (id(esphome_db).state > 80.0) {  // Adjust threshold as needed
        return true;
      } else {
        return false;
      }
    

  - platform: template
    name: "Dog Bark Detected Hers 85"
    device_class: sound
    lambda: |-
      if (id(esphome_db).state > 85.0) {  // Adjust threshold as needed
        return true;
      } else {
        return false;
      }
    

  - platform: template
    name: "Dog Bark Detected Hers 95"
    device_class: sound
    lambda: |-
      if (id(esphome_db).state > 95.0) {  // Adjust threshold as needed
        return true;
      } else {
        return false;
      }
    

    

  - platform: template
    name: "Dog Bark Detected Hers 105"
    device_class: sound
    lambda: |-
      if (id(esphome_db).state > 105.0) {  // Adjust threshold as needed
        return true;
      } else {
        return false;
      }
  - platform: template
    name: "Dog Bark Detected Hers 100"
    device_class: sound
    lambda: |-
      if (id(esphome_db).state > 100.0) {  // Adjust threshold as needed
        return true;
      } else {
        return false;
      }
    

  - platform: template
    name: "Dog Bark Detected Hers 95"
    device_class: sound
    lambda: |-
      if (id(esphome_db).state > 95.0) {  // Adjust threshold as needed
        return true;
      } else {
        return false;
      }

      
sensor:

  - platform: adc
    pin: A0
    id: esphome_db
    device_class: signal_strength
    name: "Db SoundEsp"
    icon: "mdi:volume-vibrate"
    unit_of_measurement: "db"
    update_interval: 5s
    raw: true
    filters:
      - lambda: |-
          unsigned int sample;
          unsigned long startMillis= millis(); 
          float peakToPeak = 0; 
          unsigned int signalMax = 0;
          unsigned int signalMin = 1024;
          while (millis() - startMillis < 500) {
            sample = analogRead(A0);
            if (sample < 1024){
                if (sample > signalMax){
                    signalMax = sample;
                }
                else if (sample < signalMin){
                    signalMin = sample;
                }
              }
          }
          peakToPeak = map((signalMax - signalMin),1,1024,1.5,1024);
          id(esphome_volume) = peakToPeak;
          float state = id(esphome_sensitivity)*log10(peakToPeak)+15;  
          return(state);

  - platform: template
    name: "Db Volume SoundEsp"
    icon: "mdi:volume-high"
    unit_of_measurement: "%"
    update_interval: 5s
    lambda: return(map((id(esphome_db).state),15,150,0,100));

  - platform: template
    name: "Db RAW SoundEsp"
    icon: "mdi:volume-source"
    unit_of_measurement: "%"
    update_interval: 5s
    lambda: return(map(id(esphome_volume),1,1024,0,100));

  - platform: copy
    source_id: esphome_db
    name: "Db SoundEsp Average"
    filters:
      - sliding_window_moving_average:
          window_size: 15
          send_every: 5

I had the same need and never found a good option, so I built one: a Home Assistant
add-on that detects dog barks from a USB microphone plugged into the HA
machine
— no camera required.

GitHub - maomorales/bark-sensor-home-assistant: Building a bark sensor that then pushes events to home assistant for smart home automations (lights etc) · GitHub

Frigate and yamcam both do YAMNet audio classification well, but both need a
camera RTSP stream. I wanted a mic in a room with no camera, so this reads a
locally attached USB microphone instead, you can buy a cheap USB mic stick for your raspberry, but it works better with a nice mic, I’m using it with a Blue Yeti Nano and it works really well.

What it does

  • Classifies audio locally with YAMNet (TensorFlow Lite) — nothing leaves your network
  • Creates a binary_sensor automatically via MQTT discovery, so no manual YAML
  • Picks up MQTT credentials from the Mosquitto add-on via the Supervisor
  • Optionally saves clips to /media, playable in the Media panel, with the
    confidence score in the filename so you can tune against real examples
  • Sliding-window voting + cooldown to reject one-off transients

Install: add the repo URL under Settings → Add-ons → ⋮ → Repositories.
Runs on aarch64 and amd64. On a Pi 4 it uses 1.3% CPU and 88 MB RAM.

The thing I wish I’d known first: your microphone matters far more than any
setting.

I spent hours tuning thresholds before measuring properly. Same room, same Pi,
same settings — a cheap USB electret recorded nothing at all during barks I
could clearly hear, while a USB condenser picked up dogs several hundred metres
away and scored them 0.67.

Cheap capsules have a self-noise floor around 35–40 dB SPL. A distant bark isn’t
quiet, it’s below that floor — genuinely absent from the recording. Gain,
thresholds and normalisation all scale signal and noise together, so none of
them recover it. If you’re chasing distant dogs: get the mic outdoors or to an
open window (worth 20–30 dB, more than every software option combined), and use
a decent capsule.

Realistic range: dogs in your house or a neighbour’s yard are reliable. A
kilometre away is best-effort on a quiet night.

Happy to take feedback — it’s MIT licensed and the detection parameters are all
exposed in the add-on config.

Interesting idea!

Have you put any thought into how (other than using a remote pi or similar) you could have a remote microphone, rather than physically connected?