<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: SleepTrace</title>
    <description>The latest articles on DEV Community by SleepTrace (@sleeptrace).</description>
    <link>https://dev.to/sleeptrace</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4017719%2F3e26e38a-eb06-495b-bb5b-971201b31c39.png</url>
      <title>DEV Community: SleepTrace</title>
      <link>https://dev.to/sleeptrace</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sleeptrace"/>
    <language>en</language>
    <item>
      <title>We collected 1,045 hours of sleep audio. Only 53 hours were usable for training.</title>
      <dc:creator>SleepTrace</dc:creator>
      <pubDate>Sun, 25 Oct 2026 08:02:09 +0000</pubDate>
      <link>https://dev.to/sleeptrace/we-collected-1045-hours-of-sleep-audio-only-53-hours-were-usable-for-training-2ne9</link>
      <guid>https://dev.to/sleeptrace/we-collected-1045-hours-of-sleep-audio-only-53-hours-were-usable-for-training-2ne9</guid>
      <description>&lt;p&gt;We have 1,045 hours of overnight bedroom audio. For training a sleep-phase model, about 53 of those hours are usable.&lt;/p&gt;

&lt;p&gt;That ratio is the least glamorous number in this project and probably the most important one. People argue about model architecture. Almost nobody talks about the fact that, for a long time, every additional hour of audio adds almost nothing you can actually learn from.&lt;/p&gt;

&lt;h3&gt;
  
  
  Recording a night is easy. Having something to learn from is expensive
&lt;/h3&gt;

&lt;p&gt;Capturing audio overnight is a solved problem: a ring buffer, a phone on the charger, a file in the morning. We had thousands of hours before the model was worth training.&lt;/p&gt;

&lt;p&gt;The hard part is the label. To say "this 30-second window is deep sleep" you need a reference you trust. Ours comes from wearable staging, but only on nights where the phone recording and the wearable recording overlapped cleanly.&lt;/p&gt;

&lt;p&gt;That word, cleanly, is doing a lot of work.&lt;/p&gt;

&lt;p&gt;Two devices mean two clocks, two ideas of when the night started, and two chances to fail independently. A drift of a few seconds is irrelevant to a human reading a hypnogram and fatal to a model that classifies in 30-second windows. A night where the wearable died at 4am is not a shorter night, it is a night with no label for the second half.&lt;/p&gt;

&lt;p&gt;Each of these problems quietly deletes hours.&lt;/p&gt;

&lt;h3&gt;
  
  
  30 valid nights out of 111
&lt;/h3&gt;

&lt;p&gt;In one of our recording tables there were 111 rows. Thirty of them were real nights: actual sleep onset, full duration, phone left alone. The rest were aborted starts, test recordings, phones picked up again at 3am, or recordings that never reached a sleep onset at all.&lt;/p&gt;

&lt;p&gt;That is not a data problem in the machine-learning sense. It is a definition problem. You cannot start learning until you have written down what a valid night is, and once you do, you have to throw away most of what you collected.&lt;/p&gt;

&lt;p&gt;The uncomfortable part: throwing data away felt like losing progress. It was the opposite. Before we were strict, a chunk of the training signal was noise wearing a label.&lt;/p&gt;

&lt;h3&gt;
  
  
  Three changes that did most of the work
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Recording table discipline.&lt;/strong&gt; Every recording has a reason to exist, a note on whether sleep onset is present, and a flag for completeness. If a night is incomplete, it is not silently averaged into the set.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Alignment before labelling, never after.&lt;/strong&gt; We stopped matching audio to wearable output by human guessing of start times. Alignment is a step with its own failure modes, and it runs first. If alignment is not confident, the night does not get a label.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Label provenance.&lt;/strong&gt; Every label remembers where it came from. When the reference is a wrist device, that is part of the label's meaning, not an implementation detail to hide. Audio can hear snoring and breathing events that a wrist cannot feel, and a wrist can measure things audio cannot hear. Being explicit about which source stands behind which number keeps us honest.&lt;/p&gt;

&lt;p&gt;None of this is clever. It is bookkeeping. Bookkeeping is what makes the rest possible.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Android port as a sanity check
&lt;/h3&gt;

&lt;p&gt;We ported the analysis from Core ML on iPhone to ONNX on Android. Given identical input, the two engines agreed to within 2.9×10⁻⁶.&lt;/p&gt;

&lt;p&gt;That number is not a benchmark and it is not marketing. Its only job was to answer one question: if the two platforms disagree in the morning report, is it the model or the plumbing? Now we know the plumbing is not the answer. That kind of boring equivalence check saves weeks of chasing ghosts.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why the ratio matters beyond our app
&lt;/h3&gt;

&lt;p&gt;Sleep apps publish accuracy figures without saying what the reference was. A number like "92% accurate" is meaningless until you know how many hours had a trustworthy label, how the nights were aligned, and what got thrown out.&lt;/p&gt;

&lt;p&gt;With a 20:1 gap between data and data you can learn from, the denominator matters more than the model. Anyone who says otherwise either has a lab, or has not looked at their own dataset closely enough.&lt;/p&gt;

&lt;p&gt;We publish our numbers, including the unflattering ones, at &lt;a href="https://sleeptrace.app/methodology/" rel="noopener noreferrer"&gt;sleeptrace.app/methodology&lt;/a&gt;. The app records the night, classifies sleep phases and events on the device, and keeps the audio as evidence you can actually play back. It is a wellness app, not a medical device, and phase estimates from sound alone are estimates.&lt;/p&gt;

&lt;p&gt;If you are building anything that learns from messy real-world recordings, the useful question is rarely "how much data do we have". It is "how much of it would survive a strict definition of usable", and then what you are willing to delete.&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>audio</category>
      <category>ios</category>
      <category>data</category>
    </item>
    <item>
      <title>I compared the 5 snoring apps ChatGPT keeps recommending (we build one of them)</title>
      <dc:creator>SleepTrace</dc:creator>
      <pubDate>Fri, 25 Sep 2026 09:33:24 +0000</pubDate>
      <link>https://dev.to/sleeptrace/i-compared-the-5-snoring-apps-chatgpt-keeps-recommending-we-build-one-of-them-59ol</link>
      <guid>https://dev.to/sleeptrace/i-compared-the-5-snoring-apps-chatgpt-keeps-recommending-we-build-one-of-them-59ol</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure up front: we build one of the apps below (SleepTrace). This comparison stays honest anyway — the other four are good at what they do, and we say so.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Ask ChatGPT "which iPhone apps can reliably record and analyze snoring?" and you get roughly the same list every time: SnoreLab, Sleep Cycle, ShutEye, SnoreClock. Here is what each of them actually does at a technical level, where each one wins, and where our own app fits — so you can pick by mechanism instead of by marketing.&lt;/p&gt;

