<?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 Ayush Dangol on Medium]]></title>
        <description><![CDATA[Stories by Ayush Dangol on Medium]]></description>
        <link>https://medium.com/@ayushazhar?source=rss-570fea875c8a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*G59H2PlJVyvI8UwSh7aKIg.jpeg</url>
            <title>Stories by Ayush Dangol on Medium</title>
            <link>https://medium.com/@ayushazhar?source=rss-570fea875c8a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 15:25:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ayushazhar/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 Turn Detection Helps Voice Agents Sound More Natural]]></title>
            <link>https://medium.com/@ayushazhar/how-turn-detection-helps-voice-agents-sound-more-natural-f5ca6c21b801?source=rss-570fea875c8a------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5ca6c21b801</guid>
            <dc:creator><![CDATA[Ayush Dangol]]></dc:creator>
            <pubDate>Sun, 07 Dec 2025 17:19:26 GMT</pubDate>
            <atom:updated>2025-12-07T17:19:26.089Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey amazing people! <br>Have you ever talked to an AI voice agent and felt like it just couldn’t wait for its turn?<br>Maybe it kept cutting you off mid-sentence like an overly excited friend or worse you had to sit there waiting while it rambled on, desperately wanting to jump in but having to let it finish its speech like it was giving a TED talk.</p><p>It totally ruins the flow, right? Suddenly, you’re painfully aware that you’re talking to a machine, not a human who gets conversational cues.</p><p>That’s exactly why Turn Detection comes in. It helps the voice agent actually understand when you’re done talking and when it’s supposed to take its turn so things feel smooth, natural, and, well… human.</p><p>Ever noticed how, in real conversations, we naturally pause, breathe, jump in, interrupt, or politely “hmm” our way into a reply? Humans do this instinctively, but voice agents don’t they have to detect it. That’s where turn detection comes in, analyzing speech patterns, tone, and silence to figure out the right moment to respond.</p><p>In this blog, we’ll explore turn detection, how it works and the best approaches to implement it.</p><h3>Voice Activity Detection (VAD)</h3><p>When building AI voice agents, Voice Activity Detection (VAD) is often the go-to tool for figuring out if a user is speaking or not. Think of it as a tiny bouncer that decides, “Is there voice here, or just silence?”</p><p>But is VAD alone enough to run a natural, real-time voice conversation?<br>Short answer: absolutely not.</p><p>Here’s how it typically works: a user talks, pauses and after a certain amount of silence, VAD assumes the person is done. That’s great in theory, but humans don’t speak in neat, predictable chunks. We pause to think, to breathe, to emphasize or simply because our brains forgot the next word.</p><p>So relying only on silence to decide “turn end” can backfire. A thoughtful pause doesn’t mean the user is done talking sometimes, it just means life is buffering.</p><h3>Enter Turn Detection</h3><p>While VAD can detect speech vs silence, it doesn’t understand what’s actually being said. Humans judge turns based on grammar, tone, pace and meaning not just gaps in audio.</p><p>That’s where Turn Detection steps in. Models like Smart Turn analyze speech patterns to decide whether the user has truly finished speaking or if they’re still in mid-thought.</p><p>For example, if someone trails off with:</p><blockquote>“I want to order a pizza but…”</blockquote><p>and pauses, VAD sees silence. But Turn Detection recognizes the sentence is incomplete because nobody ends a thought with <em>“but”</em> unless they’re being dramatic.</p><p>It labels that moment as not done and waits for the rest of the thought.</p><h3>Is Turn Detection Alone Enough?</h3><p>So now we have context-aware analysis. Problem solved, right?<br>Well… not quite.</p><p>Even with linguistic understanding, real conversations are messy. People stop mid-sentence, restart, stutter or just go silent to think.</p><p>Example:</p><blockquote>“I think we should go to the — ”</blockquote><p>…long pause…</p><p>A Turn Detection model might mistake that pause for a full stop and let the agent jump in prematurely, creating a painfully awkward interruption.</p><p>And that’s without factoring in background noise, fans, typing, and coughs, all of which can confuse models and trigger unwanted responses.</p><p>So, Turn Detection alone is better than VAD alone but still not perfect.</p><h3>So What Actually Works?</h3><h3>A Smart Combo: VAD + Turn Detection</h3><p>The right approach is to let each model do what it’s good at and combine their strengths.</p><p>Here’s a simplified view of how the system plays out:</p><ol><li>User starts speaking → audio gets buffered</li><li>VAD monitors silence</li><li>When silence hits a threshold, VAD flags “speech ended”</li><li>The buffered audio is passed to the Turn Detection model</li><li>Turn Detection decides:</li></ol><ul><li><strong>TURN END</strong> → forward to response pipeline</li><li><strong>NOT TURN END</strong> → keep buffering, don’t respond yet</li></ul><p>So in the earlier example:</p><blockquote>“I want to order a pizza but…”</blockquote><p>VAD sees silence, but Turn Detection says,</p><blockquote><em>“This person is definitely not done; hold the response.”</em></blockquote><p>When the user continues:</p><blockquote>“…with extra cheese,”</blockquote><p>Turn Detection marks the turn complete and the agent replies.</p><p>The final result is no awkward interruptions, no robotic rush to respond.</p><h3>Handling Interruptions Like a Human</h3><p>Real conversations aren’t one-way monologues. People interrupt each other and AI voice agents need to handle that too.</p><p>Here’s how the combo helps:</p><ul><li>VAD listens continuously even while the agent speaks</li><li>When it detects the user talking, the agent pauses</li><li>Turn Detection analyzes the speech to decide when the user is done</li><li>Then, and only then, the agent replies</li></ul><p>Example:</p><p>Agent:</p><blockquote>“Your order will be delivered at 6 PM — ”</blockquote><p>User jumps in:</p><blockquote>“Actually, can it be at 7 instead?”</blockquote><p>VAD says: <em>“User talking now, stop!”<br></em>Turn Detection waits until the user finishes, then cues a response. It is smooth, natural and more.. human-like.</p><h3>Conclusion</h3><p>Natural conversation isn’t just about recognizing speech it’s about recognizing when speech matters.</p><p>By combining VAD (to detect speech) with Turn Detection (to understand context), voice agents can interpret pauses, incomplete thoughts, tone and timing more intelligently.</p><p>The result?<br>Agents that don’t interrupt, don’t respond too late and don’t panic when humans pause to think making conversations feel more fluid, responsive and genuinely human.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5ca6c21b801" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Speech-to-Speech (STS) Pipeline: How Modern Voice Agents Work]]></title>
            <link>https://medium.com/@ayushazhar/speech-to-speech-sts-pipeline-how-modern-voice-agents-work-7a990c982b71?source=rss-570fea875c8a------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a990c982b71</guid>
            <dc:creator><![CDATA[Ayush Dangol]]></dc:creator>
            <pubDate>Mon, 17 Nov 2025 11:30:12 GMT</pubDate>
            <atom:updated>2025-11-17T11:35:05.367Z</atom:updated>
            <content:encoded><![CDATA[<p>Voice is becoming the new interface of computing. From smart assistants and customer-support bots to real-time translation tools, modern applications increasingly rely on <strong>Speech-to-Speech (STS) pipelines</strong> to deliver natural, human-like interactions. Unlike traditional speech systems that only convert audio to text or text to audio, STS pipelines handle the entire conversational loop i.e listening, understanding, reasoning, and responding all in real time.</p><p>An STS (Speech-to-Speech) pipeline powers what we commonly call a <strong>voice agent</strong>: a system capable of taking spoken input, interpreting it with an AI model, generating an appropriate response, and speaking that response back to the user. It blends multiple technologies i.e <strong>speech-to-text (STT)</strong>, <strong>language modeling (LLM)</strong>, and <strong>text-to-speech (TTS) </strong>into a seamless, low-latency conversational flow.</p><p>In this blog, we’ll break down <strong>how an STS pipeline works end-to-end</strong>, explore the components behind modern voice agents, and look at the engineering challenges involved in building real-time speech systems.</p><h4><strong>Core Component</strong></h4><h4><strong>1. Speech to Text (STT)</strong></h4><p>Speech to Text (STT), also called Automatic Speech Recognition (ASR), is the process of converting spoken audio into written text. Modern STT systems use deep learning especially large neural network trained on thousands of hours of audio to recognize words, accents, emotions, and background noise patterns. In a voice agent or Speech to Speech pipeline, STT is the first step responsible to understand the user’s spoken input so the LLM can process it.</p><p>There are several paid, cloud-based STT models that support real-time and batch transcription, such as Google Speech-to-Text, as well as open-weight STT models like Whisper, Vosk, and Nemo ASR, which can be run on a CPU.</p><p>Even with modern models, STT systems face real-world challenges:</p><ol><li>Background noise (such as crowded environments, traffic, or overlapping speakers) can reduce transcription accuracy</li><li>Models also struggle with regional accents, code-switching (English-Nepali mixes), and uncommon pronunciations</li><li>Real-time latency can be an issue, heavier models like Whisper Large, can be slow without a GPU. Therefore, there is often a trade-off between accuracy and latency</li><li>Technical, medical, or local terms are often mis-transcribed unless models are customized</li><li>Additionally, STT outputs may contain run-on sentences, incorrect punctuation, and inconsistent capitalization</li></ol><p>These issues can be addressed with a combination of strategies:</p><ol><li>noise reduction techniques and directional microphones improve recognition in noisy environments</li><li>fine-tuning models with regional accents and multilingual datasets helps handle diverse speech patterns</li><li>Real-time latency can be reduced using lightweight or optimized models, GPU acceleration and streaming decoding</li><li>low-quality audio can be enhanced through resampling, normalization, and preprocessing filters</li><li>Domain-specific vocabulary is managed with custom lexicons and contextual biasing</li><li>punctuation and formatting errors can be corrected with post-processing pipelines or transformer-based models that predict punctuation.</li><li>Multi-speaker or overlapping speech can be handled with speaker diarization models</li></ol><p>Prompting can also help address transcription errors. Modern LLMs are sophisticated enough to work around such errors. During inference, the LLM has access to the full conversation context, allowing it to reason effectively. You can inform the LLM that the input is a transcription of user speech, so it can interpret and respond accordingly.</p><blockquote>You are a helpful, concise, and reliable voice assistant. Your primary goal is<br>to understand the user’s spoken requests, even if the speech-to-text<br>transcription contains errors. Your responses will be converted to speech<br>using a text-to-speech system. Therefore, your output must be plain,<br>unformatted text.<br>When you receive a transcribed user request:<br>1. Silently correct for likely transcription errors. Focus on the intended<br>meaning, not the literal text. If a word sounds like another word in the given<br>context, infer and correct. For example, if the transcription says “buy milk<br>two tomorrow” interpret this as “buy milk tomorrow”.<br>2. Provide short, direct answers unless the user explicitly asks for a more<br>detailed response. For example, if the user says “what time is it?” you should<br>respond with “It is 2:38 AM”. If the user asks “Tell me a joke”, you should<br>provide a short joke.<br>3. Always prioritize clarity and accuracy. Respond in plain text, without any<br>formatting, bullet points, or extra conversational filler.<br>4. If you are asked a question that is time dependent, use the current date,<br>which is February 3, 2025, to provide the most up to date information.<br>5. If you do not understand the user request, respond with “I’m sorry, I<br>didn’t understand that.”<br>Your output will be directly converted to speech, so your response should be<br>natural-sounding and appropriate for a spoken conversation.</blockquote><h4>2. Large Language Model (LLM)</h4><p>A Large Language Model (LLM) is an AI model trained on massive amounts of text data to understand, generate, and reason about human language. LLMs leverage deep learning (particularly transformer architectures) to predict the next word in a sequence, generate text, answer questions, translate languages, and summarize content. <br>Examples include GPT (OpenAI), LLaMA (Meta), and Mistral. Essentially, LLMs serve as the ‘brain’ of conversational AI, capable of understanding context and producing human-like responses.</p><p>Large Language Models (LLMs) can be categorized in several ways based on accessibility and purpose. Open-weight or open-source models such as LLaMA, Mistral, and Falcon, can be run locally and fine-tuned for custom applications offering flexibility and privacy. In contrast, proprietary or closed models like GPT-4 and Claude are hosted on cloud platforms and typically accessed via paid APIs, providing ease of use and high performance without requiring local infrastructure.</p><p>LLMs can also be classified by their functional focus:</p><ol><li>instruction-tuned models such as ChatGPT and Alpaca, are optimized to follow human instructions and provide conversational responses</li><li>general-purpose models are trained broadly to handle diverse tasks without specialization</li><li>domain-specific models are fine-tuned on specialized data such as medical, legal, or technical corpora to deliver highly accurate and context-aware responses within a specific field.</li></ol><p>In a voice agent or Speech-to-Speech (STS) pipeline, Large Language Models (LLMs) serve as the cognitive layer bridging speech input and speech output. First, the user’s speech is converted into text using a Speech-to-Text (STT) system. The LLM then processes this text, analyzing the user’s intent, reasoning about context, and generating appropriate responses or actions. Finally, the generated text is converted back into speech using a Text-to-Speech (TTS) system, allowing the voice agent to interact naturally. This pipeline enables voice agents to conduct intelligent conversations, provide summaries, answer questions, and perform tasks in real time, delivering a seamless, human-like interaction experience.</p><p>Using Large Language Models (LLMs) in voice agents comes with several key challenges.</p><ol><li>One major issue is latency, as inference with large models can be slow, affecting real-time responsiveness.</li><li>Context management is another challenge, since maintaining conversation history across long dialogues can be difficult.</li><li>LLMs are also prone to hallucinations, sometimes generating incorrect or misleading information.</li><li>These models are resource-intensive, requiring significant GPU, CPU, and memory capacity for effective performance.</li><li>Bias and safety concerns arise because LLMs can produce offensive or unsafe outputs if not properly moderated. Privacy and compliance are also important considerations, especially when user data is processed through cloud-hosted models.</li></ol><p>Several strategies can help address the challenges of using LLMs in voice agents:</p><ol><li>To reduce latency, developers can use smaller or optimized models, apply quantization, or leverage model distillation for faster inference.</li><li>Context management can be improved by implementing memory mechanisms or processing conversation history in chunks.</li><li>To mitigate hallucinations, LLMs can be combined with retrieval-augmented generation (RAG) that references verified databases.</li><li>Resource efficiency can be achieved by deploying models on GPU clusters, using model sharding, or running smaller models on-device.</li><li>Addressing bias and safety involves prompt engineering, moderation filters, and fine-tuning with safe datasets. Finally, ensuring privacy and compliance may require running open-weight models locally or encrypting communications when using cloud-hosted LLMs.</li></ol><h4>3. Text to Speech (TTS)</h4><p>Text-to-Speech (TTS) is a technology that converts written text into spoken audio. Modern TTS systems leverage deep learning to produce natural, human-like speech, often incorporating nuances such as intonation, emphasis, and emotion. In a voice agent or Speech-to-Speech (STS) pipeline, TTS serves as the final step, responsible for delivering the model’s response in a way that the user can hear and understand.</p><p>A typical Text-to-Speech (TTS) pipeline operates in two main stages:</p><ol><li>First, during text analysis and linguistic processing, the input text is analyzed to determine pronunciation, intonation, sentence structure, and prosody, including rhythm and stress patterns. This stage also involves text normalization such as expanding numbers, dates, and abbreviations and converting text into phonemes for accurate pronunciation.</li><li>Next, in the speech synthesis stage, the processed text is transformed into audio using various techniques. Concatenative TTS strings together pre-recorded speech segments, while parametric TTS generates speech using statistical models.</li></ol><p>Modern neural TTS approaches, such as Tacotron, FastSpeech, or VITS, leverage deep neural networks to produce highly natural, expressive, and human-like speech that captures intonation and emotional nuance.</p><p>There are several popular Text-to-Speech (TTS) engines available, both commercial and open-source:</p><ol><li>Among commercial options, Amazon Polly offers high-quality, multi-lingual voices with real-time streaming; Google Cloud TTS provides WaveNet voices with natural prosody; Microsoft Azure TTS supports custom voice creation and expressive speech synthesis; and IBM Watson TTS delivers multiple languages, styles, and neural voices.</li><li>On the open-source or locally deployable side, Piper TTS is a lightweight solution that produces high-quality speech; Coqui TTS is a neural TTS framework with pre-trained models for multiple languages; Mozilla TTS allows customization of voices and languages; and Festival or eSpeak are older, less natural systems but remain lightweight and widely used in embedded applications.</li></ol><p>When selecting a Text-to-Speech (TTS) system, several key considerations are important:</p><ol><li>Naturalness and expressiveness determine how closely the synthetic voice resembles human speech, while latency and real-time performance are critical for voice agents, as neural TTS models can be resource-intensive.</li><li>Voice customization allows the creation of unique voices for branding or personalization, and language and accent support ensures the system can cater to global audiences.</li><li>Resource requirements, such as GPU or CPU usage, must be evaluated for efficient deployment.</li><li>Licensing and privacy are also important factors, since cloud-based TTS services may involve data transfer, whereas open-source solutions enable on-device synthesis and greater control over data.</li></ol><h4>4. WebRTC</h4><p>WebRTC enables real-time, low-latency, and secure audio streaming across browsers and devices without plugins. It handles microphone capture, audio playback, adaptive streaming, and efficient compression (e.g., Opus codec) out of the box, ensuring smooth communication even over unstable networks. For backend integration in Python-based voice agents, libraries like aiortc and FastRTC allow developers to implement WebRTC servers that connect live audio streams to speech-to-text, text-to-speech, and AI processing pipelines, making WebRTC an ideal solution for modern AI-powered Speech-to-Speech (STS) systems.</p><h4>5. Turn Detection</h4><p>Voice agents use Voice Activity Detection (VAD) and TurnDetection to enable natural and efficient conversations. Modern systems often employ the Seliro model for VAD, which accurately detects when the user is speaking, filtering out silence and background noise to reduce unnecessary processing and improve responsiveness. For turn management, models like SmartTurnV3 handle conversation turn-taking, ensuring the agent responds only after the user finishes speaking, preventing interruptions and enabling smooth, human-like dialogue. Together, Seliro and SmartTurnV3 allow voice agents to process real-time speech efficiently, maintain natural conversational flow, and optimize bandwidth and latency in AI-powered voice interactions.</p><h4>End-to-End Flow</h4><p>A modern voice agent operates as a real-time Speech-to-Speech (STS) system, combining multiple AI components to enable natural, intelligent conversations. The pipeline begins with audio capture from the user, typically through a browser or app using WebRTC (via frameworks like aiortc). WebRTC handles low-latency streaming of audio and supports bi-directional communication, making it ideal for live voice agents.</p><p>Once the audio stream is received, a Voice Activity Detection (VAD) module determines when the user is speaking. Techniques such as Seliro VAD and SmartTurnV3 efficiently detect speech boundaries, ensuring that only meaningful speech segments are processed, reducing unnecessary computation and improving real-time responsiveness.</p><p>After Turn detection, the audio is passed to a Speech-to-Text (STT) engine, which converts spoken words into text. Popular choices include OpenAI Whisper, Vosk, or cloud-based services like Google Speech-to-Text. The STT module provides a textual representation of the user’s speech, which becomes the input for the next stage.</p><p>The textual input is then processed by a Large Language Model (LLM), which serves as the cognitive core of the voice agent. The LLM interprets the user’s intent, reasons about context, and generates an appropriate response. Instruction-tuned or domain-specific models can enhance accuracy and contextual understanding, ensuring the voice agent can answer questions, summarize content, or execute tasks intelligently.</p><p>Finally, the LLM’s textual response is converted back into spoken audio using a Text-to-Speech (TTS) engine. Neural TTS models, such as Piper TTS, Coqui TTS, or cloud-based solutions like Amazon Polly, produce natural, expressive speech that is streamed back to the user through WebRTC, completing the interaction loop.</p><p>This end-to-end pipeline from real-time audio capture and turn detection to STT, LLM processing, and TTS playback creates a seamless conversational experience, enabling voice agents to interact naturally, respond intelligently, and operate efficiently in real-time applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*qdfdplijYxc47SQqaMeizg.png" /><figcaption>Speech-to-Speech Pipeline</figcaption></figure><h4>Use Cases</h4><ol><li>Customer Support Automation<br>Modern voice agents can instantly understand customer queries, detect intent and respond naturally, reducing wait times and improving service quality. They can handle tasks like troubleshooting, order tracking, or billing questions without human intervention.</li><li>Healthcare Voice Assistants<br>Doctors and patients can interact hands-free using voice. The system transcribes symptoms, retrieves medical information, schedules appointments, and provides spoken feedback, ideal for clinical environments where typing is inconvenient.</li><li>Smart Home and IoT Control<br>Voice agents allow users to control lights, appliances, security systems, and routines through voice. STS pipelines enable fast, real-time interactions with very low latency, making smart homes feel responsive and natural.</li><li>In-Car Voice Navigation &amp; Infotainment<br>Drivers can ask for directions, control music, or interact with the vehicle’s system safely without touching screens. Real-time speech-to-speech reduces distraction and enhances the driving experience.</li><li>Language Learning &amp; Real-Time Translation<br>Voice agents can convert speech from one language to another instantly, helping with travel, communication, or learning.</li></ol><h4>Conclusion</h4><p>Speech-to-Speech (STS) pipelines are transforming how humans interact with technology by enabling natural, real-time voice conversations. By combining WebRTC for low-latency audio streaming, advanced turn detection for smooth dialogue flow, high-accuracy Speech-to-Text, powerful Large Language Models for reasoning, and expressive Text-to-Speech systems, modern voice agents deliver seamless, human-like interactions across countless applications. Whether powering customer support automation, enhancing healthcare workflows, enabling smart home control, assisting drivers on the road, or providing real-time language translation, STS systems make technology more intuitive and accessible. As these components continue to improve (becoming faster, more accurate, and more efficient) the future of computing will increasingly revolve around voice-first experiences, where speaking to machines feels as effortless as speaking to people.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a990c982b71" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>