From 75be7e49413075b4fe29d297dd6604b4f7e9c1cd Mon Sep 17 00:00:00 2001 From: "Alan Ding (Google)" Date: Thu, 20 Aug 2026 15:40:41 -0700 Subject: [PATCH 1/2] Expand on limitations of existing speech recognition events Added detailed explanations regarding the limitations of existing API surfaces for tracking latency in speech recognition in the Alternatives Considered section, including issues with `speechstart` and `speechend` events and the implications of modifying `event.timeStamp`. --- explainers/speech-recognition-result-timestamps.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/explainers/speech-recognition-result-timestamps.md b/explainers/speech-recognition-result-timestamps.md index 0200cc5..8d77cf5 100644 --- a/explainers/speech-recognition-result-timestamps.md +++ b/explainers/speech-recognition-result-timestamps.md @@ -123,3 +123,15 @@ To mitigate fingerprinting vectors, browser implementations MUST apply timestamp - **Browser-Generated Warning Events (`onprocessinglag`):** Simple for web applications to catch, but fails to accommodate varying latency thresholds across different use cases (e.g. real-time meeting captioning requires <200ms latency, while dictation tools tolerate multi-second delays). - **Internal Processing Queue Metric (`queueDepth`):** Directly exposes engine backlogs, but is difficult to standardize across fragmented engine architectures, model types, and buffering strategies. - **Binary Status Flag (`isRealTime`):** Simple boolean check, but lacks numerical precision for applications seeking to track progressive latency degradation trendlines. +- **Existing API Surfaces (Events):** Existing events were deemed insufficient because: + 1. **`speechstart` and `speechend` Events:** + The Web Speech API specification defines `speechstart` and `speechend` events on the `SpeechRecognition` interface. However, these events cannot solve the continuous latency tracking problem: + * **Session-level vs. Result-level Granularity:** In continuous recognition mode, `speechstart` and `soundstart` fire once when voice activity is first detected at the beginning of the session. They do not fire for every individual phrase or sentence returned in subsequent `SpeechRecognitionResult` events. + * **Inequality with Result Audio Boundaries:** Because `speechstart` only marks initial voice activity, `speechstart.timeStamp` is not equal to `result.audioStartTime` for any subsequent utterance emitted throughout a session. + * **Fragile Event Correlation:** Even if engines fired `speechstart`/`speechend` around each phrase, associating separate asynchronous DOM events with streaming interim and final `SpeechRecognitionResult` objects requires complex, error-prone client-side state tracking (poor ergonomics). + 2. **Overloading `event.timeStamp` on Result Events:** + Another alternative considered was modifying `event.timeStamp` on the `result` event to match the speech timing: + * **Eliminates Latency Calculation:** `event.timeStamp` indicates when the browser dispatched the DOM event on the document timeline. Keeping `event.timeStamp` intact while providing `result.audioEndTime` allows web applications to measure speech recognition and translation processing delay: + $$\text{latencyMs} = \text{event.timeStamp} - \text{result.audioEndTime}$$ + * Overwriting `event.timeStamp` would conflate acoustic timing with main-thread dispatch time, eliminating the ability to detect processing lag. +Attaching `audioStartTime` and `audioEndTime` directly to `SpeechRecognitionResult` provides a 1:1 association between the recognized transcript text and its corresponding acoustic timeline. From 5b8b99a7f35f5a7592570bc19102a55ed6f0d932 Mon Sep 17 00:00:00 2001 From: "Alan Ding (Google)" Date: Thu, 20 Aug 2026 17:07:32 -0700 Subject: [PATCH 2/2] Refactor speech recognition timestamps to use seconds Updated the speech recognition result timestamps to use seconds instead of milliseconds, improving consistency with other Web APIs. Added detailed explanations for the choice of time representation, proposed behavior, and security considerations. Based off of comments from https://github.com/WebAudio/web-speech-api/pull/205 --- .../speech-recognition-result-timestamps.md | 115 ++++++++++++------ 1 file changed, 78 insertions(+), 37 deletions(-) diff --git a/explainers/speech-recognition-result-timestamps.md b/explainers/speech-recognition-result-timestamps.md index 8d77cf5..ff85d63 100644 --- a/explainers/speech-recognition-result-timestamps.md +++ b/explainers/speech-recognition-result-timestamps.md @@ -6,70 +6,103 @@ The Web Speech API currently does not expose the start and end timestamps of the source audio corresponding to a given transcription result (`SpeechRecognitionResult`). This limitation creates two major challenges for API clients and end users: -- **Timeline Association:** Developers cannot readily associate transcribed text with specific segments of the audio source, making it difficult to map generated captions to media timelines or audio tracks. +- **Timeline Association:** Developers cannot readily associate transcribed text with specific segments of the audio source, making it difficult to map generated captions to media timelines, audio tracks, or video frames. - **Latency Tracking & Backend Failover:** With the adoption of on-device Automatic Speech Recognition (ASR) to improve privacy and reduce server costs, processing performance becomes heavily dependent on local client hardware resources. The Web Speech API acts as a "black box" regarding local processing delays. Developers cannot programmatically calculate transcription latency or detect when on-device models fall behind real-time. This leads to poor user experiences (e.g. caption lag during live video conferencing) and deprives applications of the signal needed to seamlessly fail over to high-performance cloud backends. ### Proposed Solution -We propose extending the `SpeechRecognitionResult` interface to include optional (nullable) `audioStartTime` and `audioEndTime` attributes. +We propose extending the `SpeechRecognitionResult` interface to include `audioStartTime` and `audioEndTime` attributes. #### Web IDL Definition ```webidl partial interface SpeechRecognitionResult { - // Start timestamp of the audio segment in milliseconds (relative to the start of the audio stream) - readonly attribute DOMHighResTimeStamp? audioStartTime; + // Start timestamp of the audio segment in seconds relative to the start of the audio stream (0.0s). + readonly attribute double audioStartTime; - // End timestamp of the audio segment in milliseconds (relative to the start of the audio stream) - readonly attribute DOMHighResTimeStamp? audioEndTime; + // End timestamp of the audio segment in seconds relative to the start of the audio stream. + readonly attribute double audioEndTime; }; ``` +### Choice of Time Representation: Seconds as `double` + +The timestamps `audioStartTime` and `audioEndTime` are defined as `double` representing **seconds**, rather than `DOMHighResTimeStamp` (milliseconds). This design choice is based on the following considerations: + +1. **Consistency with Adjacent Web Audio & Media APIs:** + * In adjacent W3C media specifications, media-local stream timelines are universally represented in **seconds** as a `double`: + * **Web Audio API:** [`BaseAudioContext.currentTime`](https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-currenttime) (seconds) + * **HTML Media Elements:** [`HTMLMediaElement.currentTime`](https://html.spec.whatwg.org/multipage/media.html#dom-media-currenttime) (seconds) + * **AudioParam Scheduling:** [`AudioParam.setValueAtTime()`](https://webaudio.github.io/web-audio-api/#dom-audioparam-setvalueattime) (seconds) + * Using seconds ensures seamless interoperability when developers route audio between `