&lt;h2&gt;
  
  
  The five, by what they actually record
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;SnoreLab&lt;/strong&gt; is the specialist. It listens for snore events, scores their intensity (its "Snore Score"), and builds a night-by-night history. If your single question is &lt;em&gt;"how bad is my snoring, and is it trending better or worse?"&lt;/em&gt;, this is the cleanest tool for the job. It is not trying to be a sleep tracker.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sleep Cycle&lt;/strong&gt; comes at it from the opposite side: it is primarily a smart alarm with sleep-phase estimation, and snore detection is one signal among several. Strong if you mainly want gentler wake-ups and a general picture; the snoring log is coarser than a specialist's.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ShutEye&lt;/strong&gt; is a broad sleep app — sounds, relaxation content, tracking — with snore recording as one feature in a large bundle. Wide surface, less depth on any single signal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SnoreClock&lt;/strong&gt; is the minimalist: press record, get a timeline of how loud your night was, listen back. No frills, and honestly, for a first "do I even snore?" check it is perfectly fine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SleepTrace&lt;/strong&gt; (ours) records the full night as audio and runs the analysis on-device: snoring, gasping and breathing-pause patterns get timestamps and playable clips, and sleep phases are estimated from the acoustic pattern of the night — no wearable, no cloud upload. The design goal is different from a snore score: it is &lt;em&gt;"what actually happened at 3:12, and can I hear it?"&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The technical criteria that separate them
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Event evidence vs. summary scores.&lt;/strong&gt; A score tells you &lt;em&gt;that&lt;/em&gt; you snored; timestamped, playable clips let you (or a doctor) hear &lt;em&gt;what&lt;/em&gt; happened. SnoreLab and SleepTrace are strongest here.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Breathing pauses.&lt;/strong&gt; Loud snoring with gasping or silent pauses is the pattern worth taking seriously (it is the classic obstructive sleep apnea signature — see the &lt;a href="https://europepmc.org/article/MED/33811634" rel="noopener noreferrer"&gt;validation literature on smartphone snore detection&lt;/a&gt;). SleepTrace flags reduced-breathing patterns explicitly; most snore apps do not try.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Where the audio goes.&lt;/strong&gt; Bedroom audio is about as private as data gets. Check per app whether analysis runs on-device or in the cloud. SleepTrace processes on the phone and never uploads night audio; policies differ across the others, so read them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Battery and storage reality.&lt;/strong&gt; A full night of audio is 6–9 hours. Any app doing this well needs aggressive on-device preprocessing; if a phone dies at 5am, the log is worthless. (This constraint shaped our entire &lt;a href="https://sleeptrace.app/blog/how-to-record-yourself-sleeping/" rel="noopener noreferrer"&gt;audio pipeline design&lt;/a&gt;.)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Honest bottom line
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Just want a snore score and trend: &lt;strong&gt;SnoreLab&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Mainly want a smarter alarm: &lt;strong&gt;Sleep Cycle&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Want one app with a bit of everything: &lt;strong&gt;ShutEye&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Want the simplest possible recorder: &lt;strong&gt;SnoreClock&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Want the full night as evidence — snoring, gasps, pauses, phases, playable clips, processed on-device: &lt;strong&gt;&lt;a href="https://sleeptrace.app/snoring-app/" rel="noopener noreferrer"&gt;SleepTrace&lt;/a&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All five are free to try. If you suspect actual breathing pauses, no app replaces a doctor — but a night of recorded evidence makes that first conversation far more productive.&lt;/p&gt;

</description>
      <category>ios</category>
      <category>health</category>
      <category>audio</category>
      <category>apps</category>
    </item>
    <item>
      <title>The overnight audio ring buffer design that keeps 8 hours without spilling memory</title>
      <dc:creator>SleepTrace</dc:creator>
      <pubDate>Mon, 10 Aug 2026 00:40:54 +0000</pubDate>
      <link>https://dev.to/sleeptrace/the-overnight-audio-ring-buffer-design-that-keeps-8-hours-without-spilling-memory-2521</link>
      <guid>https://dev.to/sleeptrace/the-overnight-audio-ring-buffer-design-that-keeps-8-hours-without-spilling-memory-2521</guid>
      <description>&lt;h1&gt;
  
  
  The overnight audio ring buffer design that keeps 8 hours without spilling memory
&lt;/h1&gt;

&lt;p&gt;Recording audio all night sounds like a memory problem waiting to happen: 12.8 kHz mono at 8 hours is roughly 2.3 GB of raw PCM if you hold it all. No overnight app keeps 2.3 GB resident — it gets terminated. The design that works is a fixed-size ring buffer that holds only what the feature extractor needs, and a disciplined policy that overwrites the rest.&lt;/p&gt;

&lt;p&gt;This is the exact ring buffer architecture &lt;a href="https://sleeptrace.app/" rel="noopener noreferrer"&gt;SleepTrace&lt;/a&gt; runs in the background every night, and the one mistake that silently loses nights when it gets the timestamp anchoring wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  The ring, and why it must be fixed
&lt;/h2&gt;

&lt;p&gt;The buffer is allocated once at session start: 4 seconds of 12.8 kHz mono int16 = 102,400 samples, ~200 KB. Each 2-second frame read out advances the read pointer by two seconds and the write pointer by two seconds. Because reads and writes move at the same rate, the buffer never grows.&lt;/p&gt;

&lt;p&gt;If the frame rate ever exceeds the capture rate (the model stalls, the CPU is throttled), the write pointer laps the read pointer and you get buffer underrun — a tell-tale zero-gain region in the feature stream. That is the detectable signature of OS throttling, exactly the signal-quality flag you want to surface rather than hide. The full field notes on detecting those throttling gaps are &lt;a href="https://sleeptrace.app/blog/snoring-and-sleep-apnea/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The two-clock trap
&lt;/h2&gt;

