Menu

Real-Time Breath Detection in the Browser: Spectral Centroid, Dual-Path State Machines, and a Nasty iOS Bug

DEV Community: capacitor·Felix Zeller·6 months ago
#7o6jPCR7
#dev#class#code#highlight#breath
Reading 0:00
15s threshold

Microphone-based breath detection sounds simple until you actually try it. Energy goes up, energy goes down — that's a breath, right? In practice, you run into continuous breathing with no silence gaps, noisy environments that drift over time, and (on iOS) a Web Audio API that silently returns all zeros. This post walks through how @shiihaa/breath-detection solves each of these problems.

The library was extracted from shii·haa , a breathwork and biofeedback app built by Felix Zeller, a Swiss physician (Intensive Care + Internal Medicine + Diplompsychologe). It's MIT-licensed, zero dependencies, and ships TypeScript types.

Installation

npm install @shiihaa/breath-detection

The Core Idea: Spectral Centroid for Inhale/Exhale Classification

Most breath detectors only measure when breathing occurs — they can't tell you whether a given phase is an inhale or an exhale.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.