Skip to content

feat(elevenlabs): make realtime STT audio chunk duration configurable - #7183

Open
stevensukma wants to merge 1 commit into
livekit:mainfrom
stevensukma:feature/elevenlabs-stt-chunk-duration
Open

feat(elevenlabs): make realtime STT audio chunk duration configurable#7183
stevensukma wants to merge 1 commit into
livekit:mainfrom
stevensukma:feature/elevenlabs-stt-chunk-duration

Conversation

@stevensukma

Copy link
Copy Markdown

ElevenLabs realtime STT currently sends audio in hardcoded 50 ms chunks. Add audio_chunk_duration_ms to the STT constructor so applications can tune message frequency and buffering latency while preserving the existing default.

Closes #7182. The feature issue is open for discussion; feedback on the API name and scope is welcome.

from livekit.plugins import elevenlabs

stt = elevenlabs.STT(
    model="scribe_v2_realtime",
    audio_chunk_duration_ms=100,
)

The option accepts positive integer milliseconds, applies only to realtime STT, and is set at construction time. At 100 ms, continuous audio produces approximately 10 audio messages per second instead of 20, with up to 50 ms additional buffering. Partial chunks are still sent before the commit. This does not add reconnect pacing or establish that provider queue errors are resolved.

Validation

  • 68 ElevenLabs STT tests passed, including send-loop tests against a fake WebSocket at 8, 16, and 48 kHz with 1, 50, 75, 100, and 200 ms chunks. Tests cover release before flush, byte-for-byte audio preservation, partial tails, and commit ordering.
  • Repository-wide ruff check . and ruff format --check . passed using Ruff 0.15.22 from the upstream lockfile.
  • Targeted mypy for the modified plugin source and git diff --check passed. Full repository type checking and the full test suite have not been run.
  • Live provider validation has not been run.

The constructor option is documented in its API docstring and the plugin README. No changelog or package version changes are included, per CONTRIBUTING.md.

@stevensukma
stevensukma requested a review from a team as a code owner September 9, 2026 03:52
@CLAassistant

CLAassistant commented Sep 9, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@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 1 potential issue.

Devin Review

Comment on lines +504 to +505
# Buffer audio into chunks of the configured duration.
samples_per_chunk = self._opts.sample_rate * self._opts.audio_chunk_duration_ms // 1000

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.

🟡 Reconnects discard buffered speech

When update_options reconnects a live stream, send_task discards audio buffered below the configured chunk size. Larger durations can omit up to one chunk from transcription.

Prompt for agents
The configured AudioByteStream is local to send_task in livekit-plugins/livekit-plugins-elevenlabs/livekit/plugins/elevenlabs/stt.py. SpeechStream.update_options sets _reconnect_event, and the run loop then cancels send_task and creates a new one after reconnecting. Any audio already removed from _input_ch but not yet emitted as a complete configured chunk remains only in the old AudioByteStream and is lost. This existed as a small 50 ms window, but configurable chunk durations make the loss arbitrarily large. Preserve pending PCM across option-driven reconnects, either by keeping the chunker outside the per-WebSocket task or explicitly carrying its buffered tail into the replacement connection. Ensure ordering remains intact and do not commit the tail to the old connection if it belongs on the new one.
Devin Review

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

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.

Allow configuring ElevenLabs realtime STT audio chunk duration

2 participants