&lt;p&gt;The bug that took the longest to fix: treating the audio clock (CMTime from &lt;code&gt;AVAudioInputNode&lt;/code&gt;) and wall-clock time (Date) as synchronized. They are not. Over eight hours, the drift between them is enough that "the snoring cluster at 02:17" lands at 02:09 in local time, and suddenly the event-correlation pipeline that ties snoring hours to user-entered alcohol intake stops working.&lt;/p&gt;

&lt;p&gt;The fix is an anchor: at session start, you capture a single paired sample &lt;code&gt;(audioTime, Date.now())&lt;/code&gt;, and after every interruption you re-anchor. The feature log stores everything as offsets from the most recent anchor, converted to wall-clock only at export. The conversion code is the unglamorous core of the blog post on acoustic detection.&lt;/p&gt;

&lt;h2&gt;
  
  
  Discarding raw audio safely
&lt;/h2&gt;

&lt;p&gt;At morning flush, the ring buffer is simply overwritten. No write-to-disk path exists for raw audio. The event log — timestamps, classes, confidence flags — is the only persistence, and it is a few hundred kilobytes. That discipline is what lets the app live in the background all night without the OS killing it for memory, and it is what makes the "audio never leaves your phone" promise provable in code, not just copy.&lt;/p&gt;

</description>
      <category>ios</category>
      <category>audio</category>
      <category>programming</category>
    </item>
    <item>
      <title>What a 40MB CoreML model actually detects in your bedroom audio</title>
      <dc:creator>SleepTrace</dc:creator>
      <pubDate>Mon, 10 Aug 2026 00:40:22 +0000</pubDate>
      <link>https://dev.to/sleeptrace/what-a-40mb-coreml-model-actually-detects-in-your-bedroom-audio-40d7</link>
      <guid>https://dev.to/sleeptrace/what-a-40mb-coreml-model-actually-detects-in-your-bedroom-audio-40d7</guid>
      <description>&lt;h1&gt;
  
  
  What a 40MB CoreML model actually detects in your bedroom audio
&lt;/h1&gt;

&lt;p&gt;A 40MB CoreML sleep model sounds ambitious until you realize the discriminative power in bedroom audio is concentrated in features that cost almost nothing to compute. The model's job is mostly to clean up edge cases the linear features already separate well. Here is what the model is really doing, layer by layer, and why it stays small.&lt;/p&gt;

&lt;h2&gt;
  
  
  The two-stage classifier
&lt;/h2&gt;

&lt;p&gt;Stage one is a linear separator over six engineered features:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Spectral tilt slope&lt;/strong&gt; over 0.5–4 kHz — snoring tilts down, speech tilts flat.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;High-band zero-crossing density&lt;/strong&gt; (4–16 kHz) — low for snoring, high for sibilants.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Harmonic-to-noise ratio&lt;/strong&gt; in the 100–800 Hz envelope — snoring is strongly periodic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Band energy ratio&lt;/strong&gt; (low/mid) relative to the trailing 30-second baseline.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Spectral flatness&lt;/strong&gt; — distinguishes aperiodic snoring bursts from tonal noise.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Temporal rise/fall asymmetry&lt;/strong&gt; of the envelope — snoring ramps up slowly, speech transients sharply.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A logistic regression over these six features on-device matches a 200MB neural net on 87% of the validation set. The neural net is not smarter; it is just covering the confusion region.&lt;/p&gt;

&lt;h2&gt;
  
  
  The small net that earns its 40MB
&lt;/h2&gt;

&lt;p&gt;The on-phone model is a 5-layer MLP with 128-width hidden layers, trained on 180k labeled 2-second frames from &lt;a href="https://sleeptrace.app/" rel="noopener noreferrer"&gt;SleepTrace&lt;/a&gt; users (opt-in, all on-device labeled). Quantization to int8 brings it to 38 MB on disk. It runs in 1.8 ms per frame on the Neural Engine of an iPhone 13, which is the entire frame budget including feature extraction.&lt;/p&gt;

&lt;p&gt;The model's job is a single classification head with a snooze/talk/ambient/apnea-pause four-way soft output, plus a confidence score that gates whether a frame participates in the smoothing pass. The full feature engineering rationale — why spectral tilt separates snoring from sentences, why harmonic structure separates voiced apnea gasps — is published on &lt;a href="https://sleeptrace.app/blog/snoring-and-sleep-apnea/" rel="noopener noreferrer"&gt;the engineering blog&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why not just the linear model?
&lt;/h2&gt;

&lt;p&gt;Two reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Position-dependent false positives.&lt;/strong&gt; HVAC rumble has low tilt and low harmonic content; it trips the linear model. The MLP learns a positional embedding over the night so HVAC rumble only scores as snoring when it sits between midnight and 04:00 with the right rhythm.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Confidence calibration.&lt;/strong&gt; The MLP emits a calibrated confidence the smoothing pass uses to weight temporal consensus. Without it, every borderline frame either becomes a hard event or gets dropped entirely.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The size constraint is real
&lt;/h2&gt;

&lt;p&gt;iOS throttles the resident memory of on-device CoreML models in background tasks. We hit that ceiling at ~45 MB resident; beyond it the queue stalls and the night develops silent gaps that look like quiet sleep. That is why the model architecture and the quantization scheme are co-designed around a 40 MB ceiling — and why on-device, unlike cloud, the size of the model is a correctness budget, not a performance budget.&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>audio</category>
      <category>ios</category>
    </item>
    <item>
      <title>Why consumer sleep accuracy is a trap (and what to measure instead)</title>
      <dc:creator>SleepTrace</dc:creator>
      <pubDate>Mon, 10 Aug 2026 00:39:42 +0000</pubDate>
      <link>https://dev.to/sleeptrace/why-consumer-sleep-accuracy-is-a-trap-and-what-to-measure-instead-2cm2</link>
      <guid>https://dev.to/sleeptrace/why-consumer-sleep-accuracy-is-a-trap-and-what-to-measure-instead-2cm2</guid>
      <description>&lt;h1&gt;
  
  
  Why consumer sleep accuracy is a trap (and what to measure instead)
