DEV Community

Why our browser pet monitor turns off echo cancellation (and other Web Audio lessons)

We build Bugabot at Tainatec: an old phone in the browser listens to a room with a noisy pet, answers the noise with a calm voice or a soft sound, and sends the owner a Telegram message. No app, just a tab.

Here are the browser details that took us the longest to get right.

Turn off what the browser does for calls

getUserMedia defaults are tuned for video calls. Echo cancellation, noise suppression and automatic gain control all try to keep a human voice steady and remove everything else. For us "everything else" is exactly the signal: a bark, a parrot scream, a cage being chewed.

So the microphone opens with all three switched off, mono, at 48 kHz:

navigator.mediaDevices.getUserMedia({ audio: { echoCancellation: false, noiseSuppression: false, autoGainControl: false, channelCount: 1, sampleRate: 48000 } });

With automatic gain on, a quiet room slowly gets amplified until the fridge looks like a dog. With it off, the level means the same thing at 3 a.m. as at noon.

One number the owner can understand

An AnalyserNode reads the time-domain samples on every animation frame, and we turn them into a level from 0 to 100. The owner sets one sensitivity slider; when the level crosses it, the bot reacts.

One number is easier to tune at night than a frequency profile, and the owner sees the level move in real time while the pet makes noise.

Do not hear yourself

The bot answers with sound, and a microphone next to a speaker will hear that answer. While our own phrase plays, and for 800 ms after it ends, detection is paused.

After a reaction the bot waits for 3 seconds of quiet before it goes back to listening, so one long bark does not become ten reactions.

Keep the phone awake

A phone left on a shelf wants to sleep. The Screen Wake Lock API (navigator.wakeLock.request("screen")) keeps the screen on while the bot runs, and we request it again when the tab becomes visible, because the lock is released whenever the page is hidden.

One bot per phone

People open the page twice. A BroadcastChannel lets the tabs talk to each other, so a second tab knows a bot is already running instead of fighting the first one for the microphone.

Video only when someone watches

Live video from the room goes over WebRTC (RTCPeerConnection) and starts only when the owner opens it from their own phone. Nothing from the room is saved: the bot reacts, notifies and streams, and that is all.

If you have a pet that is loud when you are out, the guide behind all this is here: How to stop your dog barking when you're not home. The bot itself runs at bugabot.com.

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.