Skip to content
Bhaumik-99Public

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽ™๏ธ VoxRoute โ€” Local Real-Time Travel Voice AI

A fully local, runnable MVP of a real-time travel-support voice AI agent. VoxRoute demonstrates the core engineering challenges of a production voice support system โ€” all running on your laptop without paid APIs or cloud inference.

โš ๏ธ DEMO SYSTEM โ€” All travel information is sample data for demonstration purposes.
   Not official government or agency information.

๐Ÿ—๏ธ System Architecture

flowchart TB
    subgraph Frontend["๐Ÿ–ฅ๏ธ Streamlit Frontend"]
        UI_Mic["๐ŸŽค Audio Input / Mic Recorder"]
        UI_Transcript["๐Ÿ’ฌ Live Transcript View"]
        UI_State["๐Ÿง  State & Metrics Dashboard"]
        UI_Player["๐Ÿ”Š Audio Playback"]
    end

    subgraph AgentOrchestrator["โšก Agent Orchestrator (Async)"]
        direction TB
        VAD["๐Ÿ›ก๏ธ Silero VAD<br/>(Voice Activity Detection)"]
        STT["๐ŸŽ™๏ธ faster-whisper<br/>(Local STT Engine)"]
        Intent["๐ŸŽฏ Intent Detector<br/>(Ollama / Regex Fallback)"]
        Memory["๐Ÿง  Conversation Memory<br/>(Entity Resolution & History)"]
        StateMachine["๐Ÿ”„ Agent State Machine<br/>(Transitions & Error Recovery)"]
        Retriever["๐Ÿ“š RAG Retriever<br/>(Query Optimizer)"]
        ToolRouter["โš™๏ธ Tool Execution Router<br/>(Mock Visa DB & API)"]
        LLM["๐Ÿค– Ollama Engine<br/>(qwen2.5:3b)"]
        Guard["๐Ÿ›ก๏ธ Response Guard<br/>(Evidence & Grounding Check)"]
        TTS["๐Ÿ—ฃ๏ธ Piper / pyttsx3<br/>(Local TTS Synthesis)"]
        Interrupt["โน๏ธ Interruption Handler<br/>(Half-Duplex Playback Control)"]
    end

    subgraph Knowledge["๐Ÿ“‚ Local Knowledge & Data"]
        Chroma[("๐Ÿ—„๏ธ ChromaDB Vector Store<br/>(all-MiniLM-L6-v2)")]
        DocFiles["๐Ÿ“„ Demo Travel FAQs<br/>& Visa Policy Docs"]
    end

    subgraph Persistence["๐Ÿ’พ Persistence Layer"]
        SQLite[("๐Ÿ—ƒ๏ธ SQLite Database<br/>(Conversations, Metrics, Failures)")]
    end

    UI_Mic -->|WAV Audio Bytes| VAD
    VAD --> STT
    STT -->|Transcript| Intent
    Intent <--> Memory
    Intent --> StateMachine
    Intent --> Retriever
    Retriever <--> Chroma
    DocFiles -->|Ingestion| Chroma
    Intent --> ToolRouter
    Retriever -->|Grounded Context| LLM
    ToolRouter -->|Tool Output JSON| LLM
    Memory -->|Context Window| LLM
    LLM -->|Draft Response| Guard
    Guard -->|Validated Text| TTS
    TTS -->|WAV Buffer| UI_Player
    UI_Player -.->|Stop / Interrupt| Interrupt
    Interrupt -.->|Cancel Playback| TTS

    AgentOrchestrator -->|Log Turns & Performance| SQLite
    SQLite -->|Aggregate Stats & Metrics| UI_State
    AgentOrchestrator -->|Live Updates| UI_Transcript
Loading

๐Ÿ”„ End-to-End Voice Pipeline

flowchart LR
    Mic(["๐ŸŽ™๏ธ Microphone"]) --> VAD["Silero VAD\nFilter Silence"]
    VAD --> STT["faster-whisper\nSpeech to Text"]
    STT --> Intent{"Intent & Entities\n(Ollama LLM)"}
    
    Intent -->|Query Context| RAG["ChromaDB\nKnowledge Retrieval"]
    Intent -->|Requires Tool| Tools["Local Travel Tools\n(Status, Docs, Time)"]
    
    RAG --> Gen["Ollama LLM\nResponse Generation"]
    Tools --> Gen
    
    Gen --> Guard{"Response Guard\nGrounded & Safe?"}
    Guard -->|Pass / Adjusted| TTS["Piper TTS\nSpeech Synthesis"]
    Guard -->|Low Confidence / Risk| Escalation["Escalation Router\n(Human Agent Handoff)"]
    
    TTS --> Speaker(["๐Ÿ”Š Audio Speaker"])
    Escalation --> TTS