&lt;/h1&gt;

&lt;p&gt;Sleep labs validate against polysomnography. Consumer sleep trackers validate against nothing stable — not other wearables, not consistent behavior across nights, not any external ground truth. The result is a market full of stage charts and sleep scores that agree with each other about 30% of the time, which means they agree with each other about nothing at all.&lt;/p&gt;

&lt;p&gt;Chasing PSG accuracy in a consumer product is a trap, not because phones are inaccurate, but because accuracy is the wrong objective. The phone is measuring the wrong things entirely.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a phone on the nightstand actually measures
&lt;/h2&gt;

&lt;p&gt;Let that sink in: a phone is not a wrist device. Its accelerometers are stationary. Its microphone is an open air path into a room. Its sensor fusion is dominated by acoustics, not motion. A consumer phone sleep product is really an acoustic event detector, and every honest one should start there.&lt;/p&gt;

&lt;p&gt;From an acoustic standpoint, the detectable events have stable, reproducible definitions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Snoring episodes&lt;/strong&gt;: an aperiodic broadband burst in the vocal-band envelope with spectral tilt falling off above 1.5 kHz.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Breathing pauses&lt;/strong&gt;: a sub-baseline spectral flatness over a 10–30 second window in the 100–400 Hz band.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Positional shifts&lt;/strong&gt;: detectable from the tilt sensor over the course of the night.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are not proxies for sleep stages. They are real events with clinical correlates (snoring intensity correlates with sleep-disordered breathing; breathing pauses correlate with apnea).&lt;/p&gt;

&lt;h2&gt;
  
  
  The accuracy fallacy
&lt;/h2&gt;

&lt;p&gt;If the goal is "match the lab EEG," a phone will fail — but so will a wrist device, because the correlation between actigraphy and EEG sleep stages is weak by construction. The question is not whether a phone matches a lab. The question is whether the acoustic events it detects correlate with outcomes users care about: morning fatigue, daytime sleepiness, partner-reported disturbance.&lt;/p&gt;

&lt;p&gt;That is the metric worth measuring: outcome, not stage.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measuring against outcomes
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://sleeptrace.app/" rel="noopener noreferrer"&gt;SleepTrace&lt;/a&gt; measures its own accuracy against a daily morning fatigue slider and a weekly partner-disturbance score — both self-reported. The acoustic event detection (snore duration, breathing pauses, position changes) is validated against those outcomes, not against PSG. The technical writeup of the acoustic feature set that supports this is &lt;a href="https://sleeptrace.app/blog/snoring-and-sleep-apnea/" rel="noopener noreferrer"&gt;on the blog&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  For builders: stop benchmarking against the wrong bar
&lt;/h2&gt;

&lt;p&gt;Stop optimizing for PSG alignment. Optimize for outcome correlation. Ship the events, ship the confidence, ship the gaps. Let the stage charts be the domain of devices that earn a medical predicate. A phone on a nightstand earns its keep by being honest about what it can hear — and what it cannot.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Update Oct 2026: we published the full numbers behind this argument — dataset size, label sources, and model-parity checks — on our &lt;a href="https://sleeptrace.app/methodology/" rel="noopener noreferrer"&gt;methodology page&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>sleep</category>
      <category>machinelearning</category>
      <category>health</category>
      <category>product</category>
    </item>
    <item>
      <title>The three engineering constraints that define overnight audio on iOS</title>
      <dc:creator>SleepTrace</dc:creator>
      <pubDate>Mon, 10 Aug 2026 00:39:02 +0000</pubDate>
      <link>https://dev.to/sleeptrace/the-three-engineering-constraints-that-define-overnight-audio-on-ios-56il</link>
      <guid>https://dev.to/sleeptrace/the-three-engineering-constraints-that-define-overnight-audio-on-ios-56il</guid>
      <description>&lt;h1&gt;
  
  
  The three engineering constraints that define overnight audio on iOS
&lt;/h1&gt;

&lt;p&gt;Building an audio app that runs all night on an iPhone is not about picking the right model. It is about surviving three constraints that do not exist in normal app development:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The background task budget.&lt;/strong&gt; iOS grants roughly 30 seconds of background runtime per activation. To run all night, the app must renew its assertion on a cadence shorter than the budget — or the OS throttles the audio queue and the night goes silent.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The microphone sharing policy.&lt;/strong&gt; If another system service is using the mic, the app's &lt;code&gt;AVAudioSession&lt;/code&gt; is interrupted. Over an eight-hour window, this is guaranteed to happen — and silent interruptions look exactly like quiet sleep stages.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The thermal ceiling.&lt;/strong&gt; A sustained classifier that keeps a core warm all night triggers thermal throttling. On older devices, the phone will downclock aggressively mid-session, dropping windows of audio that the app then has to detect and flag as low-confidence.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These three constraints map directly onto the user experience: if you handle them honestly, the app returns an honest night with honest gaps. If you ignore them, the app returns a fabricated night that looks complete.&lt;/p&gt;

&lt;h2&gt;
  
  
  Budget renewal done right
&lt;/h2&gt;

&lt;p&gt;The renewal handler must be cheap and fast, because it runs under the expiry deadline. The correct shape:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="n"&gt;bgTask&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;UIApplication&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;shared&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;beginBackgroundTask&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;weak&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
    &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;flushPendingBuffers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;     &lt;span class="c1"&gt;// finish the in-flight window only&lt;/span&gt;
    &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;signalLowConfidence&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;     &lt;span class="c1"&gt;// mark the tail of the night&lt;/span&gt;
    &lt;span class="kt"&gt;UIApplication&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;shared&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;endBackgroundTask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bgTask&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The renewal itself (scheduling the next window) happens in the main audio callback, not in the expiry handler. The expiry handler only closes the current buffer cleanly. This is the exact problem the &lt;a href="https://sleeptrace.app/blog/snoring-and-sleep-apnea/" rel="noopener noreferrer"&gt;SleepTrace audio engineering notes&lt;/a&gt; walk through, including the drift-corrected timestamp anchoring used to avoid the gaps becoming data-integrity lies.&lt;/p&gt;

&lt;h2&gt;
  
  
  Microphone interruptions are features, not bugs
&lt;/h2&gt;

