Repository navigation
feat(elevenlabs): add STTv2 with streaming support for Scribe v2 - #3909
Conversation
This commit adds streaming speech-to-text support for ElevenLabs Scribe v2 API while maintaining backward compatibility with the existing STT implementation. Changes: - Added STTv2 class in stt_v2.py following the Deepgram pattern - Implements WebSocket-based real-time streaming transcription - Supports configurable VAD parameters and commit strategies - Audio buffering with 50ms chunks via AudioByteStream - Handles interim and final transcripts with proper event ordering - Supports sample rates from 8kHz to 48kHz - Added type definitions for STTModels, STTAudioFormat, and STTCommitStrategy Implementation follows the established pattern used by other streaming STT plugins (AssemblyAI, Azure, Deepgram) with concurrent send/recv tasks.
- Add _recognize_impl method (required by base class, raises NotImplementedError) - Fix transcript field name: use 'text' instead of 'transcript' - Add comprehensive logging throughout WebSocket communication - Add session_started message type handling - Log connection, send/recv tasks, transcripts, and errors
- Track last committed text to identify stale partial transcripts - Ignore partial transcripts that match last committed text - Clear last committed text when starting new speech segment - Handle empty committed transcripts by resetting state Fixes duplicate utterances caused by ElevenLabs sending partial_transcript messages after committed_transcript
Remove support for manual commit strategy to simplify implementation. ElevenLabs STTv2 now only supports VAD (Voice Activity Detection) mode for automatic speech segment detection. Changes: - Remove commit_strategy parameter from STTv2 and STTOptions - Simplify send_task by removing FlushSentinel handling - Remove frame counting and verbose logging - Hardcode to VAD mode in WebSocket connection 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Add automatic reconnection loop with _reconnect_event for handling connection issues - Add WebSocket keepalive task (30s ping interval) for connection stability - Add @utils.log_exceptions decorators to send_task and recv_task - Simplify task group cleanup to match Cartesia's pattern 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Add intelligent deduplication for ElevenLabs API duplicate text issue - Captures max_tokens_to_recompute from session_started config - Uses token-to-word ratio (0.75) for efficient duplicate detection - Handles punctuation normalization when comparing suffixes - Simplify partial transcript handling - Ignore partial_transcript events (UI-only, don't trigger agent) - Add detailed comments explaining ElevenLabs lacks correlation IDs - Fix speech segment detection using empty commits - Multiple committed_transcript events now grouped in one segment - Empty committed_transcript signals END_OF_SPEECH - Matches Cartesia's is_final pattern for better turn detection - Add comprehensive error handling for known ElevenLabs error types - Handles auth_error, quota_exceeded, transcriber_error, etc. - Add debug logging for investigating message structure - Add TODO markers for temporary exception and debug logging Fixes duplicate text issue where ElevenLabs returns phrases like "for tomorrow for tomorrow" due to token recomputation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
Thank you for this contribution to Livekit! Sharing the implementation from another project here if useful context. |
…duplicates Enhances the deduplication algorithm to check all sub-suffixes within each suffix window, catching duplicates even when followed by additional words. This handles cases like "if I can if I can uh" where the duplicate phrase "if I can" is followed by an extra word. The approach is language-agnostic and doesn't rely on hardcoded filler words, making it more robust across different languages. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…up logging - Add on_committed_transcript callback parameter for custom transcript processing - Remove built-in deduplication logic in favor of user-provided callbacks - Remove verbose debug logging to match Deepgram/Cartesia patterns - Simplify message handling by removing committed_transcript_with_timestamps - Remove development TODOs and debug comments 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
@yorrick I'm implementing the agent-js version right now, but I have some weird socket disconnections with code 1000. Not always but often after one "transaction" has been handled and the websocket is idling for few seconds. Logic wise I cannot see any difference to your inplementation, ...so my question: did you experience something similar too? Do You just reconnect the websocket and ignore it or did this not happening on your end? |
I do reconnect the websocket now, but I remember having seen that issue in dev before I implemented the reconnect indeed |
|
@louisjoecodes I noticed that I receive duplicated words in the See
(logs below) Now, initially I thought it was my fault and I dug in, but I don't find anything weird in my code (I don't think I'm sending duplicated audio frames); so I wanted to know whether this is something you are aware of on your side. cc @simllll is that something you noticed? |
|
Hi @yorrick, I believe the duplicate transcriptions are caused by a bug from our side. I should have a fix out soon. |
|
The fix is in, let me know if it works fine for you now. 🙂 |
@angelos-p nice, I don't see any duplicates now, everything looks good! |
@angelos-p I noticed that (at least sometimes), we receive a |
… retry and fallback adapters can kick in
I have noticed this as well, and causing the last partial transcript shown as duplicated interim transcripts in livekit agents. |
longcw
left a comment
There was a problem hiding this comment.
the pr looks good to me. I am more worried about this #3909 (comment) and the latency to the final transcript committed, it seems the vad on their side is sensitive to background noise that may not commit until it's very silent.
I am wondering how can we use our VAD and the manual commit_strategy.
|
I am going to merge this one, and merge the STTv2 to the original elevenlabs.STT streaming mode. |
Summary
Adds streaming speech-to-text support for ElevenLabs Scribe v2 API.
Changes
STTv2class instt_v2.pyfollowing the Deepgram and Cartesia patternSTTModels,STTAudioFormat, andSTTCommitStrategyQuestions
STTv2 approach: Is creating a separate
STTv2class (following the Deepgram pattern) the right approach for maintaining backward compatibility?Testing: I wasn't able to update
test_stt.py- the tests appear to be broken since May 2025 (make_test_speechis commented out in commit 64db393). I noticed that Deepgram STTv2 (PR deepgram: support for Flux #3245) was also added without test changes. I did the test with a full pipeline