-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fix(elevenlabs): end server vad turns #5872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
chenghao-mou
merged 3 commits into
livekit:main
from
he-yufeng:fix/elevenlabs-server-vad-eos
Jun 10, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
|
|
||
| from livekit.agents import stt | ||
| from livekit.agents.types import NOT_GIVEN | ||
| from livekit.plugins.elevenlabs import stt as elevenlabs_stt | ||
|
|
||
| pytestmark = pytest.mark.plugin("elevenlabs") | ||
|
|
||
|
|
||
| class _EventSink: | ||
| def __init__(self) -> None: | ||
| self.events: list[stt.SpeechEvent] = [] | ||
|
|
||
| def send_nowait(self, event: stt.SpeechEvent) -> None: | ||
| self.events.append(event) | ||
|
|
||
|
|
||
| def _new_stream(*, server_vad=NOT_GIVEN) -> elevenlabs_stt.SpeechStream: | ||
| stream = object.__new__(elevenlabs_stt.SpeechStream) | ||
| stream._opts = elevenlabs_stt.STTOptions( | ||
| model_id="scribe_v2_realtime", | ||
| api_key="test-key", | ||
| base_url=elevenlabs_stt.API_BASE_URL_V1, | ||
| language_code=None, | ||
| tag_audio_events=True, | ||
| include_timestamps=False, | ||
| sample_rate=16000, | ||
| server_vad=server_vad, | ||
| keyterms=NOT_GIVEN, | ||
| ) | ||
| stream._language = None | ||
| stream._event_ch = _EventSink() | ||
| stream._speaking = False | ||
| stream._start_time_offset = 0.0 | ||
| return stream | ||
|
|
||
|
|
||
| def _committed_transcript(text: str) -> dict: | ||
| return { | ||
| "message_type": "committed_transcript", | ||
| "text": text, | ||
| "words": [ | ||
| {"text": text, "start": 0.1, "end": 0.4}, | ||
| ] | ||
| if text | ||
| else [], | ||
| } | ||
|
|
||
|
|
||
| def test_server_vad_commit_emits_end_of_speech() -> None: | ||
| stream = _new_stream(server_vad={"vad_silence_threshold_secs": 0.5}) | ||
|
|
||
| stream._process_stream_event(_committed_transcript("hello")) | ||
|
|
||
| assert [event.type for event in stream._event_ch.events] == [ | ||
| stt.SpeechEventType.START_OF_SPEECH, | ||
| stt.SpeechEventType.FINAL_TRANSCRIPT, | ||
| stt.SpeechEventType.END_OF_SPEECH, | ||
| ] | ||
| assert stream._event_ch.events[1].alternatives[0].text == "hello" | ||
| assert stream._speaking is False | ||
|
|
||
|
|
||
| def test_manual_commit_still_waits_for_empty_commit() -> None: | ||
| stream = _new_stream(server_vad=None) | ||
|
|
||
| stream._process_stream_event(_committed_transcript("hello")) | ||
|
|
||
| assert [event.type for event in stream._event_ch.events] == [ | ||
| stt.SpeechEventType.START_OF_SPEECH, | ||
| stt.SpeechEventType.FINAL_TRANSCRIPT, | ||
| ] | ||
| assert stream._speaking is True | ||
|
|
||
| stream._process_stream_event(_committed_transcript("")) | ||
|
|
||
| assert stream._event_ch.events[-1].type == stt.SpeechEventType.END_OF_SPEECH | ||
| assert stream._speaking is False |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚩 Fix for pre-existing bug: NOT_GIVEN incorrectly treated as VAD-enabled
The old code at
livekit-plugins/livekit-plugins-elevenlabs/livekit/plugins/elevenlabs/stt.py:488hadcommit_strategy = "manual" if self._opts.server_vad is None else "vad". Since the default value ofserver_vadisNOT_GIVEN(notNone), theis Nonecheck evaluated toFalse, causingcommit_strategyto be"vad"for every user who didn't explicitly passserver_vad. The new_server_vadproperty correctly normalizes bothNOT_GIVENandNonetoNone, fixing the default commit strategy to"manual". This is a behavioral change for all users relying on the default — they were previously getting server-side VAD without knowing it.Was this helpful? React with 👍 or 👎 to provide feedback.