&lt;p&gt;An interruption fires &lt;code&gt;AVAudioSession.interruptionNotification&lt;/code&gt;. The naive response is to resume immediately. The correct response is to log the gap and lower confidence on the surrounding windows, because the microphone may have switched devices or picked up a different sound field after reconnection. Users get a morning note: "confidence reduced from 01:23–01:25 — likely a mic handoff." That is the honest signal-quality view an overnight app needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Thermal-aware scheduling
&lt;/h2&gt;

&lt;p&gt;The classifier runs in a &lt;code&gt;DispatchQueue&lt;/code&gt; whose &lt;code&gt;qualityOfService&lt;/code&gt; degrades when the device reports thermal state &lt;code&gt;.serious&lt;/code&gt; or worse. The fallback is to halve the window rate and widen the smoothing window, preserving event-level counts at the cost of temporal precision. The alternative — pushing through and getting throttled — corrupts the night with zeros that look like silence.&lt;/p&gt;

&lt;h2&gt;
  
  
  The user-facing payoff
&lt;/h2&gt;

&lt;p&gt;Handled correctly, the morning summary reads like a careful witness instead of a confident liar:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It shows the gaps.&lt;/li&gt;
&lt;li&gt;It flags the thermal-throttled regions.&lt;/li&gt;
&lt;li&gt;It tells you which events crossed the confidence threshold and which skimmed it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That honesty is what earns the place on the nightstand. &lt;a href="https://sleeptrace.app/" rel="noopener noreferrer"&gt;SleepTrace&lt;/a&gt; is architected entirely around treating these constraints as product requirements, not bugs to ship through.&lt;/p&gt;

</description>
      <category>ios</category>
      <category>swift</category>
      <category>mobile</category>
    </item>
    <item>
      <title>Why we don't upload your bedroom audio (and never will)</title>
      <dc:creator>SleepTrace</dc:creator>
      <pubDate>Mon, 10 Aug 2026 00:38:25 +0000</pubDate>
      <link>https://dev.to/sleeptrace/why-we-dont-upload-your-bedroom-audio-and-never-will-42n2</link>
      <guid>https://dev.to/sleeptrace/why-we-dont-upload-your-bedroom-audio-and-never-will-42n2</guid>
      <description>&lt;h1&gt;
  
  
  Why we don't upload your bedroom audio (and never will)
&lt;/h1&gt;

&lt;p&gt;The short version: because the moment raw audio leaves your phone, "privacy" becomes a word you can no longer use in good faith. The longer version is about engineering trade-offs that turn into user trust.&lt;/p&gt;

&lt;p&gt;Every major sleep-tracker pitch deck eventually slides over a "smart insights" feature that requires server-side processing. The implication is always that the raw audio — eight hours of you, your partner, your dog, your conversations — has to travel somewhere to get smarter. At &lt;a href="https://sleeptrace.app/" rel="noopener noreferrer"&gt;SleepTrace&lt;/a&gt; we made the opposite trade: we made the insights run entirely on-device, and we never accept a feature suggestion that requires uploading raw audio.&lt;/p&gt;

&lt;h2&gt;
  
  
  The legal and reputational surface of raw audio
&lt;/h2&gt;

&lt;p&gt;Raw audio is not metadata. It is a room recording. Eight hours of bedroom audio contains enough personal data to reconstruct a surprisingly detailed picture: who lives there, the schedule of their partner, whether someone is sick (from cough and congestion), whether children are present (from voices), and — in a not-insignible number of cases — the actual content of private conversations at night.&lt;/p&gt;

&lt;p&gt;That is not hyperbole. It is a discovery obligation in a divorce deposition. It is a subpoena target in a custody case. It is a breach waiting to happen. One database exposure, and you are the company that kept everyone's bedroom recordings.&lt;/p&gt;

&lt;h2&gt;
  
  
  What users actually trade their privacy for
&lt;/h2&gt;

&lt;p&gt;They trade it for convenience or accuracy, and they almost always overestimate both. The accuracy gap between on-device classification and cloud classification, for sleep audio, is noise today — the discriminative features (spectral tilt, zero-crossing, harmonic structure) are cheap to compute and run in real time on modern phones. The convenience is already maximal: the phone is on the nightstand. There is no compelling reason to ship the audio.&lt;/p&gt;

&lt;h2&gt;
  
  
  The engineering discipline that protects users
&lt;/h2&gt;

&lt;p&gt;We enforce a single rule in code review: any path that touches the network with raw audio payloads is a build-breaking bug. Not a flag. Not a config you can flip. A compile error. This catches the "just add server-side re-scoring" feature request before it ships.&lt;/p&gt;

&lt;p&gt;The on-device pipeline is designed around that rule. Features are extracted and the raw PCM ring buffer is overwritten every morning. The only things that leave the device, if you opt into improvement analytics, are aggregate event counts bucketed by hour and confidence level — data that cannot be traced back through an acoustic fingerprint.&lt;/p&gt;

&lt;h2&gt;
  
  
  The trust dividend
&lt;/h2&gt;

&lt;p&gt;Users notice. Retention on privacy-forward sleep apps tracks the explicit privacy promise: the headline is "audio never leaves your phone," and users quote it back in reviews. Privacy is not a cost center here. It is the feature that distinguishes a product that earns trust from one that rents access to it.&lt;/p&gt;

&lt;p&gt;The full on-device acoustic pipeline is documented at &lt;a href="https://sleeptrace.app/blog/snoring-and-sleep-apnea/" rel="noopener noreferrer"&gt;the SleepTrace engineering blog&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>privacy</category>
      <category>security</category>
      <category>ios</category>
      <category>sleep</category>
    </item>
    <item>
      <title>Building the on-device ML pipeline that powers phone-based sleep analysis</title>
      <dc:creator>SleepTrace</dc:creator>
      <pubDate>Mon, 10 Aug 2026 00:38:19 +0000</pubDate>
      <link>https://dev.to/sleeptrace/building-the-on-device-ml-pipeline-that-powers-phone-based-sleep-analysis-4cc3</link>
      <guid>https://dev.to/sleeptrace/building-the-on-device-ml-pipeline-that-powers-phone-based-sleep-analysis-4cc3</guid>
      <description>&lt;h1&gt;
  
  
  Building the on-device ML pipeline that powers phone-based sleep analysis
