Repository navigation
fix: report speech end timestamps across stt plugins - #7796
Merged
chenghao-mou merged 50 commits intoNov 2, 2026
Merged
chenghao-mou merged 50 commits into
chenghao-mou merged 50 commits into
Conversation
The default stt_node offsets provider timestamps from the session start, but the recognizer converted them with the pipeline's first audio frame. On a pipeline created after a handoff the two bases differ by the session's age, so stopped_speaking_at landed in the future and was clamped to the arrival time. The stream now absorbs the delay between its creation and its first frame, and re-anchors on the next frame after a reconnect, so its offset is exact on the caller's timeline. The default node records the base it measured from on the pipeline, and the recognizer adds that same base. A custom node that forwards provider timestamps untouched is anchored on the pipeline's creation, when it opens its stream. Addresses AGT-3678 Co-authored-by: Andraž Pajtler <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
…irst-audio based Two review findings. A frame queued while a connection fails is the first audio the next connection sends, but the offset was only anchored on push, so that frame kept the old connection's offset. The stream now anchors on the first frame each attempt consumes, with the capture time recorded at push. A node that builds events itself, relative to its first frame, was anchored on the pipeline's creation. An undeclared offset now means the stream's timeline starts with its first audio, so such streams keep a zero offset and the pipeline is stamped by the first frame pushed, as before this change. Only the default node, which declares a session-relative offset, is anchored on the session input start.
A resampler can hold audio across pushes, so its first output can carry samples from an earlier frame. Stamping it with the push that released it anchored the offset late by the time between the two pushes. Track the capture time of the oldest held sample and stamp each resampled frame from there.
A resampler can release audio from several pushes at once. Stamping the later outputs by adding durations erased the gap between those pushes, so a retry starting on one of them was anchored early. Track the held input as capture spans and advance through them per output frame.
Carry provider speech-end timing through END_OF_SPEECH so STT turn metrics retain the word timestamp instead of replacing it with event arrival. Keep unknown timestamps unset and clear Deepgram's cached final timing between turns and connections. Addresses AGT-3678 and the EOS reporting case in #7651. Co-authored-by: Andraž Pajtler <[email protected]>
Keep the change small. The offset is anchored on the first frame pushed to each attempt; a frame still queued when a connection fails is left as a TODO. Resampled frames are no longer stamped individually, so resampler buffering is a millisecond-level approximation.
Apply speaker filtering and formatting only to transcripts so timed EOS events still close turns and do not rewrite shared transcript text. Use word timing for Inference endpoints; billed audio duration does not identify when speech ended.
Soniox and Speechmatics Linden gateway finals carry utterance spans without word timestamps. Preserve those endpoints when every configured model uses that duration contract. Leave billing and unknown durations untimed. The timing semantics were checked against agent-gateway 69bcc23d088b.
chenghao-mou
marked this pull request as draft
October 13, 2026 23:48
Carry provider speech end timestamps and local VAD anchors through endpoint events. Normalize stream offsets and exclude billing duration, trailing silence, and audio from earlier pooled sessions. Add provider-specific regression coverage. Addresses AGT-3678 Co-authored-by: Andraž Pajtler <[email protected]>
The stream encoded one timeline in six fields and turned the caller's origin into an offset and back. Move the timeline into RecognizeStream._InputChan, which sees every push and every read. The channel stores the origin and anchors the offset when a connection reads its first frame. That frame was captured at the last push minus the audio still queued. This fixes the case where a connection fails before it reads: the retry now anchors on the oldest queued frame, not on the next push. A value set through the setter now means that the timeline began that many seconds ago, also after the first frame.
The push-audio stub left input_started_at as a truthy MagicMock, so no test reached the stamping branch. Reset it to None and assert it again. State the pipeline anchor contract next to the field.
The anchor took the last push minus the queued audio. A pause between queued frames is not in that sum, so the anchor moved forward by the pause. Also keep the push time of each queued frame. A frame is pushed after it is captured, so both values are upper bounds on its capture start: take the earlier one. It is exact across a pause and for a burst of buffered audio.
A leg was seeded only when it was created. If the caller set the offset after the first leg started, that leg kept a zero offset. Seed a leg that was not seeded when the first frame is forwarded to it. The outer stream has read that frame, so its timeline has a start.
The module docstring said a custom node is anchored on the pipeline's creation. It counts from its first audio, as on main.
…om:livekit/agents into chenghao/fix/AGT-3678-stt-eos-timestamps
Contributor
STT Test ResultsStatus: ✗ Some tests failed
Failed Tests
Skipped Tests
Triggered by workflow run #5474 |
Reanchor each Reson8 connection on its first audio frame instead of rewriting the caller timeline. Exercise real input and shutdown in the reconnect test, and correct the Sarvam offset comment.
davidzhao
reviewed
Oct 31, 2026
davidzhao
left a comment
Member
There was a problem hiding this comment.
another one from codex:
[OpenAI](https://github.com/livekit/agents/blob/864446bc8/livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/stt.py#L837) and [Mistral](https://github.com/livekit/agents/blob/864446bc8/livekit-plugins/livekit-plugins-mistralai/livekit/plugins/mistralai/stt.py#L553) calculate speech end from the wall clock when the VAD event is consumed. Their VAD receives audio after connection setup and through a sender that can block. I queued captured audio behind a nine-second OpenAI configuration delay: expected EOS was 1000.7, but it reported 1009.7. Map the VAD boundary to captured audio time, and test queued audio during setup and reconnect.
Map Gradium provider timestamps around inserted VAD silence. Anchor OpenAI local VAD events to captured audio, including queued audio and reconnects. Keep the current STT boundary when an untimed final arrives. Co-authored-by: David Zhao <[email protected]>
Queued audio can reach VAD after connection setup or a blocked send. Use its audio timestamp with the capture anchor so those delays do not shift the speech boundary. Cover setup and send delays on first connect and reconnect, and retain the boundary across a slow flush. Co-authored-by: David Zhao <[email protected]>
Move the padding bookkeeping into a _PaddedTimeline helper. Provider timestamps arrive in order, so padding that ends before a timestamp is folded into a running total instead of being summed on every lookup for the rest of the connection. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Member
Author
updated the timestamp to use the event creation time instead. |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
davidzhao
approved these changes
Nov 2, 2026
chenghao-mou
added a commit
that referenced
this pull request
Nov 2, 2026
Port #7795 and #7796 onto the shared STT connection coordinator, with #7739 that they build on. Each provider connection restarts the input clock. RTZR detects idle in the send loop, and Gladia and Reson8 re-anchor each session on its first frame. Co-Authored-By: Claude Opus 5.5 <[email protected]>
peirangong-baseten
added a commit
to peirangong-baseten/agents
that referenced
this pull request
Nov 12, 2026
Conflict in tests/test_plugin_baseten_stt.py: main (livekit#8510) moved the Whisper tests onto an in-process FakeWebSocket under virtual time. The v2 tests are moved the same way, since a real local server times out on the virtual clock: the fake server now answers each event as the client sends it, and its segment times count the socket's own audio. main (livekit#7796) also re-anchors start_time_offset on the first frame each connection reads. A reconnected v2 socket's clock starts at the replayed audio, before that frame, so the stream now uses the live offset only until its first reconnect after reading audio, and keeps that anchor from then on. The offset test starts its audio 1 s after the offset is set and fails both with the anchor read at connect time and with the live offset throughout. Co-Authored-By: Claude Opus 5.5 <[email protected]>
dhruvladia-sarvam
added a commit
to dhruvladia-sarvam/agents
that referenced
this pull request
Nov 18, 2026
Conflict in tests/test_plugin_sarvam_stt.py: main added REST timestamp tests where this branch added the transcription_delay test; both kept. STTRealtime goes back to main: livekit#7796 keeps its END_OF_SPEECH untimed (test_manual_eos_precedes_final_received_during_send), and its finals already carry audio-position timing. This PR now changes only the legacy sarvam.STT stream. With livekit#7796's framework change, an untimed final after END_OF_SPEECH no longer replaces the turn's anchor, so the transcription_delay test also covers a final that arrives after the EOS fallback. The fake WebSocket gains a no-op ping, because that case idles past the liveness probe interval. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Report speech-end timestamps for live-tested STT configurations and retain clock fixes across providers. Sarvam realtime keeps untimed EOS with corrected manual ordering. Untimed transcripts that follow EOS retain the current turn’s boundary.
Paced tests follow @Malik1234567891011's proposal. AssemblyAI gateway parameter forwarding is tracked separately in livekit/agent-gateway#1827.
Stacked on #7795. Addresses AGT-3678 (Linear) and #7651 (@AndrazP's diagnosis). Reconnect handling follows @longcw's review.
@davidzhao’s review identified delayed local VAD timestamps; his Gradium and consumer findings were also reproduced. The fixes remove synthetic padding from Gradium timing, use captured audio time for OpenAI and Mistral local VAD, and retain EOS across untimed finals.
Plugin status
Changes are relative to #7795, which supplies the shared clock fix. Only changed production paths are listed. EOS checks use the paced stream tests.
Live checks ran on 2026-10-30; Gradium, OpenAI, and Mistral were rechecked on 2026-11-01. Reconnect checks use real provider connections and verify the original audio timeline after reconnection. OpenAI also reuses a live pooled socket; Sarvam checks nonzero session offsets. RTZR's English-fixture WER remains exempt; its speech timing passed. Reson8’s internal-reconnect probe adds a 1 s delay before reopening to avoid its connection limit; the socket-failure probe uses the normal retry path.
ink-whisper(legacy)last_word_endend_text.stop_svad_flush=TrueInitial prompt and agent context
Model: GPT-6 Astra
Clarification for Azure-related exclusions:
Latest scope:
Final validation scope: