The Screamer
Don't you want to just yell at your electronics?
Who remembers The Clapper? Hard to forget the jingle, forever burned in my brain. For those unfamiliar, it was a very early version of a smart switch that allowed you to clap twice to turn the switch on and off. The early version was pretty bad, then there some revisions that made it better, and apparently they still sell it!
But we live in 2025! There has to be a better way! Have you ever tried to use Siri or Alexa to turn off a light and ended up just wanting to yell at it? Well now you can!
Volume warning: I'm yelling in this video.
Volume warning: I am yelling
How it works
For this project I wanted an "off-the-shelf" smart switch so I opted for a Sonoff S31. The Sonoff series are well regarded for their hackability as they're built on an ESP8266 and therefore you can run ESPHome on them pretty easily. This makes it so you can change pretty much everything about how it works from a software perspective, but still retain the hardware engineering that went into making it safe to use.
I'll note here - ESPHome is probably overkill, but I've used it a ton so I'm very familiar with it, and they maintain an excellent directory that has info on the device. If you were doing this from scratch with your own components you probably wouldn't go with this option.
I went with an INMP441 microphone which uses I2S and would be relatively easy to set up. I was hoping to just piggyback off the S31's ESP to run all my code on, but I think the S31 doesn't have enough GPIO pins to support using the microphone. For a future revision of the project I'll find a device that has just enough pins to run the project all of one board, but for this version I ended up using an additional ESP32 board to do the scream detection.
I connected a GPIO port on the ESP32 running the scream detection to the TX
pin on the S31, and added this to the Sonoff's ESPHome code:
binary_sensor:
- platform: gpio
pin:
mode: INPUT_PULLUP
number: TX
on_press:
- switch.toggle: relay
Whenever a signal is received on this pin, the internal Sonoff relay toggles and so does the load attached to it (e.g. a light).
On the ESP32, I wrote Arduino code. It initializes the microphone and starts taking samples to check things in this order:
- Does the amplitude surpass a certain threshold?
- Does the FFT result contain enough energy in certain frequency bands (between 1000 and 4000 Hz, where I assume most screaming is done)?
- Are we currently not detecting a scream?
If the answer is yes to all of those, we bring the GPIO pin that is connected to the Sonoff S31's TX
pin low which then toggles the relay in the above ESPHome code. We then set my favorite variable name ever, currently_screaming
, to True
and wait a little bit as a debounce period before we start all over again.
Why didn't you...
Run something higher level (e.g. Python or run it on a Raspberry Pi)
Ultimately I want someone to be able to plug this in and it immediately starts working. No connectivity needed at all, and unplugging it and plugging it back in is guaranteed to get the software stack in some known good state.
Use some other scream detection method
Probably because I don't know about it! Please let me know if you know of any better methods. This one seems fairly accurate but there's definitely some limitations - I'm not sure yet if it's the detection methodology or a limitation of the microphone.
Integrate this with some other software to allow for more advanced functionality
Maybe you want to scream to close your garage door. Maybe you scream to change your lights to red. The possibilities are endless! Maybe one day. Keeping the ESPHome config involved makes this pretty easy to integrate with Home Assistant, the "Scream Detected" pin is exposed as an entity there.
Why?
Great question. It seemed fun, and people get a laugh out of it. I think that's reason enough.
If you:
- want to get notified when I clean this up a bit and get it on GitHub
- want to buy one for the angry person in your life if I end up producing these
- want to read more nonsense like this in the future
Then please sign up here!
Thanks for reading.