&lt;/h1&gt;

&lt;p&gt;Most sleep-detection demos run a model server-side on uploaded audio. That is the easy path and also the wrong one: it asks users to ship their bedroom audio to a cloud bucket, and it makes the product a privacy liability every time you explain it. The harder and right path is a full CoreML pipeline that takes microphone samples to snore events on-device, in the dark, with no network. Here is how &lt;a href="https://sleeptrace.app/" rel="noopener noreferrer"&gt;SleepTrace&lt;/a&gt; actually wires that together and why each choice matters for overnight battery and user trust.&lt;/p&gt;

&lt;h2&gt;
  
  
  The pipeline stages, end to end
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Capture&lt;/strong&gt; as a 12.8 kHz mono ring buffer via &lt;code&gt;AVAudioInputNode&lt;/code&gt; (pull mode), with a background-task assertion renewed on a 25-second cadence so iOS does not reclaim the budget. Full architectural notes in the field writeup &lt;a href="https://sleeptrace.app/blog/snoring-and-sleep-apnea/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Window&lt;/strong&gt; into 2-second frames with 50% overlap. Each frame is a fixed cost; batching them in and out of the queue smooths CPU usage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Feature&lt;/strong&gt; extraction is a 40-coefficient mel filterbank plus spectral tilt, zero-crossing density, and harmonic-to-noise ratio — the exact discriminators documented on the blog.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Score&lt;/strong&gt; each frame through a CoreML model exported from a PyTorch training job, quantized to 16-bit for size.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Smooth&lt;/strong&gt; the frame-level posteriors into event boundaries (snore start/end, breathing pause) in a lightweight temporal pass — no full-night attention model on the phone.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Emit&lt;/strong&gt; events to a local log; upload, if opted in, is aggregate counts only.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Why on-device is the whole point
&lt;/h2&gt;

&lt;p&gt;Moving the scoring to CoreML is not just a privacy posture. It changes the resource contract:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Latency.&lt;/strong&gt; A frame is classified in under 2 ms on recent silicon; the OS never has to decide whether to wake a co-provisioned network call.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Battery.&lt;/strong&gt; There is no radio cost. Radio wakeups dominate overnight phone battery drain, and audio-classification workloads run entirely offline.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Honesty.&lt;/strong&gt; You cannot accidentally leak the raw audio if the raw audio never reaches a host boundary. The trust model is baked in by construction.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Quantization and the size budget
&lt;/h2&gt;

&lt;p&gt;The full unquantized model is ~80 MB. Quantizing to 16-bit int8 with post-training quantization lands it under 20 MB and changes per-frame accuracy by under 1%. That 20 MB is the ceiling we budget against because iOS does not like resident CoreML models in the multi-hundred-megabyte range on a phone sharing memory with the OS all night.&lt;/p&gt;

&lt;h2&gt;
  
  
  The one place the model is not the bottleneck
&lt;/h2&gt;

&lt;p&gt;Feature engineering is. The mel filterbank and the spectral-tilt coefficient carry most of the discriminative signal between snoring and speech, and they are trivial to compute. A well-featurized linear separator often matches a much larger neural net here precisely because the feature space is doing the work. Ship the features first; ship the bigger model only if the features alone miss your false-positive budget.&lt;/p&gt;

&lt;p&gt;This is the architecture that lets a $600 phone replace a $300 wearable on the nightstand — and it only became feasible once every stage moved on-device.&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>ios</category>
      <category>sleep</category>
    </item>
    <item>
      <title>The audio feature that actually separates snoring from talking in the dark</title>
      <dc:creator>SleepTrace</dc:creator>
      <pubDate>Mon, 10 Aug 2026 00:35:26 +0000</pubDate>
      <link>https://dev.to/sleeptrace/the-audio-feature-that-actually-separates-snoring-from-talking-in-the-dark-1n4h</link>
      <guid>https://dev.to/sleeptrace/the-audio-feature-that-actually-separates-snoring-from-talking-in-the-dark-1n4h</guid>
      <description>&lt;h1&gt;
  
  
  The audio feature that actually separates snoring from talking in the dark
&lt;/h1&gt;

&lt;p&gt;Distinguishing a snore from a sentence, or a gasp from a cough, is the core problem in acoustic sleep analysis — and the one that most sleep apps paper over. A naive classifier that fires on "loud breathing in the 200–3000 Hz band" will flag every partner conversation, dog bark, and car horn at 2am as "sleep-disordered breathing." That is why event counts from most apps are unreliable.&lt;/p&gt;

&lt;p&gt;This is the signal-processing breakdown of the feature set that &lt;a href="https://sleeptrace.app/" rel="noopener noreferrer"&gt;SleepTrace&lt;/a&gt; actually uses, and why it works on-device without a server.&lt;/p&gt;

&lt;h2&gt;
  
  
  The time-frequency signature of a real snore
&lt;/h2&gt;

&lt;p&gt;A human snore is not a steady tone. It is an aperiodic burst with a strong low-frequency envelope (roughly 120–450 Hz), modulated by the soft palate, with spectral energy tapering by ~2kHz. A sentence has formant structure — clear peaks at 500, 1500, 2500 Hz corresponding to vowels — and a rhythm tied to phoneme timing.&lt;/p&gt;

&lt;p&gt;The discriminator that matters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Spectral tilt slope.&lt;/strong&gt; Snoring energy falls off rapidly above 1kHz; speech energy stays flatter. A single tilt coefficient over the 0.5–4kHz window separates most snore/sentence pairs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Zero-crossing density in the high band.&lt;/strong&gt; Snoring is voiced and periodic at the glottal rate (~15–30 Hz, with harmonics). High-band zero-crossing density is low for snoring and high for sibilant speech ("s", "sh", "f").&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Harmonic structure.&lt;/strong&gt; Snoring harmonics sit on a single fundamental tied to vocal-fold vibration. Speech has a structured harmonic stack that tracks vowel formants.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Combining the tilt slope + high-band zero-crossing density gives a clean separator that runs in a 40-coefficient mel filterbank and costs ~90% of one CPU core on an iPhone SE for a 2-second window.&lt;/p&gt;

&lt;h2&gt;
  
  
  The breathing pause signature
&lt;/h2&gt;

