MLS-Based Measurement
Uses a Maximum Length Sequence signal and cross-correlation for accurate round-trip latency estimation. Chirp and Golay are planned for a future release.
Web Component powered by Web Audio API. Headless API, MLS-based latency measurement, easy to embed in any Web Audio project.
npm install @adasp/latency-test<script type="module" src="https://cdn.jsdelivr.net/npm/@adasp/latency-test@1.2.1/dist/latency-test.esm.js"></script>
<latency-test id="lt"></latency-test>
<button id="btn">Test</button>
<script type="module">
const lt = document.getElementById('lt')
lt.addEventListener('latency-result', (e) => {
console.log(`${e.detail.latency} ms — ratio: ${e.detail.ratio.toFixed(2)} dB`)
})
// audioContext and inputStream must be assigned before start() — create them from a user gesture
document.getElementById('btn').addEventListener('click', async () => {
if (!lt.inputStream) {
const ac = new AudioContext({ latencyHint: 0 })
try {
lt.inputStream = await navigator.mediaDevices.getUserMedia({
audio: { echoCancellation: false, noiseSuppression: false, autoGainControl: false }
})
lt.audioContext = ac
} catch (e) {
await ac.close()
console.error('Could not access mic:', e.message)
return
}
}
lt.start()
})
</script>start() / stop() and fires events. No built-in button or result display.latency-result CustomEvent ({ latency, ratio, reliable, timestamp, mode }).start(), assign element.inputStream (a MediaStream) and element.audioContext (an AudioContext) — the component never creates audio resources itself. If your app already has an AudioContext, pass it directly to avoid creating a second one.recording-mode to select the capture backend: "mediarecorder" (2-channel, v1 default — no start-timing bias), "mediarecorder-1ch" (1-channel fallback for browsers that downmix stereo to mono), or "audioworklet" (planned v2 default, sample-accurate raw PCM).signal-type is "mls" in v1. "chirp" and "golay" are planned for v2.An interactive demo is live at idsinge.github.io/latency-test/demo. It loads the built IIFE bundle and lets you test round-trip latency in your browser — with your own microphone and audio setup — across all available capture backends and usage patterns.
This component is the web component development branch of gilpanal/weblatencytest, a proof-of-concept associated with the paper presented at WAC 2025.