Loading

๐Ÿ”„ Agent State Machine

stateDiagram-v2
    [*] --> IDLE
    IDLE --> LISTENING : Start Conversation
    LISTENING --> TRANSCRIBING : User Speaks (Audio Input)
    TRANSCRIBING --> UNDERSTANDING : Transcript Available
    TRANSCRIBING --> ERROR_RECOVERY : STT Failed
    
    UNDERSTANDING --> RETRIEVING : Need Knowledge Base
    UNDERSTANDING --> TOOL_CALL : Tool Triggered
    UNDERSTANDING --> GENERATING : Direct Query
    UNDERSTANDING --> ESCALATION : Explicit Human Request
    
    RETRIEVING --> TOOL_CALL : Tool Also Needed
    RETRIEVING --> GENERATING : Context Ready
    
    TOOL_CALL --> GENERATING : Tool Output Ready
    TOOL_CALL --> ESCALATION : Tool Failed
    
    GENERATING --> VALIDATING : Draft Answer Ready
    
    VALIDATING --> SPEAKING : Validation Passed
    VALIDATING --> GENERATING : Unsafe Certainty Adjusted
    VALIDATING --> ESCALATION : Low Evidence / Hallucination
    
    SPEAKING --> LISTENING : Playback Completed / Interrupted
    SPEAKING --> IDLE : End Conversation
    
    ESCALATION --> SPEAKING : Synthesize Handoff Notice
    ERROR_RECOVERY --> LISTENING : Fallback Recovery
Loading

โน๏ธ Interruption Handling Flow

sequenceDiagram
    autonumber
    actor Customer as ๐Ÿง‘ Customer
    participant UI as ๐Ÿ–ฅ๏ธ Streamlit UI
    participant Handler as โน๏ธ Interruption Handler
    participant TTS as ๐Ÿ—ฃ๏ธ TTS / Audio Engine
    participant Agent as โšก Orchestrator

    Agent->>TTS: Synthesize and begin playback
    TTS-->>UI: Streaming audio / playback active
    Note over Customer,TTS: Agent is speaking...
    
    Customer->>UI: Clicks "Stop" or Records new utterance
    UI->>Handler: interrupt(reason="user_button")
    Handler->>TTS: stop_playback() (Set Stop Event)
    TTS-->>UI: Playback terminated immediately
    Handler->>Agent: Transition state: SPEAKING โ†’ LISTENING
    UI->>Agent: Submit new customer utterance
    Agent->>Agent: Process new turn
Loading

๐Ÿ› ๏ธ Technology Stack

Component Technology Purpose
Frontend Streamlit Web UI with audio I/O
STT faster-whisper Local speech-to-text
LLM Ollama (qwen2.5:3b) Local language model
Embeddings sentence-transformers Document embeddings
Vector DB ChromaDB RAG retrieval
TTS Piper TTS / pyttsx3 Local text-to-speech
VAD Silero VAD Voice activity detection
Database SQLite Conversation & metrics logging

๐Ÿ“ฆ Installation

Prerequisites

Step 1: Clone and Setup

git clone <repository>
cd voxroute

# Create virtual environment
python -m venv .venv

# Windows
.venv\Scripts\activate

# macOS/Linux
source .venv/bin/activate

# Install dependencies
pip install -r requirements.txt

Step 2: Install and Start Ollama

  1. Download and install Ollama from https://ollama.ai
  2. Start the Ollama service:
ollama serve
  1. Pull the default model:
ollama pull qwen2.5:3b

Step 3: Configure (Optional)

# Copy the example config
copy .env.example .env    # Windows
# cp .env.example .env    # Linux/macOS

# Edit .env to customize models, thresholds, etc.

Step 4: Piper TTS (Optional but Recommended)

Piper provides better quality local TTS. If it fails to install via pip, the app will fall back to system TTS (pyttsx3).

pip install piper-tts

If pip installation fails on Windows, you can:

  1. Download the Piper binary from Piper releases
  2. Download a voice model from Piper voices
  3. Place the .onnx and .onnx.json files in models/piper/

