feat(deepgram): use Configure control message for mid-stream keyterm updates#5809
Open
Panmax wants to merge 5 commits into
Open
feat(deepgram): use Configure control message for mid-stream keyterm updates#5809Panmax wants to merge 5 commits into
Panmax wants to merge 5 commits into
Conversation
…pdates When only keyterm, eot thresholds, or language_hint are updated, send a Deepgram Configure control message instead of reconnecting the WebSocket. This avoids dropping in-progress speech recognition when options are updated mid-stream (e.g. updating keyterms while the user is speaking). Options that cannot be updated mid-stream (model, sample_rate, mip_opt_out, endpoint_url, tags) still trigger a full reconnect. Ref: https://developers.deepgram.com/docs/keyterm#configure-control-message Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Wrap the WebSocket send in an async helper that re-checks connection state and catches exceptions gracefully, avoiding unhandled task errors if the WebSocket is closing when the coroutine executes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Replace asyncio.ensure_future with tracked asyncio.create_task - Fall back to reconnect when Configure send fails instead of silently dropping - Handle ConfigureSuccess/ConfigureFailure responses from Deepgram - Cancel pending configure task on WebSocket cleanup Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
keyterm, EOT thresholds, orlanguage_hintare updated viaupdate_options(), send a Deepgram Configure control message instead of reconnecting the WebSocketmodel,sample_rate,mip_opt_out,endpoint_url,tags) still trigger a full reconnect as beforeMotivation
Currently, any call to
SpeechStreamv2.update_options()triggers_reconnect_event.set(), which tears down the active WebSocket and reconnects. If this happens while the user is speaking, any in-progress INTERIM_TRANSCRIPT is lost and the final transcript may be incomplete.Deepgram's Flux models support a
Configurecontrol message that allows updating keyterms, EOT thresholds, and language hints mid-stream without reconnecting:{ "type": "Configure", "keyterms": ["term1", "term2"], "thresholds": { "eot_threshold": 0.8, "eot_timeout_ms": 5000 } }Ref: https://developers.deepgram.com/docs/flux/configure#configure-message
Changes
self._wsinstance variable toSpeechStreamv2to hold the current WebSocket reference_send_configure()method that constructs and sends the Configure control messageupdate_options()to check whether the update requires a reconnect or can be applied mid-stream via Configure messageConfigureSuccess/ConfigureFailureresponses from Deepgram — on failure, fall back to reconnect so options still take effectasyncio.create_taskwith tracked reference instead of fire-and-forgetensure_future; cancel pending task on WebSocket cleanupTest plan
🤖 Generated with Claude Code