# Voice-Enabled OpenWebUI Chat PRD
Execute via Gemini Flash 2.0 Ralph Wiggum Loop

## Context
Build voice-enabled chat interface using OpenWebUI that can talk to:
1. Claude Code terminal agents
2. AIVA (Ollama on Elestio)

This enables hands-free voice interaction with Genesis agents.

**Infrastructure:**
- Elestio Ollama: `ollama-genesis-u50607.vm.elestio.app`
- Local Whisper: `E:\voice-dictation\whisper-writer` (medium.en model)
- OpenWebUI: To be deployed

---

### US-001: OpenWebUI Docker Compose
**Goal:** Create Docker Compose for OpenWebUI with Ollama backend

**Acceptance Criteria:**
- GIVEN docker-compose.yml WHEN docker-compose up THEN OpenWebUI accessible on port 3000
- AND connects to Elestio Ollama backend
- AND persists data in volume
- AND includes environment variables for API keys

**Files to Create:**
- `/mnt/e/genesis-system/apps/openwebui/docker-compose.yml`

**Technical Hints:**
Use ghcr.io/open-webui/open-webui:main image. Env vars: OLLAMA_BASE_URL=https://ollama-genesis-u50607.vm.elestio.app, WEBUI_AUTH=false for dev. Expose port 3000. Volume for /app/backend/data.

**Dependencies:** None

---

### US-002: OpenWebUI Ollama Connection Config
**Goal:** Create configuration to connect OpenWebUI to Elestio Ollama

**Acceptance Criteria:**
- GIVEN config file WHEN OpenWebUI starts THEN Ollama models available
- AND includes authentication for Elestio
- AND lists available models (qwen2.5:32b, llama3.2, etc.)

**Files to Create:**
- `/mnt/e/genesis-system/apps/openwebui/config.json`

**Technical Hints:**
Elestio Ollama uses basic auth. Include models list. Set default model to qwen2.5:32b. Enable streaming responses.

**Dependencies:** US-001

---

### US-003: Voice Input Bridge Script
**Goal:** Create Python bridge between local whisper and OpenWebUI

**Acceptance Criteria:**
- GIVEN voice input WHEN transcribed by Whisper THEN sent to OpenWebUI API
- AND captures audio from microphone
- AND uses faster-whisper for GPU-accelerated transcription
- AND outputs to OpenWebUI chat endpoint

**Files to Create:**
- `/mnt/e/genesis-system/apps/openwebui/voice_bridge.py`

**Technical Hints:**
Use sounddevice for audio capture. Use faster-whisper with model medium.en on CUDA. OpenWebUI API endpoint: POST /api/chat. Include VAD (voice activity detection) for automatic speech detection.

**Dependencies:** None

---

### US-004: Claude Code WebSocket Bridge
**Goal:** Create bridge that relays OpenWebUI messages to Claude Code terminal

**Acceptance Criteria:**
- GIVEN message from OpenWebUI WHEN route=claude-code THEN message sent to Claude Code
- AND captures Claude Code response
- AND streams response back to OpenWebUI
- AND handles multi-turn conversation

**Files to Create:**
- `/mnt/e/genesis-system/apps/openwebui/claude_bridge.py`

**Technical Hints:**
Use websocket for bidirectional communication. Claude Code listens on terminal stdin. Capture stdout. Format as OpenWebUI chat response. Include timeout handling.

**Dependencies:** US-001

---

### US-005: AIVA Chat Endpoint
**Goal:** Create FastAPI endpoint for AIVA chat that OpenWebUI can call

**Acceptance Criteria:**
- GIVEN OpenWebUI request WHEN endpoint called THEN AIVA responds via Ollama
- AND uses qwen2.5:32b model
- AND includes Genesis system context
- AND streams response

**Files to Create:**
- `/mnt/e/genesis-system/apps/openwebui/aiva_endpoint.py`

**Technical Hints:**
FastAPI with streaming response. Call Ollama API at Elestio. System prompt includes AIVA personality and Genesis context. Use httpx for async streaming.

**Dependencies:** US-002

---

### US-006: Text-to-Speech Output
**Goal:** Create TTS module for voice output from agent responses

**Acceptance Criteria:**
- GIVEN agent response WHEN TTS enabled THEN response spoken aloud
- AND uses ElevenLabs or local pyttsx3
- AND configurable voice settings
- AND non-blocking audio playback

**Files to Create:**
- `/mnt/e/genesis-system/apps/openwebui/tts_output.py`

**Technical Hints:**
Try ElevenLabs API first (check for key). Fallback to pyttsx3 for local TTS. Use threading for non-blocking playback. Include voice selection (Australian accent preferred).

**Dependencies:** None

---

### US-007: Voice Chat Orchestrator
**Goal:** Create main orchestrator combining voice input, routing, and TTS output

**Acceptance Criteria:**
- GIVEN voice command WHEN processed THEN appropriate agent responds with voice
- AND routes to Claude Code for code tasks
- AND routes to AIVA for general queries
- AND provides voice feedback

**Files to Create:**
- `/mnt/e/genesis-system/apps/openwebui/voice_orchestrator.py`

**Technical Hints:**
Main loop: listen -> transcribe -> route -> get response -> speak. Intent detection for routing. Keywords like "claude", "code", "terminal" route to Claude Code. Default to AIVA.

**Dependencies:** US-003, US-004, US-005, US-006

---

### US-008: Windows Launch Script
**Goal:** Create PowerShell script to launch voice chat system

**Acceptance Criteria:**
- GIVEN script execution WHEN run THEN all voice chat components start
- AND starts OpenWebUI container
- AND starts voice bridge
- AND creates desktop shortcut

**Files to Create:**
- `/mnt/e/genesis-system/apps/openwebui/start_voice_chat.ps1`

**Technical Hints:**
Start docker-compose in background. Start voice_orchestrator.py. Check for CUDA availability. Create shortcut in Desktop folder. Include health check.

**Dependencies:** US-001, US-007

---

### US-009: OpenWebUI Custom Model Config
**Goal:** Create custom model configurations for Claude Code and AIVA in OpenWebUI

**Acceptance Criteria:**
- GIVEN OpenWebUI WHEN models listed THEN Claude Code and AIVA appear as options
- AND Claude Code model routes to claude_bridge
- AND AIVA model routes to aiva_endpoint
- AND includes model descriptions

**Files to Create:**
- `/mnt/e/genesis-system/apps/openwebui/models/claude_code.json`
- `/mnt/e/genesis-system/apps/openwebui/models/aiva.json`

**Technical Hints:**
OpenWebUI modelfiles format. Claude Code: description "Terminal agent for code execution", endpoint localhost:8001. AIVA: description "Genesis orchestrator", endpoint localhost:8002. Include system prompts.

**Dependencies:** US-004, US-005

---

### US-010: Health Check Dashboard
**Goal:** Create simple HTML dashboard showing voice chat system status

**Acceptance Criteria:**
- GIVEN dashboard URL WHEN accessed THEN shows all component status
- AND shows: OpenWebUI, Ollama, Voice Bridge, Claude Bridge, AIVA Endpoint
- AND auto-refreshes every 10 seconds
- AND shows last message processed

**Files to Create:**
- `/mnt/e/genesis-system/apps/openwebui/dashboard.html`

**Technical Hints:**
Simple HTML with fetch() to status endpoints. Green/red indicators. Show uptime. Include quick test buttons. Use vanilla JS, no frameworks.

**Dependencies:** US-001, US-005

---
