How roberttips/ai-chat-voice works
1. Overall shape
- This is a small, single-page local chat app with a thin Node.js server and a browser-based frontend.
- The core architecture is: browser UI + Web Speech API + local Node proxy/server + local Ollama daemon.
2. Primary runtime boundaries
- Browser: renders the UI, manages conversation state, streams assistant replies, and handles speech synthesis/recognition.
- Node.js server (server.js): serves the static files and proxies requests to Ollama.
- Ollama: provides model metadata and chat completions locally.
- User’s OS/browser speech stack: supplies available voices and microphone recognition through the Web Speech API.
3. Frontend module layout
- scripts/app.js is the browser entrypoint and event wiring layer.
- scripts/dom.js centralizes DOM references.
- scripts/config.js holds shared constants.
- scripts/ui.js contains UI helpers.
- scripts/theme.js handles system theme detection.
- scripts/models.js, scripts/chat.js, and scripts/speech.js are the main feature modules.
4. Chat data flow
- User input enters through the browser UI.
- chat.js sends messages to the local server, which forwards them to Ollama.
- Assistant responses are streamed back and rendered progressively in the UI.
- Conversation state is maintained client-side so the browser can continue the dialogue and replay past assistant messages.
5. Model discovery and selection
- models.js loads the list of available Ollama models from the local backend.
- The selected model becomes part of the chat request path, so model choice is a user-controlled runtime dependency rather than a build-time setting.
6. Voice and microphone subsystem
- speech.js wraps browser speech synthesis for auto-readout and per-message replay.
- It also wraps speech recognition via SpeechRecognition or webkitSpeechRecognition.
- Voice selection comes from the browser/OS-installed voices, not from Ollama.
- Hands-free mode is a browser-side loop: after spoken output ends, the app listens for a short window, waits for a pause, then submits the transcript as the next message.
7. UI behavior and presentation
- ui.js supports interaction patterns such as buttons, state changes, and message rendering.
- styles/main.css provides the full visual layer and system-aware styling.
- theme.js aligns the interface with the user’s light/dark system preference.
8. Server responsibilities
- server.js is intentionally minimal: static file hosting plus an Ollama API proxy.
- This avoids direct browser-to-Ollama coupling issues and keeps the browser talking to one local origin.
- The repo has no external frontend dependencies or API keys; all AI traffic stays on the local machine.
9. Operational dependencies
- The app requires Ollama to be running locally and at least one model to be installed.
- Hands-free microphone mode depends on browser support for the Web Speech API, which is typically better in Chrome/Edge.
- Because speech voices come from the browser and operating system, available voices can differ across environments even on the same machine.
10. Architecture takeaway
- The important diagram boundaries are:
- Presentation and interaction in the browser
- Local HTTP proxy/static server in Node
- Local Ollama model inference
- Browser/OS speech engines for TTS and STT
- Most of the app logic lives in the browser; the server is only an integration boundary.
Main entry points: app.js App entry · speech.js Speech · server.js Server · ui.js UI helpers
Components 15
Browser app
Client-side UI, state, and speech interactions
- App shell · Single-page container for the browser app
index.html - App entry · Wires UI events and coordinates feature modules
scripts/app.js - DOM refs · Centralized element lookup and shared handles
scripts/dom.js - Config · Shared client-side constants and defaults
scripts/config.js - UI helpers · Message rendering and interactive UI behavior
scripts/ui.js - Theme · Adapts the UI to light and dark preferences
scripts/theme.js - Model picker · Loads available local models and tracks selection
scripts/models.js - Chat flow · Sends prompts, streams replies, and keeps chat state
scripts/chat.js - Speech · Wraps voice output and microphone recognition
scripts/speech.js - Styles · Visual styling and responsive presentation
styles/main.css
Local server
Node static host and Ollama proxy
- Server · Serves static files and forwards API calls to Ollama
server.js
External runtimes
Local services and browser/OS APIs
- Ollama · Local model metadata and chat completion provider
- Speech API · System voices and microphone recognition support
- System theme · Light/dark appearance preference from the host environment
- User · Types messages, selects models, and uses voice controls
Connections 16
- App shell → App entry: loads · Bootstraps the browser application
- App entry → DOM refs: binds · Reads shared DOM references
- App entry → Config: uses · Applies shared runtime settings
- App entry → UI helpers: orchestrates · Coordinates rendering and interaction
- App entry → Theme: initializes · Sets up theme handling
- App entry → Model picker: initializes · Fetches model list for selection
- App entry → Chat flow: connects · Routes user messages into the chat pipeline
- App entry → Speech: connects · Enables speech output and voice input
- UI helpers → Styles: styled by · Presentation is driven by the stylesheet
- Theme → System theme: reads · Follows host light/dark preference
- Model picker → Server: fetches · Requests available models from the local backend
- Chat flow → Server: posts to · Sends chat requests through the local proxy
- Server → Ollama: proxies · Forwards model and chat API traffic locally
- Speech → Speech API: uses · Wraps browser speech synthesis and recognition
- User → App entry: drives · Provides input and controls the conversation
- User → Speech: speaks/listens · Uses hands-free and replay voice features