<?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 San D on Medium]]></title>
        <description><![CDATA[Stories by San D on Medium]]></description>
        <link>https://medium.com/@sandipanarnab_33609?source=rss-88035e82f922------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by San D on Medium</title>
            <link>https://medium.com/@sandipanarnab_33609?source=rss-88035e82f922------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 21:32:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sandipanarnab_33609/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[I Built a Fully Local Voice-Controlled AI Agent — Here Is What I Learned]]></title>
            <link>https://medium.com/@sandipanarnab_33609/i-built-a-fully-local-voice-controlled-ai-agent-here-is-what-i-learned-751dfb0ccec2?source=rss-88035e82f922------2</link>
            <guid isPermaLink="false">https://medium.com/p/751dfb0ccec2</guid>
            <category><![CDATA[ai-projects]]></category>
            <category><![CDATA[llm-projects]]></category>
            <category><![CDATA[intent-classification]]></category>
            <category><![CDATA[ai-voice-agent]]></category>
            <category><![CDATA[voice-agent]]></category>
            <dc:creator><![CDATA[San D]]></dc:creator>
            <pubDate>Mon, 13 Apr 2026 11:12:42 GMT</pubDate>
            <atom:updated>2026-04-13T11:12:42.072Z</atom:updated>
            <content:encoded><![CDATA[<p><em>From audio input to intelligent action: a complete pipeline with STT, LLM intent classification, and real-time evaluation metrics</em></p><p>There is something deeply satisfying about speaking a command and watching a computer actually understand it — not just transcribe it, but understand it, decide what to do, and do it. That was the goal of this project.</p><p>I built a fully local, voice-controlled AI agent using Python. You speak into a microphone, or upload an audio file, and the system will transcribe your speech, clean it up, detect what language you are speaking, translate if needed, figure out what you want, and then take the right action — all without sending a single byte to a cloud API. Everything runs on your own machine.</p><p>In this article, I want to walk you through the project from start to finish: the architecture, the pipeline, the libraries involved, how human feedback is collected, and how the agent is evaluated using standard machine learning metrics. I will also explain why I did not use LLM-based evaluation techniques like G-Eval, even though they exist — and that was actually a deliberate choice with a clear reason.</p><h3>The Objective: A Mini Jarvis, But Local</h3><p>The core idea is simple to state but non-trivial to build:</p><blockquote>Take voice input → convert to text → understand the intent → execute the right action → show everything in a clean UI.</blockquote><p>The agent supports four main intents: creating files or folders, generating and saving code, summarizing long text, and general conversational Q&amp;A. Each of these maps to a concrete tool that does something on your filesystem or uses the LLM to produce output.</p><p>What makes this interesting is not any single component — it is how all the components connect into a reliable, measurable pipeline. That pipeline design is the real challenge, and it is also what makes this project genuinely useful for a resume or interview.</p><h4><strong>System Architecture :</strong></h4><p>The high-level data flow looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WAjMXpQPK0a_M6jnLnk_cw.png" /></figure><p>Every stage in this pipeline is timed, so you can see where bottlenecks are. And every stage produces visible output in the Streamlit UI, which makes debugging and demonstrating the system much easier.</p><h3>The Pipeline, Step by Step :</h3><h3>Step 1 — Audio Input</h3><p>The user either records directly from the microphone using the browser-based audio recorder in Streamlit, or uploads a .wav or .mp3 file. The file is temporarily stored and passed to the transcription module.</p><h3>Step 2 — Speech-to-Text with faster-whisper</h3><p>The transcription is handled by faster-whisper, which is a reimplementation of OpenAI&#39;s Whisper model using the CTranslate2 backend. It runs significantly faster than the original Whisper and supports GPU acceleration via CUDA. If no GPU is available, it falls back to CPU automatically.</p><p>The base model is the default, but users can switch to small, medium, or others depending on their hardware. Larger models give more accurate transcriptions but are slower.</p><h3>Step 3 — Language Detection (Dual Stage)</h3><p>This is one of the more interesting parts of the pipeline. Language detection happens in two stages for higher reliability across 20+ languages:</p><ul><li><strong>Audio-level detection</strong>: Whisper itself provides a language probability score during transcription.</li><li><strong>Text-level detection</strong>: After transcription, lingua-language-detector confirms the language based on the actual text content.</li></ul><p>The dual approach handles edge cases where the audio quality is poor or the accent is heavy — one method may fail while the other succeeds.</p><h3>Step 4 — Translation</h3><p>If the detected language is not English, the transcript is passed to Ollama with a prompt to translate it into English before further processing. This keeps the intent classification model clean and English-only, which improves its reliability.</p><h3>Step 5 — Text Normalization and Grammar Correction</h3><p>Real speech is messy. People say “um” and “uh,” trail off mid-sentence, or mumble. This step sends the raw transcript to an LLM (via Ollama) with a prompt to clean it up: remove filler words, fix grammar, and normalize the sentence structure. The output is a clean, well-formed English sentence that the intent classifier can work with reliably.</p><p>You can see this in action in the pipeline results — for example, “Hello, what is the price of flight ticket today?” becomes “How much does the plane ticket cost today?” after grammar correction.</p><h3>Step 6 — Intent Classification :</h3><p>The cleaned text is sent to the LLM again, this time with a structured prompt that asks it to classify the intent into one of four categories: create_file, write_code, summarize, or general_chat. The model also returns a confidence level (high, medium, or low) and extracts any named entities from the text.</p><p>The four supported intents with example commands are:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H5av-aPGKOkSMOCYpldX9g.png" /></figure><h3>Step 7 — Routing</h3><p>The dispatcher maps the detected intent to the correct tool function. This is a straightforward routing step — think of it like a switch-case — but it is kept as a separate module so new intents and tools can be added without touching the rest of the pipeline.</p><h3>Step 8 — Tool Execution</h3><p>Each tool does something concrete:</p><ul><li><strong>file_ops.py</strong> — Creates files or folders using os.makedirs and open. All operations are sandboxed to the output/ directory for safety.</li><li><strong>code_gen.py</strong> — Calls Ollama to generate code based on the user’s description, then saves the result to a .py file in output/.</li><li><strong>summarizer.py</strong> — Sends the user’s text to the LLM with a summarization prompt.</li><li><strong>chat.py</strong> — Handles general conversational queries by sending them directly to the LLM.</li></ul><p>Critical file operations require user confirmation before execution, which is the “human-in-the-loop” safety feature.</p><h3>Project Structure</h3><p>The project is organized as a clean, modular Python package:</p><p>voice_ai_agent/<br>├── app.py # Main Streamlit application &amp; UI<br>├── stt/ # Speech processing<br>│ ├── transcriber.py<br>│ ├── language.py<br>│ ├── translator.py<br>│ └── grammar.py<br>├── intent/<br>│ └── classifier.py<br>├── router/<br>│ └── dispatcher.py<br>├── tools/<br>│ ├── file_ops.py<br>│ ├── code_gen.py<br>│ ├── summarizer.py<br>│ └── chat.py<br>├── utils/<br>│ ├── config.py<br>│ ├── feedback.py<br>│ └── metrics.py<br>├── feedback/ # JSON feedback logs<br>├── output/ # Sandboxed generated files<br>└── temp/ # Temporary audio storage</p><p>Every module has a single responsibility. This made it much easier to debug individual stages and swap out components.</p><h3>Libraries and Technologies Used :</h3><p>Here is a summary of the key libraries powering the system:</p><ul><li><strong>faster-whisper</strong> — Speech-to-text transcription with CTranslate2 backend</li><li><strong>lingua-language-detector</strong> — High-accuracy text-level language identification</li><li><strong>Ollama</strong> — Local LLM serving (using llama3.2 by default)</li><li><strong>Streamlit</strong> — Frontend UI</li><li><strong>scikit-learn</strong> — For computing precision, recall, and F1 score in the metrics module</li><li><strong>sounddevice / soundfile</strong> — Audio capture and processing</li></ul><p>The entire stack runs locally. The only dependency on external infrastructure is Ollama, which itself runs as a local server on your machine.</p><h3>The Streamlit UI</h3><p>The frontend is built with Streamlit and has three main sections.</p><p>The top area shows a gradient banner with the app title and two panels: one for recording from the microphone and one for uploading an audio file. Once audio is captured, a prominent red “Process Audio” button triggers the full pipeline.</p><p>Below that is the <strong>Pipeline Results</strong> section, which shows every stage of the pipeline with its timing. You see the raw transcription, the detected language, the grammar-corrected version, the classified intent with confidence level, any extracted entities, and finally the action that was taken. Each card has a small timer badge so you can see exactly how long each step took. In a typical run, STT takes about 0.6 seconds, grammar correction takes 2–3 seconds, and intent classification takes around 2 seconds.</p><p>The sidebar contains configuration controls (Whisper model size, Ollama model name), a session history showing all past requests with their detected intents, and a live evaluation metrics dashboard.</p><h3>The Streamlit UI</h3><p>The frontend is built with Streamlit and has three main sections.</p><p>The top area shows a gradient banner with the app title and two panels: one for recording from the microphone and one for uploading an audio file. Once audio is captured, a prominent red “Process Audio” button triggers the full pipeline.</p><p>Below that is the <strong>Pipeline Results</strong> section, which shows every stage of the pipeline with its timing. You see the raw transcription, the detected language, the grammar-corrected version, the classified intent with confidence level, any extracted entities, and finally the action that was taken. Each card has a small timer badge so you can see exactly how long each step took. In a typical run, STT takes about 0.6 seconds, grammar correction takes 2–3 seconds, and intent classification takes around 2 seconds.</p><p>The sidebar contains configuration controls (Whisper model size, Ollama model name), a session history showing all past requests with their detected intents, and a live evaluation metrics dashboard.</p><h3>Human Feedback Loop</h3><p>After each response, the UI presents a feedback form with two questions:</p><ol><li>Was the intent detected correctly? If not, what should it have been?</li><li>Was the action executed correctly?</li></ol><p>There is also an optional comments field. When the user submits feedback, it gets logged to a JSON file in the feedback/ directory with the input text, predicted intent, correct intent, confidence level, language, and action success flag.</p><p>This feedback data is then used by the metrics module to compute evaluation scores. It is a lightweight but surprisingly effective way to build a labeled evaluation dataset through normal usage.</p><p>The session history in the sidebar shows the progression of interactions, color-coded by intent. This lets you quickly see patterns in what the agent is being asked to do and how it is performing.</p><h3>Evaluation Metrics</h3><p>The metrics.py module reads the accumulated feedback log and produces a comprehensive evaluation report. This can be triggered from the command line or viewed live in the sidebar.</p><h3>Intent Classification Metrics</h3><p>Standard multi-class classification metrics are computed per intent:</p><ul><li><strong>Accuracy</strong> — Overall correct predictions out of total</li><li><strong>Precision per class</strong> — Of all times we predicted this intent, how often were we right?</li><li><strong>Recall per class</strong> — Of all times this was the true intent, how often did we catch it?</li><li><strong>F1 Score</strong> — Harmonic mean of precision and recall</li></ul><p>In a sample run with 15 feedback entries:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*m_a8QHM37dPNtEZSEjkVtw.png" /></figure><p>Overall Intent Accuracy: <strong>80.0%</strong></p><p>summarize scores zero because it had no test cases in this particular run — which the problem areas section flags automatically.</p><h3>Action Execution Metrics</h3><p>Separately, the module tracks whether the tool executed the task correctly:</p><p>Overall Action Accuracy: <strong>86.7%</strong> (13/15 correct)</p><p>general_chat had 2 failures out of 10 attempts (80% success rate). write_code and create_file had 100% action success rates.</p><h3>Language-Wise Performance</h3><p>The metrics also break down performance by detected language:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*Ot66DCJZQbwTtS-dxnwMFQ.png" /></figure><h3>Problem Areas Detection</h3><p>The sidebar automatically highlights struggling intents (those with failure rates above a threshold) and struggling languages. This surfaces issues without requiring you to manually inspect the confusion matrix.</p><p>The full confusion matrix is also printed in the terminal report, showing exactly which intents are being confused with which.</p><h3>Why G-Eval Was Not Used</h3><p>This is a question worth addressing directly, because G-Eval and RAGAS are popular evaluation techniques in the LLM world right now and it might seem like an obvious choice for a project like this.</p><p>G-Eval is not a library — it is a method. The idea is to use one LLM to evaluate the output of another LLM by scoring it on dimensions like correctness, clarity, and relevance. RAGAS is a library that implements similar ideas, primarily designed for evaluating RAG (Retrieval-Augmented Generation) systems.</p><p>The key distinction is this: these techniques are designed for <strong>open-ended generative outputs where there is no ground truth</strong>. When a system generates a code snippet or a summary and you want to know if it is <em>good</em>, traditional metrics like accuracy and F1 cannot help you — there is no labeled answer to compare against. That is where G-Eval shines.</p><p>But for this agent, the most critical evaluation question is different. The question is: <strong>did the system route the voice command to the correct action?</strong> That is a classification problem. We know what the correct intent was (the user tells us via feedback), and we can compare it directly to what the model predicted. This is exactly the scenario where precision, recall, and F1 score are the right tools.</p><p>In other words:</p><blockquote><em>Traditional metrics measure </em><strong><em>correctness</em></strong><em>. LLM-based evaluation measures </em><strong><em>quality</em></strong><em>.</em></blockquote><p>For intent classification and task success rate, correctness is the right thing to measure. For evaluating whether generated code is elegant or whether a summary is truly insightful, G-Eval would be more appropriate. A future improvement to this project would be to add a G-Eval module specifically for scoring the write_code and summarize outputs — but for the core evaluation of pipeline correctness, classical metrics are the better and more honest choice.</p><h3>Safety and Performance Considerations</h3><p>A few design decisions worth noting:</p><p><strong>Sandboxed file operations.</strong> All file creation is restricted to the output/ directory. The tools never touch any path outside this sandbox, which prevents the agent from accidentally modifying system files.</p><p><strong>GPU fallback.</strong> Whisper automatically detects whether CUDA is available and falls back to CPU if not. This makes the project portable across different hardware.</p><p><strong>Per-step timing.</strong> Every stage of the pipeline is timed using Python’s time module. The results are displayed in the UI with millisecond precision. This makes it easy to identify bottlenecks — in practice, the grammar correction and intent classification steps (both LLM calls) dominate the latency.</p><p><strong>Human-in-the-loop for critical operations.</strong> Before any file is created or deleted, the UI requires explicit confirmation. This is not just good UX — it is a safety mechanism for agentic systems that take real-world actions.</p><h3>Final Thoughts</h3><p>What I found most valuable about building this project is that it forces you to think about evaluation from the very beginning. It is easy to build a demo that works on your own examples. It is harder to build a system that you can honestly measure, identify weaknesses in, and improve over time.</p><p>The feedback loop — small and simple as it is — changes how you think about the system. Instead of asking “does this work?”, you start asking “under what conditions does this fail, and how often?”</p><p>The metrics dashboard showed me clearly that summarize was undertested, that general_chat had the most action failures, and that the single French query handled correctly is not enough to draw any conclusions about multilingual performance. Those are honest, useful insights that came directly from real usage data.</p><p>If you want to go further, adding G-Eval for output quality scoring, expanding the intent set, or integrating Mem0 for persistent memory across sessions would be natural next steps. But even in its current form, this project demonstrates something valuable: a production-minded approach to building and evaluating AI agents, not just a working demo.</p><p><em>The full source code, README, and requirements are available in the project repository. The stack: Python 3.10+, faster-whisper, lingua-language-detector, Ollama (llama3.2), Streamlit, scikit-learn.</em></p><p><a href="https://github.com/sandipanarnab/voice_ai_agent"><em>https://github.com/sandipanarnab/voice_ai_agent</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=751dfb0ccec2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>