Description
The Web Speech API currently does not expose the start and end timestamps of the source audio corresponding to a transcription result (SpeechRecognitionResult).
While SpeechRecognitionEvent.timeStamp provides a single timestamp for the event itself, it does not convey the start time, end time, or duration of the acoustic speech segment within the audio stream.
Without acoustic bounds for each result, web applications cannot associate transcribed text with media timelines:
- Automated Subtitling & Caption Tracks: Cannot construct frame-accurate subtitle cues (
VTTCue(start, end, text)) for recorded video or audio.
- Interactive "Click-to-Seek" Transcripts: Cannot jump media playback (
mediaElement.currentTime = result.speechStartTime) to the exact moment a phrase was spoken.
- Live Video Conferencing & Recording Sync: In applications like Google Meet or WebRTC calls, captions displayed live cannot be accurately aligned with the recorded video track for post-meeting review or synchronized with video playout delay buffers.
- Text-Based Media Editing: Tools that allow users to edit audio/video by cutting or rearranging transcript text require precise acoustic boundaries for each segment.
Specification
Expose speech segment bounds on the SpeechRecognitionResult interface in seconds as a double, measured on the timeline of the audio stream consumed by the recognizer ($t = 0.0\text{s}$, marked by audiostart).
Web IDL
partial interface SpeechRecognitionResult {
// Start timestamp of the recognized speech segment in seconds relative to the audio stream (0.0s).
readonly attribute double speechStartTime;
// End timestamp of the recognized speech segment in seconds relative to the audio stream.
readonly attribute double speechEndTime;
};
Usage Example: Subtitling & "Click-to-Seek" Navigation
const mediaElement = document.querySelector('video');
const track = mediaElement.addTextTrack('captions', 'English', 'en');
track.mode = 'showing';
const recognition = new SpeechRecognition();
recognition.continuous = true;
recognition.interimResults = false;
recognition.onresult = (event) => {
for (let i = event.resultIndex; i < event.results.length; ++i) {
const result = event.results[i];
if (!result.isFinal) continue;
const transcriptText = result[0].transcript;
// 1. Create frame-accurate WebVTT cue directly from seconds
const cue = new VTTCue(result.speechStartTime, result.speechEndTime, transcriptText);
track.addCue(cue);
// 2. Click-to-seek transcript element
const item = document.createElement('p');
item.textContent = `[${result.speechStartTime.toFixed(1)}s] ${transcriptText}`;
item.onclick = () => {
mediaElement.currentTime = result.speechStartTime;
mediaElement.play();
};
document.getElementById('transcript').appendChild(item);
}
};
recognition.start(mediaElement.captureStream().getAudioTracks()[0]);
Security & Privacy Considerations
- Fingerprinting Mitigation: To mitigate micro-architectural timing attacks and hardware fingerprinting, user agents may reduce the resolution of
speechStartTime and speechEndTime or introduce jitter, in accordance with user agent security and privacy policies (consistent with [[HR-TIME-3]] and [[HTML]]).
Alternatives Considered
- Existing
SpeechRecognitionEvent.timeStamp: Represents a single point in time (the event occurrence in document time). It does not provide the duration or start/end acoustic boundaries of the utterance within the stream, making subtitle cue generation (VTTCue) and click-to-seek impossible.
- Separate Events (
speechstart / speechend): Fire only once at session voice-activity boundaries, cannot be correlated to individual stream results in continuous recognition, and do not provide segment start/end bounds per result.
DOMHighResTimeStamp (Milliseconds): Semantically represents time relative to document origin rather than a media stream timeline, and causes friction with existing W3C media APIs (HTMLMediaElement.currentTime, BaseAudioContext.currentTime, and VTTCue) which universally operate in seconds as a double.
Links & References
Description
The Web Speech API currently does not expose the start and end timestamps of the source audio corresponding to a transcription result (
SpeechRecognitionResult).While
SpeechRecognitionEvent.timeStampprovides a single timestamp for the event itself, it does not convey the start time, end time, or duration of the acoustic speech segment within the audio stream.Without acoustic bounds for each result, web applications cannot associate transcribed text with media timelines:
VTTCue(start, end, text)) for recorded video or audio.mediaElement.currentTime = result.speechStartTime) to the exact moment a phrase was spoken.Specification
Expose speech segment bounds on the$t = 0.0\text{s}$ , marked by
SpeechRecognitionResultinterface in seconds as adouble, measured on the timeline of the audio stream consumed by the recognizer (audiostart).Web IDL
Usage Example: Subtitling & "Click-to-Seek" Navigation
Security & Privacy Considerations
speechStartTimeandspeechEndTimeor introduce jitter, in accordance with user agent security and privacy policies (consistent with [[HR-TIME-3]] and [[HTML]]).Alternatives Considered
SpeechRecognitionEvent.timeStamp: Represents a single point in time (the event occurrence in document time). It does not provide the duration or start/end acoustic boundaries of the utterance within the stream, making subtitle cue generation (VTTCue) and click-to-seek impossible.speechstart/speechend): Fire only once at session voice-activity boundaries, cannot be correlated to individual stream results in continuous recognition, and do not provide segment start/end bounds per result.DOMHighResTimeStamp(Milliseconds): Semantically represents time relative to document origin rather than a media stream timeline, and causes friction with existing W3C media APIs (HTMLMediaElement.currentTime,BaseAudioContext.currentTime, andVTTCue) which universally operate in seconds as adouble.Links & References