The app will automatically fall back to pyttsx3 (system TTS) if Piper is not available.

Step 5: Run

python run.py

This single command:

  1. Checks Python version
  2. Verifies Ollama is running
  3. Creates .env if missing
  4. Launches the Streamlit app

The app opens at http://localhost:8501.


๐ŸŽฎ Usage

Voice Mode

  1. Click Start Conversation
  2. Click the microphone widget to record your message
  3. The system processes through the full pipeline:
    • STT โ†’ Intent โ†’ RAG โ†’ Tool โ†’ LLM โ†’ Guard โ†’ TTS
  4. You'll hear the response and see real-time metrics

Text Mode (Demo)

  1. Switch to the Text Mode tab
  2. Use the quick demo buttons or type your own query
  3. The system processes through the pipeline (skipping STT)

Evaluation Dashboard

  • Switch to the Evaluation tab
  • See aggregate metrics, latency breakdowns, and failure patterns

๐Ÿงช Demo Scenarios

Scenario 1 โ€” Normal Query

You: "How long does a France visa normally take?"

Expected: Intent โ†’ VISA_PROCESSING_TIME, RAG retrieval, grounded response about 7-15 working days

Scenario 2 โ€” Tool Calling

You: "Can you check application AT12345?"

Expected: Intent โ†’ VISA_STATUS, Tool โ†’ check_application_status, status from mock database

Scenario 3 โ€” Hallucination Prevention

You: "Will my visa definitely arrive tomorrow?"

Expected: Response Guard catches absolute certainty, modifies response to use hedged language

Scenario 4 โ€” Human Escalation

You: "I want to speak to a human."

Expected: Intent โ†’ HUMAN_REQUEST, handoff_to_human() tool called, escalation message

Scenario 5 โ€” Interruption

During agent playback, click End Conversation or record a new message

Expected: TTS stops, new input is processed


๐Ÿ“ Project Structure

voxroute/
โ”œโ”€โ”€ app.py                      # Streamlit main application
โ”œโ”€โ”€ run.py                      # Single entry point
โ”œโ”€โ”€ config.py                   # Central configuration
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ .env.example
โ”œโ”€โ”€ README.md
โ”‚
โ”œโ”€โ”€ agent/
โ”‚   โ”œโ”€โ”€ orchestrator.py         # Main pipeline coordinator
โ”‚   โ”œโ”€โ”€ intent.py               # LLM-based intent detection
โ”‚   โ”œโ”€โ”€ state.py                # Agent state machine
โ”‚   โ”œโ”€โ”€ memory.py               # Conversation memory
โ”‚   โ””โ”€โ”€ prompts.py              # All LLM prompts
โ”‚
โ”œโ”€โ”€ voice/
โ”‚   โ”œโ”€โ”€ stt.py                  # faster-whisper STT
โ”‚   โ”œโ”€โ”€ tts.py                  # Piper/pyttsx3 TTS
โ”‚   โ”œโ”€โ”€ vad.py                  # Silero VAD
โ”‚   โ””โ”€โ”€ interruption.py         # Interruption handler
โ”‚
โ”œโ”€โ”€ rag/
โ”‚   โ”œโ”€โ”€ vectorstore.py          # ChromaDB management
โ”‚   โ”œโ”€โ”€ ingest.py               # Document chunking & indexing
โ”‚   โ””โ”€โ”€ retriever.py            # RAG retrieval
โ”‚
โ”œโ”€โ”€ tools/
โ”‚   โ”œโ”€โ”€ visa.py                 # Processing times & status
โ”‚   โ”œโ”€โ”€ documents.py            # Required documents
โ”‚   โ”œโ”€โ”€ eligibility.py          # Visa eligibility
โ”‚   โ””โ”€โ”€ support.py              # Tickets & human handoff
โ”‚
โ”œโ”€โ”€ safety/
โ”‚   โ”œโ”€โ”€ response_guard.py       # Response validation
โ”‚   โ””โ”€โ”€ confidence.py           # Escalation logic
โ”‚
โ”œโ”€โ”€ evaluation/
โ”‚   โ”œโ”€โ”€ metrics.py              # Quality metrics
โ”‚   โ””โ”€โ”€ failure_analyzer.py     # Failure classification
โ”‚
โ”œโ”€โ”€ database/
โ”‚   โ””โ”€โ”€ db.py                   # SQLite manager
โ”‚
โ”œโ”€โ”€ dashboard/
โ”‚   โ””โ”€โ”€ components.py           # Streamlit UI components
โ”‚
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ server.py               # Startup & health checks
โ”‚   โ””โ”€โ”€ websocket.py            # WebSocket (future)
โ”‚
โ””โ”€โ”€ data/
    โ”œโ”€โ”€ travel_faq.txt           # Demo FAQ data
    โ”œโ”€โ”€ visa_processing.txt      # Demo processing times
    โ”œโ”€โ”€ required_documents.txt   # Demo document requirements
    โ””โ”€โ”€ travel_support.txt       # Demo support info

