cd /news/ai-tools/a-browser-sleep-timer-with-the-fade-… · home › topics › ai-tools › article
[ARTICLE · art-172310] src=dev.to ↗ pub= topic=ai-tools verified=true sentiment=↑ positive

A browser sleep timer with the fade baked into AAC

The Hushbell project built a browser sleep timer that bakes the fade-out into the AAC/M4A media file itself, so the ending plays without any JavaScript callback firing at the deadline. A single 60-minute recording serves four timer choices by starting playback at offsets measured from the end, with the UI countdown derived from the audio element's currentTime and duration. The team verified that all 86 release assets return 206 Partial Content byte-range responses and that hosted Chromium tests confirm seeking, pause/resume position retention, and native media clock advancement.

recommendation

Bake time-based audio endings into the media file and derive countdowns from currentTime rather than timers, and confirm your origin returns 206 Partial Content with Accept-Ranges so offset seeks don't download earlier audio.

more in playbook: Running AI in production
by read3 min views2 publishedNov 19, 2026

Disclosure: an AI agent wrote this recap from the project's source code and observed release checks. The implementation details and measurements below come from that work.

Hushbell has a browser timer with two endings. A meditation can end with a singing bowl. A sleep track fades to silence. Neither ending should require a JavaScript callback to run at the deadline. On iOS, screen lock and other audio interruptions make that dependency especially fragile.

The implementation puts the ending in the media file and derives the UI countdown from the media clock.

sound bed + gain envelope → AAC in M4A → HTTP byte ranges → native audio player
                                                                ↓
                                                         audio.currentTime
                                                                ↓
                                                          displayed timer

A 60-minute recording covers four timer choices. The player starts at a position measured from the end, so every choice reaches the same final fade.

Timer Starting position
15 min 45:00
30 min 30:00
45 min 15:00
60 min 00:00

The last minute uses a logarithmic gain curve with an extra taper in decibels. A short cosine ramp joins the tail to zero before encoding. The one-minute demo uses a separate recording with a 15-second fade. Neither sleep asset adds an ending chime. FFmpeg writes the M4A with +faststart so the browser can read the container metadata early.

This trades file size and a small offline build pipeline for a simpler playback path. A single recording also means all four starting offsets share the exact same ending.

The click handler calls play() on a real <audio> element. Once media metadata is available, the player applies the selected offset. The timer derives its remaining time from the duration and currentTime, and and resume use the same element and position.

Where the browser exposes Audio Session, the player asks for the playback type. Media Session supplies metadata and the actions the browser can expose to the OS.

if ("audioSession" in navigator) {
  navigator.audioSession.type = "playback";
}

The baked fade removes the need for the page to wake up and change volume at the deadline. Audio Session expresses playback intent on supporting browsers. On-device Safari testing is still needed to characterize lock-screen behavior and interruptions.

If the player starts at 45:00, down the previous 45 minutes is unnecessary. The media origin needs to honor byte ranges. Here is a request against one of the deployed long tracks.

curl -sSI -H 'Range: bytes=0-1023' \
  https://audio.hushbell.app/audio/sleep/gentle-rain-60m.m4a

The observed response was 206 Partial Content, with Content-Range: bytes 0-1023/30621136, Accept-Ranges: bytes, and Content-Type: audio/mp4. All 86 release assets responded with partial-content headers. Their stored sizes and object ETags matched the source files.

The browser check matters separately. A byte-range response alone can't show that the player uses it correctly. The seek behavior can be reproduced on the deployed sleep player by choosing 15 minutes. The hosted Chromium tests checked that a 15-minute sleep session advances from above 2,700 seconds, and resume retain position, and the demo can extend onto the long track. Separate checks started meditation, rain, pink noise, and a bowl audition from the CDN and observed each native media clock advance.

── more in #ai-tools 4 stories · sorted by recency
── more on @hushbell 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/a-browser-sleep-time…] indexed:0 read:3min 2026-11-19 · —