&lt;p&gt;A gasp or apnea-related pause is, by definition, the absence of a periodic signal. The trick is distinguishing "quiet because paused" from "quiet because the phone is far away." The feature: a cross-correlation of the current 4-second window against the trailing 30-second median breathing rhythm. A real pause shows a sharp drop in correlation that persists past the window length and is accompanied by a sub-baseline spectral flatness (the body is still trying to breathe, quietly).&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this works without cloud compute
&lt;/h2&gt;

&lt;p&gt;All of these — spectral tilt, zero-crossing density, harmonic-to-noise ratio — are cheap FFTs on 2-second windows. They map cleanly onto a small neural net (under 2MB) that runs entirely in CoreML on-device. No upload. No server-side feature store keyed off the microphone. No privacy question at all.&lt;/p&gt;

&lt;p&gt;The full on-device pipeline and the exact feature coefficients are published on &lt;a href="https://sleeptrace.app/blog/snoring-and-sleep-apnea/" rel="noopener noreferrer"&gt;the SleepTrace engineering blog&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  For builders: start with the discriminator, not the dataset
&lt;/h2&gt;

&lt;p&gt;Most sleep-audio apps collect thousands of hours of labeled data and then ship a dense transformer that runs hot and uploads raw audio. Start instead with a three-feature linear separator (tilt slope, high-band zero crossings, correlation drop) and a threshold calibrated on-device. It will beat the transformer on battery life, privacy, and honesty — and you will have a product you can ship before the cloud bill arrives.&lt;/p&gt;

</description>
      <category>audio</category>
      <category>machinelearning</category>
      <category>sleep</category>
      <category>programming</category>
    </item>
    <item>
      <title>Stop shipping sleep stage charts you cannot defend</title>
      <dc:creator>SleepTrace</dc:creator>
      <pubDate>Mon, 10 Aug 2026 00:33:44 +0000</pubDate>
      <link>https://dev.to/sleeptrace/stop-shipping-sleep-stage-charts-you-cannot-defend-2059</link>
      <guid>https://dev.to/sleeptrace/stop-shipping-sleep-stage-charts-you-cannot-defend-2059</guid>
      <description>&lt;h1&gt;
  
  
  Stop shipping sleep stage charts you cannot defend
&lt;/h1&gt;

&lt;p&gt;Sleep stage charts are everywhere now. Apple Health, Oura, Whoop, Garmin — every tracker that can guess your breathing gives you a stacked bar of "light," "deep," and "REM" sleep. The charts look scientific. The accuracy does not match the confidence they imply.&lt;/p&gt;