โš™๏ธ Configuration

All settings are configurable via .env:

Variable Default Description
WHISPER_MODEL small STT model (tiny/base/small/medium/large-v3)
OLLAMA_MODEL qwen2.5:3b Ollama LLM model
OLLAMA_BASE_URL http://localhost:11434 Ollama API URL
EMBEDDING_MODEL all-MiniLM-L6-v2 Embedding model
PIPER_VOICE en_US-lessac-medium Piper voice model
TTS_FALLBACK true Fall back to pyttsx3 if Piper unavailable
RAG_TOP_K 3 Number of RAG chunks to retrieve
MAX_CONVERSATION_TURNS 10 Memory window size
CONFIDENCE_HIGH 0.85 Threshold for direct answer
CONFIDENCE_MEDIUM 0.60 Threshold for clarification
FORCE_CPU false Force CPU even with CUDA available

Hardware Detection

The app automatically detects CUDA availability:

  • CUDA GPU: Uses float16 compute for STT, GPU embeddings
  • CPU only: Uses int8 compute for STT, CPU embeddings

๐Ÿ”ง Troubleshooting

"Cannot connect to Ollama"

# Start Ollama
ollama serve

# Verify it's running
curl http://localhost:11434/api/tags

"Model not found"

# Pull the configured model
ollama pull qwen2.5:3b

"faster-whisper not found"

pip install faster-whisper

"No audio output"

  • Install sounddevice: pip install sounddevice
  • Check system audio output settings
  • In text mode, audio plays via Streamlit's st.audio widget

"Piper TTS not working on Windows"

  • The piper-tts pip package may not have Windows wheels
  • The app automatically falls back to pyttsx3 (system TTS)
  • For better quality, download the Piper binary from GitHub releases

High Latency

  • Use a smaller Whisper model: WHISPER_MODEL=tiny
  • Use a smaller LLM: OLLAMA_MODEL=qwen2.5:1.5b
  • If CUDA is available, it will be used automatically

ChromaDB Errors

# Delete the vector store and re-ingest
rm -rf data/chroma_db/
python run.py

๐Ÿ“Š Evaluation Methodology

Per-Turn Metrics

  • Intent Accuracy: Based on LLM confidence score
  • Response Groundedness: Keyword overlap between response and evidence
  • Tool Success: Whether tool calls return successful results
  • Latency: Pipeline stage timing (STT + Intent + RAG + Tool + LLM + Guard + TTS)

Aggregate Metrics

  • Total conversations, average latencies
  • Tool success rate, escalation rate
  • Grounded response rate, resolution rate

Failure Classification

Failures are automatically categorized:

  • STT_FAILURE: Low confidence or empty transcription
  • INTENT_FAILURE: Unknown intent or low confidence
  • RAG_FAILURE: No relevant chunks found
  • TOOL_FAILURE: Tool returned error
  • HALLUCINATION: Response failed grounding check
  • HIGH_LATENCY: > 5 second response time
  • HUMAN_ESCALATION: Conversation escalated

โš ๏ธ Known Limitations

  1. Half-duplex interruption: User must click stop/re-record rather than auto-detecting voice during playback (true full-duplex requires WebRTC)
  2. Piper TTS Windows: May need manual binary installation; pyttsx3 fallback is available
  3. LLM tool calling: Uses deterministic intentโ†’tool mapping rather than LLM native function calling (more reliable with small models)
  4. CPU latency: On CPU-only machines, expect 3-10 second total response time
  5. Single-turn audio: Each recording is processed as a complete utterance (no streaming)
  6. Demo data only: All travel information is fictional sample data

๐Ÿ”’ Privacy

VoxRoute runs entirely locally:

  • No data sent to cloud services
  • No API keys required
  • All models run on your machine
  • Conversations stored only in local SQLite
  • Internet only needed for initial model downloads

๐Ÿ“ License

MIT License โ€” see LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages