Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ def update_options(
sample_rate=sample_rate,
no_delay=no_delay,
endpointing_ms=endpointing_ms,
enable_diarization=enable_diarization,

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.

🟡 Enabled diarization remains unavailable to adapters

After update_options(enable_diarization=True), open streams emit speaker IDs but capabilities.diarization stays false. MultiSpeakerAdapter rejects the STT even though diarization is active.

Learn more

The constructor initializes capabilities.diarization from the initial option in STT.init. The newly forwarded update changes the configuration of open sockets without updating that capability. MultiSpeakerAdapter gates construction on the capability, so an STT can produce speaker IDs while the adapter refuses it.

Example: Create STT(api_key="test-key"), open a stream, then call update_options(enable_diarization=True). The next Deepgram socket requests diarize=true, but MultiSpeakerAdapter(stt=instance) raises ValueError.

Recommended fix: Synchronize self._capabilities.diarization with an explicitly supplied enable_diarization in STT.update_options and cover both enabling and disabling with a test. Consider how existing wrappers cache the capabilities at construction.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

filler_words=filler_words,
keywords=keywords,
keyterm=keyterm,
Expand All @@ -421,6 +422,7 @@ def update_options(
numerals=numerals,
mip_opt_out=mip_opt_out,
vad_events=vad_events,
tags=tags,
endpoint_url=endpoint_url,
utterance_end_ms=utterance_end_ms,
dictation=dictation,
Expand Down
37 changes: 37 additions & 0 deletions tests/test_plugin_deepgram_stt.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,43 @@ async def ws_connect(self, url: str, **kwargs):
return self._ws


class _URLRecordingSession:
"""Hands out a fresh socket per connect and keeps every URL it was asked to open."""

def __init__(self) -> None:
self.closed = False
self.urls: list[str] = []

async def ws_connect(self, url: str, **kwargs):
self.urls.append(url)
ws = _LiveWS()
ws._response = SimpleNamespace(headers={}) # read for the dg- response headers
return ws


async def test_stt_update_options_reaches_open_streams_diarization_and_tags():
from urllib.parse import parse_qs, urlparse

from livekit.plugins.deepgram import STT

session = _URLRecordingSession()
instance = STT(api_key="test-key", language="en-US", http_session=session)
stream = instance.stream()
try:
await _wait_until(lambda: len(session.urls) == 1)
assert "diarize" not in parse_qs(urlparse(session.urls[0]).query)

instance.update_options(enable_diarization=True, tags=["prod"])

await _wait_until(lambda: len(session.urls) == 2)
query = parse_qs(urlparse(session.urls[1]).query)
assert query["diarize"] == ["true"]
assert query["tag"] == ["prod"]
finally:
await stream.aclose()
await instance.aclose()


class _DeadSocket:
"""A socket that has silently gone away: writes fail, the read side never notices.

Expand Down
Loading