feat(deepgram): support diarize_model option and V2 diarization#6104
feat(deepgram): support diarize_model option and V2 diarization#6104anshulkulhari7 wants to merge 2 commits into
Conversation
Add the Deepgram diarize_model option to the STT plugin so callers can select the diarization model version (latest, v2, or v1), including the new V2 batch diarizer. The option is passed through to both the pre-recorded and live request params, mirroring how existing options are wired. Backward-compatible: no change to requests when unset. Closes livekit#6038
| if self._opts.enable_diarization: | ||
| live_config["diarize"] = True | ||
| if self._opts.diarize_model: | ||
| live_config["diarize_model"] = self._opts.diarize_model |
There was a problem hiding this comment.
π΄ Missing diarize=True in streaming config when diarize_model is set without enable_diarization
In _connect_ws, diarize=True is only added when self._opts.enable_diarization is True (stt.py:671-672). When a user sets only diarize_model (per the docstring: "Enabling this turns on diarization without also needing enable_diarization"), the request sends diarize_model=X but NOT diarize=true. According to Deepgram's API, the diarize boolean parameter is what enables diarization; diarize_model selects which model to use. Without diarize=true, the diarize_model parameter is likely ignored, making the feature silently non-functional for users who follow the docstring and set only diarize_model.
| if self._opts.enable_diarization: | |
| live_config["diarize"] = True | |
| if self._opts.diarize_model: | |
| live_config["diarize_model"] = self._opts.diarize_model | |
| if self._opts.enable_diarization or self._opts.diarize_model: | |
| live_config["diarize"] = True | |
| if self._opts.diarize_model: | |
| live_config["diarize_model"] = self._opts.diarize_model |
Was this helpful? React with π or π to provide feedback.
| sample_rate=sample_rate, | ||
| no_delay=no_delay, | ||
| endpointing_ms=endpointing_ms, | ||
| diarize_model=diarize_model, | ||
| filler_words=filler_words, | ||
| keywords=keywords, | ||
| keyterm=keyterm, |
There was a problem hiding this comment.
π© Pre-existing: enable_diarization not forwarded to streams in update_options
In STT.update_options at lines 374-394, the stream.update_options() call forwards diarize_model (newly added) but does NOT forward enable_diarization, despite SpeechStream.update_options accepting it as a parameter (stt.py:460). This is a pre-existing omission that predates this PR. If a user calls stt.update_options(enable_diarization=True), the STT's own _opts is updated (line 344-345), but active streams won't pick up the change. The PR correctly adds forwarding for diarize_model but inherits this gap for enable_diarization.
(Refers to lines 374-394)
Was this helpful? React with π or π to provide feedback.
| if config.diarize_model: | ||
| recognize_config["diarize_model"] = config.diarize_model | ||
| if config.enable_diarization: | ||
| logger.warning("speaker diarization is not supported in non-streaming mode, ignoring") |
There was a problem hiding this comment.
π© Pre-recorded path also missing diarize=True for diarize_model
In _recognize_impl at lines 243-246, diarize_model is added to recognize_config but diarize=True is not. The existing code for enable_diarization only logs a misleading warning that 'speaker diarization is not supported in non-streaming mode' (Deepgram does support pre-recorded diarization). For consistency with the streaming fix in BUG-0002, the prerecorded path should also set recognize_config['diarize'] = True when diarize_model is specified. Additionally, the docstring mentions "v2" as a "pre-recorded only" model, confirming the intent that diarize_model should work in prerecorded mode.
Was this helpful? React with π or π to provide feedback.
STTCapabilities.diarization was derived solely from enable_diarization, so STT(diarize_model="latest") reported diarization=False. This contradicted the documented contract that diarize_model turns on diarization without enable_diarization, and broke MultiSpeakerAdapter, which raises ValueError when capabilities.diarization is False.
Summary
Adds support for the Deepgram
diarize_modeloption to the Deepgram STT plugin, enablingselection of the diarization model version β including the new V2 Diarization batch
diarizer announced in Deepgram's 2026-05-13 changelog.
diarize_modelaccepts"latest","v2", or"v1". Setting it enables diarization andselects the model version in a single parameter (no need to also set
diarize=true). PerDeepgram's diarization docs,
"v2"is apre-recorded/batch-only diarizer, while
"latest"/"v1"work for both streaming andpre-recorded requests β so the option is passed through on both code paths and the provider
validates support.
This is a minimal, backward-compatible option passthrough that mirrors how existing options
(
diarize,redact,keyterm, etc.) are wired into the live and pre-recorded request params.Closes #6038
Changes
STTOptions: newdiarize_model: strfield (empty string = not set).STT.__init__: newdiarize_model: NotGivenOr[str] = NOT_GIVENargument + docstring.STT._recognize_impl: includediarize_modelin the pre-recorded request params when set.SpeechStream._connect_ws: includediarize_modelin the live request params when set.STT.update_options/SpeechStream.update_options: allow updatingdiarize_model.No behavior changes for existing callers β when
diarize_modelis not provided, the requestparams are identical to before.
Tests
Added unit tests under
tests/test_plugin_deepgram_stt.py(mocked, no live keys/network) thatassert
diarize_modelis included in the request params the plugin builds for both thepre-recorded and live paths, and that
update_options(diarize_model=...)updates the storedoption:
Verified locally:
ruff check,ruff format --check, andmypy(repo config) are clean onthe changed files.
AI-assisted: this change was developed with AI assistance and reviewed/verified by the author.