feat(elevenlabs): make realtime STT audio chunk duration configurable - #7183
Open
stevensukma wants to merge 1 commit into
Open
feat(elevenlabs): make realtime STT audio chunk duration configurable#7183stevensukma wants to merge 1 commit into
stevensukma wants to merge 1 commit into
Conversation
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 |
Contributor
There was a problem hiding this comment.
🟡 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
ElevenLabs realtime STT currently sends audio in hardcoded 50 ms chunks. Add
audio_chunk_duration_msto 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.
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
ruff check .andruff format --check .passed using Ruff 0.15.22 from the upstream lockfile.git diff --checkpassed. Full repository type checking and the full test suite have 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.