Skip to content

feat(deepgram): support diarize_model option and V2 diarization#6104

Open
anshulkulhari7 wants to merge 2 commits into
livekit:mainfrom
anshulkulhari7:feat/6038-deepgram-diarize-v2
Open

feat(deepgram): support diarize_model option and V2 diarization#6104
anshulkulhari7 wants to merge 2 commits into
livekit:mainfrom
anshulkulhari7:feat/6038-deepgram-diarize-v2

Conversation

@anshulkulhari7

Copy link
Copy Markdown
Contributor

Summary

Adds support for the Deepgram diarize_model option to the Deepgram STT plugin, enabling
selection of the diarization model version β€” including the new V2 Diarization batch
diarizer announced in Deepgram's 2026-05-13 changelog.

diarize_model accepts "latest", "v2", or "v1". Setting it enables diarization and
selects the model version in a single parameter (no need to also set diarize=true). Per
Deepgram's diarization docs, "v2" is a
pre-recorded/batch-only diarizer, while "latest"/"v1" work for both streaming and
pre-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: new diarize_model: str field (empty string = not set).
  • STT.__init__: new diarize_model: NotGivenOr[str] = NOT_GIVEN argument + docstring.
  • STT._recognize_impl: include diarize_model in the pre-recorded request params when set.
  • SpeechStream._connect_ws: include diarize_model in the live request params when set.
  • STT.update_options / SpeechStream.update_options: allow updating diarize_model.

No behavior changes for existing callers β€” when diarize_model is not provided, the request
params are identical to before.

Tests

Added unit tests under tests/test_plugin_deepgram_stt.py (mocked, no live keys/network) that
assert diarize_model is included in the request params the plugin builds for both the
pre-recorded and live paths, and that update_options(diarize_model=...) updates the stored
option:

tests/test_plugin_deepgram_stt.py ......                                 [100%]
6 passed

Verified locally: ruff check, ruff format --check, and mypy (repo config) are clean on
the changed files.


AI-assisted: this change was developed with AI assistance and reviewed/verified by the author.

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
@anshulkulhari7 anshulkulhari7 requested a review from a team as a code owner June 15, 2026 09:55

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 4 potential issues.

Open in Devin Review

Comment on lines 671 to +674
if self._opts.enable_diarization:
live_config["diarize"] = True
if self._opts.diarize_model:
live_config["diarize_model"] = self._opts.diarize_model

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ”΄ 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.

Suggested change
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
Open in Devin Review

Was this helpful? React with πŸ‘ or πŸ‘Ž to provide feedback.

Comment on lines 381 to 387
sample_rate=sample_rate,
no_delay=no_delay,
endpointing_ms=endpointing_ms,
diarize_model=diarize_model,
filler_words=filler_words,
keywords=keywords,
keyterm=keyterm,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚩 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)

Open in Devin Review

Was this helpful? React with πŸ‘ or πŸ‘Ž to provide feedback.

Comment on lines +243 to 246
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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚩 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.

Open in Devin Review

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Deepgram STT diarize_model option and V2 Diarization

1 participant