# Audio Latency Tracing The `“audio.latency”` tracing category is a tool to measure internal chromium audio latency, without any hardware dependencies. This document outlines how to record and analyse a latency trace, and offers suggestions as to how to construct test pages. [TOC] ## Overview ![audio.latency tracing overview](latency_tracing_overview.png) When an input stream detects an audio signal peak (e.g. clapping hands in front of microphone), we start an “audio.latency” trace event. When the output stream detects an audio peak, we stop the tracing event. The duration of the trace event should give us the total internal Chrome latency. **This excludes any latency incured from hardware** such as a microphone or sound card's internal buffers. ## Measuring Latency ### Prerequisites * The computer must have a microphone input accessible through `getUserMedia()` * Only the test page and `chrome://tracing` should be open. * The test page must have one call to `getUserMedia()` + one audio output (e.g. one media element OR one WebAudio graph). * The surrounding area should be relatively quiet. * If echo cancellation is disabled, consider lowering speaker volume or OS volume. * **Trace recording must be started before any streams are created** by the test page, or there will be no traces. One can check that there are no `Input Controllers` or `Output Streams` in the chrome://media-internals audio tab, as pictured below. ![No streams](latency_tracing_media_internals.png) ### Steps * Open the latest version of Chrome (114.0.5695.0 or later). * Open chrome://tracing. * Record a new trace selecting the “audio” and the “audio.latency” categories. ![Selecting tracing categories](latency_tracing_tracing_categories.png) * In a separate tab, open the [test page](#Test-pages). * Initialize the test page, so that it is capturing audio using `getUserMedia()` and playing out the captured stream. * Repeatedly clap next to the microphone, clearly and loudly, waiting roughly 1 second between claps. * Stop the trace. * Look for the `AmplitudePeak` trace event: the wall duration corresponds to the measured latency ![Viewing results](latency_tracing_results.png) ## Test pages ### Baseline latency test page The simplest latency test page involves directly routing a `getUserMedia()` MediaStream to an `