Created
December 31, 2025 16:40
-
-
Save dy/1dfbd44aa73fdf5626ee2124f6e94abb to your computer and use it in GitHub Desktop.
measure-latency
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let mediaElement = new Audio('data:audio/wav;base64,UklGRmgAAABXQVZFZm10IBAAAAABAAEAgLsAAAB3AQACABAAZGF0YQIAAABpNUxJU1Q6AAAASU5GT0lTRlQUAAAAcHJvYmUuYXVkaW90b29sLmNvbQBJQ1JEEQAAADIwMjMtMDMtMDIgMDctNDQAAA==') | |
| mediaElement.preload = "metadata" | |
| mediaElement.load() | |
| mediaElement.volume = 0 | |
| // Measure latency of audio file between first 'playing' event and actual first sample | |
| export async function measureLatency() { | |
| return new Promise(ok => { | |
| mediaElement.play() | |
| let start | |
| mediaElement.onplaying = () => start = performance.now() | |
| mediaElement.onended = () => { | |
| ok(performance.now() - start) | |
| } | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment