We shipped a free hearing test that runs in a plain browser tab: no install, no account, headphones only. You can try it at anpheros.com/hearing-test. It takes about five minutes, tests six pitches in each ear, and plots the result on a chart shaped like an audiogram.

This post is about how it works under the hood, the parts that were harder than expected, and the line we drew between "screening you can repeat" and "a clinical measurement", because that line shaped almost every technical decision.

One ear at a time: ChannelMerger, not StereoPanner

The first instinct is StereoPannerNode with pan = -1 or 1. It works, but it's a panning law, not a routing guarantee, and it's one more thing between you and a clean signal. What we actually want is: this sine goes into channel 0 only, or channel 1 only.

ChannelMergerNode does exactly that:

function play(ctx, ear, freq, db) { const t = ctx.currentTime + 0.02; const amp = Math.min(1, Math.pow(10, (db - 85 + (OFFSET[freq] || 0)) / 20)); const osc = ctx.createOscillator(); osc.type = 'sine'; osc.frequency.value = freq; const g = ctx.createGain(); g.gain.setValueAtTime(0, t); g.gain.linearRampToValueAtTime(amp, t + 0.05); // 50 ms attack g.gain.setValueAtTime(amp, t + 0.95); g.gain.linearRampToValueAtTime(0, t + 1); // 50 ms release const m = ctx.createChannelMerger(2); osc.connect(g); g.connect(m, 0, ear === 'right' ? 1 : 0); // input 0 = left, 1 = right m.connect(ctx.destination); osc.start(t); osc.stop(t + 1.05); } 

Two details that matter more than they look:

  • The ramps. Start or stop a sine abruptly and you get a broadband click. At very soft levels, people hear the click and tap, even when they can't hear the tone. A 50 ms linear ramp on each end removes it. Without it, low thresholds are just wrong.
  • Scheduling against currentTime. Everything is scheduled on the audio clock, not with setTimeout, so the tone is exactly one second long even if the main thread is busy re-rendering the UI.

Headphones get swapped. Check before you test

It's easy to wear earbuds the wrong way round. If you don't catch it, the whole result is mirrored, and a one-sided drop (the thing most worth noticing) ends up attributed to the wrong ear.

So before the test, we play one 1 kHz tone into a random ear and ask "which side?". A wrong answer stops the flow with "the sides seem swapped, check the L and R on your headphones". It costs five seconds and catches a whole class of garbage results.

The search: a simplified Hughson-Westlake

Clinical pure-tone audiometry uses a "down 10, up 5" bracketing procedure. Ours is a simplified version of it, shared with our mobile app so a web result and an app result mean the same thing:

function answer(s, heard) { s.tones++; const finish = v => { s.threshold = v; s.done = true; }; if (heard) { s.heard.push(s.level); if (s.asc) { // only ascending hits count s.hits[s.level] = (s.hits[s.level] || 0) + 1; if (s.hits[s.level] >= 2) return finish(s.level); } if (s.level === MIN) return finish(MIN); s.level = Math.max(MIN, s.level - 10); s.asc = false; } else { if (s.level === MAX && ++s.maxMiss >= 2) return finish(null); s.level = Math.min(MAX, s.level + 5); s.asc = true; } if (s.tones >= MAX_TONES) finish(s.heard.length ? Math.min(...s.heard) : null); } 

Start at 40, go down 10 after a hit, up 5 after a miss, and accept a level once it's been heard twice on the way up. The "ascending only" rule is the important bit: it's what stops one lucky tap on the way down from becoming your threshold. There's also a cap of 14 tones per pitch, so nobody gets stuck in an endless loop at one frequency.

Order is 1k, 2k, 4k, 8k, then 500 and 250 Hz. Starting at 1 kHz gives people an easy, familiar tone first.

Timing: don't let people learn the rhythm

If tones arrive on a fixed beat, people start tapping on the beat, tone or no tone. Two guards against that:

  1. Random gaps of 1.2 to 3 seconds between tones.
  2. A response window. A tap only counts in the 2.3 seconds after a tone starts. A tap in the silence gets visual feedback ("wait for the next tone, then press") but doesn't move the search.

If nothing is pressed inside the window, that's a miss and the next tone comes a little louder, which we tell the user up front so silence doesn't feel like a broken app.

The honest part: dBFS is not dB HL

Here's the thing we couldn't engineer away. Web Audio gives you a level relative to digital full scale. What reaches an eardrum depends on the device's output stage, the OS volume, the headphones' sensitivity, and the fit. None of that is known to a web page.

We do apply a small per-frequency offset (OFFSET above) because ears are much less sensitive at 250 Hz and 8 kHz than at 1 kHz for the same signal, so the raw numbers would otherwise exaggerate the edges. But that's a rough shape correction, not calibration. So:

  • The chart shows approximate dB HL, and the page says so.
  • We never output a "hearing loss %" or a category label. That would imply a precision we don't have, and it'd drift toward diagnosis, which a consumer app shouldn't do.
  • What the test is good at is consistency. Same headphones, same volume, a year later, and the comparison means something. That's why the result can be saved with its date and method (method: 'web_tap_tones_v1'), so a future version of the algorithm doesn't silently get compared with an old one.

The user-facing guidance is deliberately plain: a clear difference between ears, or a drop at the high pitches, is a reason to see an audiologist. Sudden hearing loss in one ear is a same-day doctor visit. The tool points to a professional and stops there.

A few smaller lessons

  • AudioContext must start from a gesture. We create it lazily on the first tap and call resume() before every tone, because browsers, Safari in particular, can leave it suspended.
  • Noise cancelling skews results. Some ANC modes shape quiet sounds. The setup checklist asks people to turn it off.
  • Keep the setup interactive. Four tick-off steps (headphones on, quiet room, volume at half, left/right check) are harder to skip than a paragraph of instructions.

Try it, break it

The hearing test is at anpheros.com/hearing-test, and the other browser checks (eye test with card-based screen calibration, colour vision, contrast, tinnitus pitch matching and more) are at anpheros.com/tests. They're free and need no account.

If you've built audio in the browser and know a better way to handle the uncalibrated-output problem, I'd really like to hear it in the comments. That's the piece I'm least satisfied with.

Disclosure: I'm the founder of Anpheros, a patient-held health record. The tests are informative only; they don't diagnose and don't replace an audiologist.