Repository navigation
fix(stt): support external AssemblyAI endpointing - #3066
rosetta-livekit-bot[bot] wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 0863e02 The changes in this PR will be included in the next version bump. This PR includes changesets to release 42 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Devin Review found 2 potential issues.
3 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
| } | ||
|
|
||
| vadStream?.endInput(); | ||
| for (const frame of audioStream.flush()) sendAudioFrame(frame); |
There was a problem hiding this comment.
🔴 Partial audio aborts final transcription
With external VAD enabled, send closes the detector before sending any audio left in the 50 ms buffer. The send callback pushes that audio into the closed detector and throws. AssemblyAI never receives the finalization request.
Learn more
The stream buffers incoming audio into 50 ms chunks. With external AssemblyAI endpointing, prepareAudioFrame feeds each chunk to the voice activity detector only when the writer sends it. The final partial chunk takes that same path after VADStream.endInput has marked the detector input closed. VADStream.pushFrame then throws synchronously, so the writer never sends the final request.
Example: Push three 20 ms frames into an AssemblyAI stream configured with an external VAD, then call endInput(). The writer sends 50 ms normally. Sending the padded 10 ms remainder calls the closed VAD, so the final transcript is not requested.
Recommended fix: Keep the detector input open until all remaining audio callbacks have run. Flush the tail before ending the detector on the immediate-write path, and defer detector EOF until buffered writes replay on the handoff path.
Was this helpful? React with 👍 or 👎 to provide feedback.
| vad: VAD | undefined, | ||
| externalEndpointing = false, | ||
| ): VAD | undefined { | ||
| if (externalEndpointing && isAssemblyAIModel(model)) return vad; |
There was a problem hiding this comment.
🔴 External VAD blocks stream completion
After endInput() on an external-VAD stream, run waits for processVAD before closing the detector. Silero leaves its event output open at input EOF. Transcript consumers never receive EOF, even after the gateway closes.
Learn more
This option lets AssemblyAI streams use a local voice activity detector such as Silero. VADStream.endInput closes only the detector input, and InferenceVADStream exits its inference loop without closing the event output when that input ends. processVAD remains blocked reading those events until canceled or until the output closes. finishFinalization cleans up the WebSocket and server-event channel, but run waits for the detector task before it cancels and closes the detector. The base stream closes its transcript queue only once that attempt returns.
Example: Use the bundled Silero VAD with external AssemblyAI endpointing, send an exact multiple of 50 ms, and call endInput(). A for await consumer receives the final transcript but waits forever for the stream to finish unless it explicitly closes it.
Recommended fix: Give the detector reader its own cancellation signal and cancel it when terminal finalization begins, before joining the tasks. Keep transcript reception independent so trailing provider events can drain, and test that a VAD whose output stays open at input EOF does not prevent transcript EOF.
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
Ports livekit/agents#8610 to support AssemblyAI turn finalization through LiveKit Inference while the audio stream remains open. Adds external VAD or framework-driven endpointing, ordered audio/finalize writes, 50 ms padding for short chunks, corrected timestamps, and stream-level manual-flush propagation.
Source: livekit/agents#8610
Source diff coverage
livekit-agents/livekit/agents/inference/stt.py-> adapted toagents/src/inference/stt.ts; camelCase public options and the existing JS WebSocket/handoff writer are used for external endpointing, VAD handling, padding, timestamp correction, and frozen stream capabilities. The generated public API update is recorded inagents/etc/agents.api.md.livekit-agents/livekit/agents/stt/fallback_adapter.py-> adapted toagents/src/stt/fallback_adapter.ts; the fallback stream delegates manual flush to its live child stream.livekit-agents/livekit/agents/stt/stt.py-> adapted toagents/src/stt/stt.ts; adds the TypeScriptSpeechStream.manualFlushcontract.livekit-agents/livekit/agents/voice/audio_recognition.py-> adapted toagents/src/voice/audio_recognition.ts; the pipeline reads manual-flush behavior from the live stream, with the existing registration capability fallback retained for structural custom-node streams.tests/test_inference_stt.py-> adapted toagents/src/inference/stt.test.ts; ports the source constructor/VAD, live-stream capability, ordered finalize, short-audio padding, and timestamp regressions into the Vitest gateway harness.tests/test_stt_fallback.py-> adapted toagents/src/stt/fallback_adapter.test.ts; ports the live-child manual-flush regression.Target-only release metadata:
.changeset/assemblyai-external-endpointing.mdadds a minor bump for the new public API.Validation
pnpm test agents/src/inference/stt.test.ts agents/src/stt/fallback_adapter.test.ts agents/src/voice/audio_recognition_manual_flush.test.ts(163 passed, 1 skipped)pnpm build:agentspnpm --filter @livekit/agents lintpnpm --filter @livekit/agents typecheckpnpm --filter @livekit/agents api:checkpnpm test agentsand serialpnpm test agents --maxWorkers=1were run. Both reached 5,111 passing tests and exposed unrelated timing flakes ininference/tts,tcp_session_transport, and oncetelemetry/loop_monitor; all failing files pass together when rerun in isolation (112 passed, 1 skipped).Runtime
cue-clivalidation could not run becausecue-cliand LiveKit credentials are unavailable in this workspace. The ported gateway and voice manual-flush tests validate the affected framework behavior locally.Ported from livekit/agents#8610
Original PR description
Summary
AssemblyAI can hold a turn open for a client endpoint, but Inference STT previously sent
session.finalizeonly when input ended. Withexternal_endpointing=True, AgentSession turn detection or a directflush()can finalize each turn while the audio stream stays open. A supplied VAD can drive finalization instead.The audio writer sends pending audio before finalize and pads a short flushed chunk to AssemblyAI’s 50 ms minimum. Select the provider’s turn detection separately, for example
extra_kwargs={"mode": "manual"}on U3.7 Realtime Agent.Validation
make checkpassed.Related gateway investigation and benchmark: livekit/agent-gateway#2055.