feat(soniox): populate SpeechData.words with per-word timing and confidence#6292
Draft
FurlanLuka wants to merge 1 commit into
Draft
feat(soniox): populate SpeechData.words with per-word timing and confidence#6292FurlanLuka wants to merge 1 commit into
FurlanLuka wants to merge 1 commit into
Conversation
β¦idence Soniox streams sub-word tokens that each carry confidence, start_ms and end_ms, but the plugin previously kept only the per-transcript mean confidence and dropped the per-token metadata. Group consecutive tokens into words at whitespace boundaries (or at token boundaries for the unspaced scripts among Soniox's supported languages: Han, Kana and Thai) and expose them as TimedString entries on SpeechData.words, with each word's confidence being the mean of its tokens' confidences.
|
|
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.
What
The Soniox websocket API returns per-token
confidence,start_msandend_ms, but the plugin currently keeps only the per-transcript mean confidence β the per-token metadata is dropped. This PR groups consecutive sub-word tokens ("walk" + "ing") into words and exposes them asTimedStringentries onSpeechData.words, following the Deepgram plugin's precedent (offset applied to times,start_time_offsetattribute set).Word confidence = mean of its tokens' confidences; word timing spans first token
start_msβ last tokenend_ms.Why
Word-level ASR confidence enables downstream consumers to detect likely mistranscriptions. Our production use case (language-learning voice agent): the agent issues grammar corrections against phrases the learner never said β ~16% of corrections traced to ASR artifacts. A plausible-in-context mishear ("walking" β "working") is invisible to text-only downstream logic but shows up as a per-word confidence dip. The scalar per-transcript mean (added recently) is too coarse: one garbled word barely moves the mean of a long utterance.
Word-boundary rules
Open question for Soniox folks: is a leading space in
token["text"]a guaranteed word-start marker for spaced languages? If the server could emit an explicit boundary flag, the script-range heuristic here could be deleted.Notes
text, scalarconfidenceand timing fields are untouched;wordswas previously alwaysNonefor this plugin.wordsfollows the same side astext/confidence(the target side).INTERIM_TRANSCRIPT/PREFLIGHT_TRANSCRIPT(merged_speech_data), a word straddling the final/non-final seam may appear split until the endpoint β same instability interimtextalready has.speaker_idper word is first-token-wins, consistent with the transcript-level field.Testing
8 new tests in
tests/test_plugin_soniox_stt.py(existing fake-WebSocket harness): sub-word grouping + confidence mean,start_time_offsetapplication, Han/Thai token-boundary words,NOT_GIVENfallbacks when metadata absent,reset()clearing, merged final+non-final words, and end-to-endFINAL_TRANSCRIPTassertions.ruff check,ruff formatandscripts/check_types.py(mypy) all pass.π€ Generated with Claude Code