How badrinathantv/openvoice-ai works
Purpose and Entry Points
OpenVoice AI is a browser-based, real-time voice/text assistant with a FastAPI backend and React/Vite client. Backend startup exposes HTTP, WebRTC, and WebSocket interfaces through backend/src/api/server.py; the browser boots from frontend/src/main.jsx into frontend/src/App.jsx. Container/process launch is supported by Dockerfile, entrypoint.sh, and start.sh.
Client Orchestration and UI
The frontend presents agent identity, transcript, mic/text controls, and audio-state visualizations. frontend/src/hooks/useVoicePipeline.js coordinates transport, capture, playback, and UI state; it composes WebRTC-first connectivity and WebSocket fallback from frontend/src/hooks/useWebRTC.js and frontend/src/hooks/useWebSocket.js. Agent metadata is a client-side boundary in frontend/src/config/agents.js.
API and Transport Boundary
backend/src/api/server.py owns FastAPI REST health/agent endpoints plus /api/webrtc/offer, /ws/voice, and /ws/chat. Voice traffic carries PCM and control events over WebRTC data channels primarily, with WebSocket fallback; text chat is JSON WebSocket traffic. The API delegates per-connection processing to backend/src/api/web_pipeline.py, keeping transport lifecycle separate from inference orchestration.
Voice Processing Pipeline
backend/src/api/web_pipeline.py processes inbound utterances through optional denoising, speech detection/buffering, transcription, agent response streaming, sentence chunking, and synthesized PCM output. Model adapters are separated by interfaces in backend/src/core/interfaces.py:
• VAD: backend/src/vad/silero.py
• ASR: backend/src/asr/qwen.py
• Noise reduction: backend/src/audio/denoiser.py
• TTS: backend/src/tts/piper.py (with backend/src/tts/kitten.py available)
Streaming text is segmented before TTS by backend/src/utils/chunker.py; language filtering occurs at backend/src/utils/language_guard.py.
Agent Swarm and Session Memory
backend/src/agents/session.py builds the LangGraph Swarm conversation graph and retains session/checkpoint state. backend/src/agents/state.py defines shared voice/conversation state. Specialized agents provide domain prompts, tools, and transfer behavior:
backend/src/agents/specialized/customer_care.py,
backend/src/agents/specialized/shopper.py, and
backend/src/agents/specialized/order_ops.py.
The LLM-facing wrapper in backend/src/llm/client.py connects streaming generation to this session graph. Agent handoffs are surfaced back through pipeline status/agent events for client orb updates.
Runtime, Models, and External Dependencies
Backend requires Python 3.12 and runs under Uvicorn/FastAPI; frontend requires Node 18+ with React 19/Vite. CUDA is optional but intended for Silero, Qwen ASR, and ONNX TTS/denoising. OpenAI GPT-4o-mini is the primary LLM service, with Groq configured as an alternative. Qwen ASR can run through Transformers or optional vLLM streaming. LangGraph MemorySaver provides in-process session persistence; DATABASE_URL supports MongoDB configuration but the documented conversation checkpoint is in memory.
End-to-End Control Flow
Browser microphone PCM enters WebRTC or fallback WebSocket, then web_pipeline performs VAD and utterance assembly. Accepted audio is transcribed, English-gated, and submitted to the LangGraph session. The active agent may transfer control; generated tokens stream through sentence chunking to TTS, and synthesized PCM plus transcript/status/agent events return to the browser. Text mode bypasses microphone/VAD/ASR but shares the agent-session and streamed response path.
Main entry points: session.py Swarm session graph · web_pipeline.py Connection pipeline · server.py FastAPI server · useVoicePipeline.js Voice pipeline hook
Components 18
Browser Client
- React app · Displays transcript, controls, and agent/audio state.
frontend/src/App.jsx - Voice pipeline hook · Coordinates capture, transport, playback, and UI state.
frontend/src/hooks/useVoicePipeline.js - WebRTC transport · Primary PCM and control-event channel.
frontend/src/hooks/useWebRTC.js - WebSocket transport · Fallback voice transport and text-chat channel.
frontend/src/hooks/useWebSocket.js - Agent metadata
frontend/src/config/agents.js
API & Transport
- FastAPI server · Serves health and agent APIs plus offer, voice, and chat endpoints.
backend/src/api/server.py - Connection pipeline · Separates connection lifecycle from voice and chat processing.
backend/src/api/web_pipeline.py
Voice Pipeline
- VAD & utterance buffer
backend/src/vad/silero.py - Qwen transcription
backend/src/asr/qwen.py - English gate
backend/src/utils/language_guard.py - Sentence chunker
backend/src/utils/chunker.py - Piper synthesis · Produces streamed PCM response audio.
backend/src/tts/piper.py
Agent Runtime
- Swarm session graph · Builds conversations and retains in-process checkpoint state.
backend/src/agents/session.py - Conversation state
backend/src/agents/state.py - Specialized agents · Provide prompts, tools, and transfer behavior.
backend/src/agents/specialized/customer_care.py - LLM streaming client · Connects streaming generation to the session graph.
backend/src/llm/client.py
Models & Services
- LLM providers · GPT-4o-mini is primary; Groq is an alternative.
- MemorySaver
Connections 22
- React app → Voice pipeline hook: UI actions and state
- Agent metadata → React app: agent identity
- Voice pipeline hook → WebRTC transport: primary transport
- Voice pipeline hook → WebSocket transport: fallback / text mode
- WebRTC transport → FastAPI server: offer, PCM, control events
- WebSocket transport → FastAPI server: voice fallback and chat JSON
- FastAPI server → Connection pipeline: per-connection processing
- Connection pipeline → VAD & utterance buffer: microphone audio
- VAD & utterance buffer → Qwen transcription: accepted utterance
- Qwen transcription → English gate: transcript
- English gate → Swarm session graph: validated text
- Connection pipeline → Swarm session graph: text mode · Text chat bypasses VAD and ASR.
- Swarm session graph → Conversation state: reads and updates
- Swarm session graph → Specialized agents: routes and transfers
- Swarm session graph → LLM streaming client: streams generation
- LLM streaming client → LLM providers: LLM requests
- Swarm session graph → MemorySaver: checkpoints
- LLM streaming client → Sentence chunker: streamed tokens
- Sentence chunker → Piper synthesis: sentences
- Piper synthesis → Connection pipeline: synthesized PCM
- Connection pipeline → FastAPI server: PCM, transcript, status, agent events
- FastAPI server → Voice pipeline hook: response events