How I built a voice stream that stops instead of repeating itself: 2,000-char chunks, 1 read-ahead sentence, 0 replays
Ankita AI is a desktop AI assistant by Krish Verma, and it speaks its progress reports out loud. That sounds simple until the network drops mid-sentence. The obvious fix — just play the sentence again — is worse than the failure: the listener hears the same sentence twice and has no way to tell which copy is real. So the stream is built to die loudly instead of repeating itself. This is how that boundary works, and the one place it is still silent.
The rule: only a capability failure may fall back
The streaming path starts in prepareVoiceStreamClip (src/channels/voice-stream-clip.mjs). It asks the provider for exactly one chunk first, then pipes the iterator straight into the player's stdin. The fallback to a buffered clip is deliberately narrow: it fires only when the error carries the code VOICE_STREAM_UNSUPPORTED, which the Sarvam path sets for HTTP 404, 405, 415, 422 and 501 — capability or model failures that happen before any audio exists. Auth and rate-limit failures are not in that set, and neither is a stream that dies after audio started.
A mid-stream death throws. The iterator is closed, the controller aborts, and the sentence is never re-spoken. Only a clip that finishes cleanly gets cached (cached = Buffer.concat(chunks) runs after the loop completes), so a half-played sentence can never come back as a replay later. The delivery object the player reports — {mode, fallback, firstChunkMs} — carries the mode so the panel can show whether what you heard was streamed, buffered, or cached, instead of guessing.
The queue: one sentence ahead, no second chances
Playback is owned by VoiceSpeechQueue (src/automation/voice-speech-queue.mjs). Sentences are cut with chunkSentences — 190 characters for the Groq path, up to 2,000 characters per Sarvam chunk — and the queue pre-fetches at most one following sentence while the current one plays, hiding its TTS latency under live audio. The pending backlog is capped at 24 clips.
When a part fails, the queue's pump() catches it and calls onError — but only for non-abort errors. The entry is marked unavailable, resolves as not played, and the queue moves on. There is no retry for a failed part: the retry flag exists for reports interrupted by the user, not for synthesis that died. That is the whole point. A retry would need to know how much of the sentence already played, and the queue does not track that — so it refuses to guess.
The measured cost of the design is small: first audio arrived in 491 ms on the 10 November re-verification, with the first chunk consumed 32 ms later. The numbers were single samples, not a benchmark, but they are the reason streaming was worth building at all.
What the listener actually gets today
Here is the honest limit, and it is the reason this article exists. When a stream dies mid-sentence, the error travels up through onError into fail(session, error) in desktop/electron/voice.mjs — the failure is visible in the panel, but nothing is spoken. The listener hears half a sentence, then silence. Silence after half a sentence is easy to mistake for a pause, so they keep waiting for the rest.
That gap came out of a thread on Ahmad Dogar's TTS-voices article, where he put it plainly: he'd rather the player say something short when the stream dies. He is right, and I am going with the spoken note. There is already a precedent in the same code — a stop word gets a spoken Stopped. (STOPPED_LINE in desktop/electron/voice.mjs) — so a cut-off note would be a short fixed phrase through the same path, not a re-speak of the sentence. Re-speaking would reopen the double-play the whole design exists to prevent.
The open question
The part still undecided is what the note should say. A fixed phrase — "That update got cut off" — is honest about what happened and costs nothing to generate. Naming the sentence that died would be more useful, but it means speaking text the listener already half-heard, through the same queue that just failed. Tell me I'm wrong: is a fixed short phrase enough when the listener already heard the first half, or should the note name what was lost?
Ankita is open source at https://github.com/akyourowngames/A.N.K.I.T.A, and the site is https://ankita-sable.vercel.app. If you run spoken output anywhere — a voice assistant, a screen reader, a notification reader — how do you signal a cut-off stream without replaying it?
— Krish Verma, creator of Ankita AI
Top comments (4)
Refusing to guess is the right call. A retry that doesn't know how much already played gives the worst outcome: two copies and no way to tell which one counts. Job-site radios work the same way. If a call gets cut off, the listener says "say again" and the sender repeats on request. Nobody re-sends on their own. For your open question I'd go with the fixed phrase. "That update got cut off" tells me what happened and leaves it to me whether to ask for it again. Good that you labeled the 491 ms as a single sample and not a benchmark, too.
That's the vote I'm going with — the fixed phrase. Your radio analogy is exactly the shape of it: the listener decides whether to ask again, and Ankita never re-sends on its own. That's also why the note has to be fixed text rather than naming the sentence that died: the queue doesn't track how much already played — pump() in src/automation/voice-speech-queue.mjs marks a failed part unavailable and moves on — so anything that re-speaks the sentence reopens the double-play the whole design exists to prevent. The precedent is already in desktop/electron/voice.mjs: a stop word gets a spoken "Stopped." (STOPPED_LINE), so the cut-off note goes through the same path. One honest caveat: the note travels through the same queue that just failed, so if the provider is down entirely it may not play either — fail() only publishes phase: 'error' to the panel, which is the fallback. And thanks for catching the 491 ms note — single sample, not a benchmark, and I'll keep labelling it that way.
The "die loudly instead of repeating" rule is the right instinct — a retry that doesn't know how much already played really is worse than silence, as Sal said. On your open question, I'd go with "That update got cut off" over "The network dropped that part": the listener doesn't need a diagnosis, they need to know the sentence is done and nothing more is coming. The VOICE_STREAM_UNSUPPORTED split is the other detail I liked — treating a 404/415 as a capability failure while a mid-stream death just aborts keeps the fallback honest instead of papering over a real failure.
You and Sal agree, and so do I — "That update got cut off" it is. You're right about why: the listener needs to know the sentence is done, not a diagnosis of the network. The VOICE_STREAM_UNSUPPORTED split stays as it is: prepareVoiceStreamClip in src/channels/voice-stream-clip.mjs only falls back to a buffered clip on a capability failure (404/405/415/422/501) before any audio exists; a mid-stream death throws, the iterator closes, and nothing replays. The caveat is the same one I gave Sal: the note goes through the same queue that just failed, so if the provider is fully down the note itself may not play — the panel's error phase is the backstop. Thanks for the close read.