<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sanket Ugale on Medium]]></title>
        <description><![CDATA[Stories by Sanket Ugale on Medium]]></description>
        <link>https://medium.com/@sanketugale?source=rss-1e9a93d99dec------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*u_QAFY6kDvOMoaAJkeJ5xg.jpeg</url>
            <title>Stories by Sanket Ugale on Medium</title>
            <link>https://medium.com/@sanketugale?source=rss-1e9a93d99dec------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 09:08:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sanketugale/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How I Built a Sub-Second Voice AI Pipeline That Actually Feels Human]]></title>
            <link>https://sanketugale.medium.com/how-i-built-a-sub-second-voice-ai-pipeline-that-actually-feels-human-9d0e50cc813a?source=rss-1e9a93d99dec------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d0e50cc813a</guid>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[voice-ai]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Sanket Ugale]]></dc:creator>
            <pubDate>Fri, 27 Nov 2026 06:09:10 GMT</pubDate>
            <atom:updated>2026-11-27T06:15:01.141Z</atom:updated>
            <content:encoded><![CDATA[<p>Real-time voice interfaces live or die by latency. If an assistant takes three to four seconds to respond after you finish speaking, the interaction breaks down. The rhythm feels unnatural, and both sides end up talking over each other.</p><p>Achieving a conversational response under one second requires rethinking how Speech-to-Text (STT), Large Language Models (LLM), and Text-to-Speech (TTS) interact. A standard sequential approach — recording audio, waiting for transcription, waiting for full text generation, and then synthesizing speech — cannot hit this threshold.</p><p>Here is how a streaming, sentence-pipelined voice architecture works under the hood.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EBdTCWdWcl0FHgy4vxG_5Q.png" /></figure><h3>Architecture Overview</h3><p>The system operates across three tiers: a client-side audio edge, a streaming transport layer, and a pipelined inference backend.</p><p>Instead of passing complete audio files and complete text responses between isolated services, data moves as continuous chunks. The client detects speech boundaries locally, the backend streams text tokens from the LLM, and the TTS engine synthesizes audio sentence-by-sentence.</p><h3>1. Client-Side Edge: Voice Activity Detection &amp; Audio Buffering</h3><p>The conversation starts in the browser or native client. Pushing raw audio streams continuously to a cloud speech recognizer introduces unnecessary compute load and network chatter. Handling detection locally on the audio thread solves this.</p><h3>Root-Mean-Square (RMS) Energy Tracking</h3><p>Using the Web Audio API, an audio context connects to the user microphone with hardware-level acoustic echo cancellation and noise suppression enabled. An audio analyser node samples the incoming audio frames every 20 milliseconds, calculating the Root-Mean-Square (RMS) energy level.</p><h3>The Rolling Pre-Roll Buffer</h3><p>A common failure in naive voice activity detection (VAD) is syllable clipping. When a speaker starts a word with a soft consonant like “th”, “p”, or “s”, the volume often sits below the activation threshold for the first 100 to 200 milliseconds.</p><p>To prevent clipping the start of words, the client maintains a continuous 500-millisecond rolling FIFO ring buffer in memory. When speech energy crosses the activation threshold, the system prepends this pre-roll buffer to the recorded audio. The transcription engine receives the complete opening sound.</p><h3>Silence Debouncing and Breathing Pauses</h3><p>People do not speak like teletype machines; they pause to breathe or gather their thoughts. If a silence detector cuts off the recording after 300 milliseconds of silence, a normal pause gets chopped into multiple disconnected requests.</p><p>The client implements an 850 to 1000-millisecond hangover timer. The recording state only closes if the audio level remains below the silence floor for the entire duration of this window.</p><h3>2. Ingestion and Speech Recognition (STT)</h3><p>Once the silence timer confirms the speaker has completed their turn, the client exports the captured PCM samples as a single 16kHz or 24kHz WAV payload and sends it to the backend over HTTP.</p><p>On the server, a streaming speech-to-text engine processes the audio using GPU acceleration. The transcription takes between 200 and 350 milliseconds depending on utterance length.</p><h3>Fragment Coalescing</h3><p>If a speaker pauses for slightly longer than the debounce window and continues their thought, the system does not process the fragments as isolated prompts. A coalescing layer checks the timestamp of the incoming utterance against the previous turn. If the gap is short, the new text appends to the prior utterance before hitting the model, preserving context and preventing redundant replies.</p><h3>3. The Core Optimization: Sentence-Boundary Pipelining</h3><p>In standard text chat, a language model generates tokens until it reaches an end-of-sequence token. Generating a three-sentence response from a local or cloud model usually takes between two and four seconds.</p><p>If the TTS engine waits for the entire generation to finish before creating speech, total turnaround time balloons to five or six seconds.</p><p>The solution is sentence-level pipelining:</p><ol><li><strong>Token Ingestion:</strong> The backend reads delta tokens from the LLM via Server-Sent Events as they are sampled.</li><li><strong>Boundary Detection:</strong> An accumulator buffer inspects the incoming text against sentence delimiters: periods, question marks, exclamation marks, and semicolons.</li><li><strong>Immediate Synthesis Dispatch:</strong> The moment the first complete sentence is formed — often within 8 to 12 words — it is immediately dispatched to the TTS engine.</li><li><strong>Parallel Processing:</strong> While the TTS engine synthesizes Sentence #1 into a playable audio chunk, the LLM continues generating Sentences #2 and #3 concurrently.</li></ol><p>By the time Sentence #1 has finished playing on the client speaker, Sentence #2 has already been synthesized and buffered in the client playback queue. Apparent latency drops to the time required to produce just the first sentence.</p><h3>4. Neural Text-to-Speech (TTS) &amp; Streaming Delivery</h3><p>The TTS engine operates on sentence-level text chunks, converting text into 24kHz linear PCM or WAV data. Because sentences are short, synthesis finishes within 150 to 250 milliseconds per chunk.</p><p>The generated audio chunk is Base64 encoded and pushed to the client over an established HTTP Server-Sent Events (SSE) stream.</p><p>On the client side:</p><ul><li>The browser decodes each incoming base64 audio payload into an audio buffer.</li><li>A sequential playback queue schedules each chunk to play back-to-back using the Web Audio API clock, ensuring seamless transitions without audible clicks or gaps between sentences.</li></ul><h3>5. Full-Duplex Interruption (Barge-In)</h3><p>A conversation feels unnatural if the user cannot interrupt the assistant while it is speaking. Supporting barge-in requires synchronizing the client audio pipeline with backend request lifecycles.</p><ol><li><strong>Acoustic Echo Cancellation:</strong> Hardware-backed echo cancellation prevents the assistant’s own voice coming through the device speakers from re-triggering the microphone input.</li><li><strong>Interrupt Trigger:</strong> If the client VAD detects sustained human speech while the playback queue is active, an interruption event fires immediately.</li><li><strong>Queue Purge:</strong> The client audio context immediately stops the currently playing audio node and clears all queued sentence buffers.</li><li><strong>Backend Abort:</strong> The client aborts the active HTTP fetch request using an AbortController. The server catches the client disconnect, instantly cancels LLM token generation, and halts further TTS synthesis tasks to save compute.</li><li><strong>State Transition:</strong> The client switches from speaking state to listening state without reloading or resetting session context.</li></ol><h3>Measured Latency Profile</h3><p>Here is the stage-by-stage latency measured across a locally hosted deployment running on modern Apple Silicon hardware:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P9uJSMni1JZDQgEQ89Xfow.png" /></figure><h3>Summary</h3><p>Low-latency voice interaction does not require speculative black boxes. It relies on tight mechanical pipelining:</p><ul><li>Moving voice detection and buffer prepending to the client edge.</li><li>Splitting LLM output by sentence boundaries instead of waiting for full generation.</li><li>Overlapping the synthesis of sentence N<em>N</em> with the playback of sentence N−1<em>N</em>−1 and the generation of sentence N+1<em>N</em>+1.</li><li>Maintaining a hard cancellation loop for full-duplex interruptions.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9d0e50cc813a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>