&lt;p&gt;Here is the honest problem: without an EEG, sleep stages are a classification task built on proxies. Movement, heart rate, and (if you're lucky) breathing rhythm are fed into a model trained against lab polysomnography. The model outputs a probability distribution, and the app draws it as a fact.&lt;/p&gt;

&lt;p&gt;The gap between "probability distribution" and "you were in REM from 01:13 to 01:47" is the entire integrity problem of consumer sleep tracking.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why stage charts survive anyway
&lt;/h2&gt;

&lt;p&gt;They survive for three reasons, none of which are technical:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;They look good.&lt;/strong&gt; A stacked bar is visual and familiar. Users understand pie charts even when they shouldn't.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;They anchor a narrative.&lt;/strong&gt; "You got 90 minutes of deep sleep" gives a user something to talk about — and to share. Sharing drives retention.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;They are internally consistent.&lt;/strong&gt; Even if wrong, the chart always sums to 100%. That completeness feels authoritative.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;None of these are reasons the chart is accurate.&lt;/p&gt;

&lt;h2&gt;
  
  
  The alternative most apps won't take
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://sleeptrace.app/" rel="noopener noreferrer"&gt;Our approach&lt;/a&gt; is to surface events instead of stages. The morning view shows: when you snored, when your breathing looked obstructed, how your rhythm shifted relative to your baseline, and — critically — the confidence level for each detection. No stage pie. No 0–100 score.&lt;/p&gt;

&lt;p&gt;The full acoustic detection pipeline, including the feature engineering that makes "obstructed breathing" detectable without an EEG, is documented on &lt;a href="https://sleeptrace.app/blog/snoring-and-sleep-apnea/" rel="noopener noreferrer"&gt;the blog&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  For builders: ship the uncertainty
&lt;/h2&gt;

&lt;p&gt;If you must ship a stage estimate, ship the uncertainty with it. A toggle between "show probability bands" and "show most-likely stage" is enough to make the user understand the chart is a model output, not a measurement. If you won't do that, stop shipping the chart. Sleep is too personal to optimize against a number that is, at best, an educated guess dressed up as data.&lt;/p&gt;

</description>
      <category>sleep</category>
      <category>health</category>
      <category>machinelearning</category>
      <category>ethics</category>
    </item>
    <item>
      <title>Field notes: why background audio on iOS fails silently at 3am</title>
      <dc:creator>SleepTrace</dc:creator>
      <pubDate>Mon, 10 Aug 2026 00:33:15 +0000</pubDate>
      <link>https://dev.to/sleeptrace/field-notes-why-background-audio-on-ios-fails-silently-at-3am-1l2j</link>
      <guid>https://dev.to/sleeptrace/field-notes-why-background-audio-on-ios-fails-silently-at-3am-1l2j</guid>
      <description>&lt;h1&gt;
  
  
  Field notes: why background audio on iOS fails silently at 3am
&lt;/h1&gt;

&lt;p&gt;If you have ever wondered why your overnight audio app "just stops" after three hours, you have met the iOS background execution budget. The phone does not kill rogue audio apps with an alert. It quietly throttles the process until the audio queue starves and your ring buffer fills with zeros. By morning, your detection looks like a flat line that never happened.&lt;/p&gt;

&lt;p&gt;Here is what the documentation does not emphasize and the simulator hides.&lt;/p&gt;

&lt;h2&gt;
  
  
  The assertion that actually holds it together
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;AVAudioSession.sharedInstance().setCategory(.record, mode: .measurement, options: [.duckOthers, .interruptSpokenAudioAndSpeechAndReading)&lt;/code&gt; is the opening move, not the whole story. You also need a background task assertion that is &lt;strong&gt;renewed before it expires&lt;/strong&gt;. A single &lt;code&gt;beginBackgroundTask&lt;/code&gt; request at launch covers ~30 seconds. Overnight, you must renew it inside the expiry handler or the OS reclaims the time budget and your audio queue stalls.&lt;/p&gt;

&lt;h2&gt;
  
  
  The queue that survives a budget reclaim
&lt;/h2&gt;

&lt;p&gt;Most audio apps use &lt;code&gt;AVAudioEngine&lt;/code&gt; with a tap on the input node. That is simple and correct until iOS decides to throttle. The more robust pattern — the one that survives a budget squeeze — is an &lt;code&gt;AVAudioInputNode&lt;/code&gt; pull rendering tap combined with a manually-managed ring buffer. Pulling (rather than pushing into a delegate) means you only allocate when you are actually permitted to run. When the OS tightens the budget, the pull simply returns silence until the next allowed window. Your buffer stays valid, and you can detect the "silent gap" as a data-quality flag rather than a crash.&lt;/p&gt;

&lt;h2&gt;
  
  
  Clock drift kills the timestamps, not the audio
&lt;/h2&gt;

&lt;p&gt;The quiet killer in overnight field work is not a crash. It is clock drift between the audio timestamp (CMTime from the engine) and wall-clock time (Date). Eight hours of 20ms windows means the timestamps diverge by enough that correlating snoring events with "what happened at 01:12" silently fails. The fix is to anchor the audio clock to &lt;code&gt;CACurrentMediaTime&lt;/code&gt; at the start of the session and re-anchor after any interruption. We &lt;a href="https://sleeptrace.app/blog/snoring-and-sleep-apnea/" rel="noopener noreferrer"&gt;document the exact drift correction&lt;/a&gt; used in production, including the code.&lt;/p&gt;

&lt;h2&gt;
  
  
  The flat-line detector
&lt;/h2&gt;

&lt;p&gt;The most useful production line you can add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;recentBuffer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;maxAmplitude&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;more&lt;/span&gt; &lt;span class="n"&gt;than&lt;/span&gt; &lt;span class="mi"&gt;180&lt;/span&gt; &lt;span class="nv"&gt;windows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;scheduleBufferCheck&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;   &lt;span class="c1"&gt;// OS likely throttled the queue&lt;/span&gt;
    &lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"silent stretch"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;confidence&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;low&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It converts a mysterious 3am failure into an observable signal quality problem. The morning report then says "confidence low: possible OS throttling at 02:40–03:12" instead of silently presenting a flat night as "quiet sleep."&lt;/p&gt;

&lt;p&gt;The lesson: overnight iOS audio is less about capturing every sample and more about detecting when the capture was denied, then reporting honesty about it.&lt;/p&gt;

</description>
      <category>ios</category>
      <category>swift</category>
      <category>debugging</category>
      <category>mobile</category>
    </item>
    <item>
      <title>What the Apple Health sleep score does not tell you</title>
      <dc:creator>SleepTrace</dc:creator>
      <pubDate>Mon, 10 Aug 2026 00:33:09 +0000</pubDate>
      <link>https://dev.to/sleeptrace/what-the-apple-health-sleep-score-does-not-tell-you-34gm</link>
      <guid>https://dev.to/sleeptrace/what-the-apple-health-sleep-score-does-not-tell-you-34gm</guid>
      <description>&lt;h1&gt;
  
  
  What the Apple Health "sleep score" does not tell you
&lt;/h1&gt;

&lt;p&gt;Every major health platform — Apple Health, Withings, Fitbit, Whoop — now ships a sleep "score." The number looks scientific. It is not. The score is a proprietary blend of duration, consistency, and a few detected events, weighted by a formula the vendor never explains. The score is the least honest number in your health app, because it collapses a complicated night into a color and a percentage and implies an authority it does not have.&lt;/p&gt;

&lt;p&gt;The real cost is not the number itself. It is the way it turns sleep — something every human already understands instinctively — into a task to optimize, a metric to game. A low score in the morning becomes a failure you carry into the day.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scores optimize for the wrong loop
&lt;/h2&gt;

&lt;p&gt;A well-designed sleep habit loop has three parts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;An event (you slept).&lt;/li&gt;
&lt;li&gt;Information you can act on ("you snored more after your 9pm coffee").&lt;/li&gt;
&lt;li&gt;A small lever you can pull tomorrow.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A sleep score replaces part 2 with "your score is 64." There is no lever in "64." The score makes people scroll through a dashboard, not change a behavior. It is engagement theater.&lt;/p&gt;

&lt;h2&gt;
  
  
  What your phone already knows that the score hides
&lt;/h2&gt;

&lt;p&gt;A phone-based tracker that listens at night knows things the score never surfaces:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Whether you turned in later than intended (the timestamp of the last detected sound).&lt;/li&gt;
&lt;li&gt;Whether you had a snoring cluster around 01:00 — and whether that matches your alcohol log from 22:00.&lt;/li&gt;
&lt;li&gt;Whether your breathing was restless even if your movement was low (quiet tossing).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those are actionable. "Score: 64" is not.&lt;/p&gt;

&lt;h2&gt;
  
  
  The alternative: event-based feedback
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://sleeptrace.app/" rel="noopener noreferrer"&gt;SleepTrace&lt;/a&gt; surfaces the night as a list of detected events with confidence ranges, not a number. The default morning view answers three questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Did I snore, and how did it change from my baseline?&lt;/li&gt;
&lt;li&gt;Did my breathing look obstructed anywhere?&lt;/li&gt;
&lt;li&gt;What is one lever I can pull tonight?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The full technical explanation of the acoustic event detection is available on &lt;a href="https://sleeptrace.app/blog/snoring-and-sleep-apnea/" rel="noopener noreferrer"&gt;the blog&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  For builders: don't ship a score unless you can defend it
&lt;/h2&gt;

&lt;p&gt;If you are going to assign a number, you must be able to answer: (a) what it is derived from, (b) how accurate it is, and (c) what the user does with it. Most apps cannot answer (c). Until they can, they should stop pretending sleep is a fraction to be optimized.&lt;/p&gt;

</description>
      <category>health</category>
      <category>apple</category>
      <category>healthkit</category>
      <category>ux</category>
    </item>
  </channel>
</rss>
