feat(api/transcription): include segments + duration + language on stream done event#9709
Merged
Merged
Conversation
…ream done event streamTranscription previously emitted a done event with just `text`, matching the OpenAI streaming spec exactly. Streaming clients that need per-utterance timings or audio duration had to fall back to the non-streaming JSON path — and that path is exactly the one that trips on ResponseHeaderTimeout when whisper requests queue behind each other on a SingleThread backend. Extend the done event to additively carry `language`, `duration`, and a `segments` array (id, start, end, text — start/end as float seconds, matching TranscriptionSegmentSeconds). Empty / zero values are still omitted; spec-compliant clients ignore the new fields. This unblocks notary's streaming Transcribe (companion change in the notary repo) so it produces the same TranscriptionResult shape as the JSON path while sidestepping the queue-induced header timeouts. Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Assisted-by: Claude:claude-opus-4-7 [Claude Code]
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.
Summary
Extends the
transcript.text.doneSSE payload emitted bystreamTranscriptionto additively carrylanguage,duration, and asegmentsarray so streaming clients can build the sameTranscriptionResultSecondsshape they get from the non-streaming JSON path.Why
Streaming clients (e.g. notetaker / notary) want streaming semantics for one big practical reason: the JSON path's
ResponseHeaderTimeouttrips when whisper requests queue behind each other on aSingleThreadbackend.streamTranscriptionfixes that by flushing 200 + headers immediately, but until now the done event only carriedtext— clients that needed per-utterance timings or audio duration had to fall back to the JSON path and accept the queue-induced timeouts again.This change closes the loop: the streaming endpoint becomes a strict superset of the JSON endpoint's body, and clients can stay on SSE end-to-end.
Compatibility
textis mandated ontranscript.text.done; spec-compliant clients ignore unknown fields.Language == "",Duration == 0,len(Segments) == 0), so a transcription that came from a backend without these signals emits the same shape as before.start/endare float seconds (matchingTranscriptionSegmentSeconds.Seconds()from the JSON path) so clients can share decoding logic.Test plan
POST /v1/audio/transcriptionswithstream=trueagainst a model that emits segment timings (whisper-cpp). Verify the finaldata: {...}line before[DONE]includessegmentsanddurationand matches the JSON-mode response for the same audio.textand thesegmentsfield is absent (omitempty preserved).Companion change
The notetaker repo's notary client switches its
Transcribeto streaming and consumes these fields in the same shape as its existing JSON-path parser (internal/shared/localai/client.go::parseTranscriptionStream). Without this server change, the streaming client falls through to text-only results — so this PR completes the round trip but isn't a breaking dependency.🤖 Generated with Claude Code