6.0 KiB
6.0 KiB
3D Digital Human System Technical Documentation
1. Project Summary
This project implements a real-time conversational digital human system with these core capabilities:
- Text and voice interaction
- LLM response generation (DeepSeek online, with fallback)
- TTS synthesis for reply audio
- Audio-driven 3D animation control stream
- Browser-side 3D rendering (Three.js + VRM/GLTF)
- WebRTC audio transport and WebSocket animation transport
Current workspace root:
/home/xsl/code/product
2. Runtime Architecture
2.1 High-Level Pipeline
- User input enters through
/chat/textor voice pipeline. - LLM generates reply text.
- TTS synthesizes reply waveform.
- Avatar service converts audio chunks to animation control frames.
- Backend pushes:
- reply audio to WebRTC audio track
- animation frames to
/ws/animation
- Frontend renders 3D model and applies mouth/head/body motions.
2.2 Transport Split
- WebRTC: audio only
- WebSocket (
/ws/animation): animation control data - SSE (
/events): system metrics and runtime status
This split removes server-side video generation and makes rendering native in the browser.
3. Core Modules
3.1 Backend Entry
main.py
Responsibilities:
- FastAPI app and route registration
- WebRTC offer/peer management
- Animation WebSocket broadcasting
- Runtime metrics and
/health - Session reset and chat endpoints
3.2 Pipeline Orchestration
core/pipeline.pycore/state_machine.py
Responsibilities:
- Turn-based orchestration (input -> LLM -> TTS -> output)
- State transitions (idle, thinking, speaking)
- Latency accounting and result metadata
3.3 Services
services/llm.pyservices/tts.pyservices/asr.pyservices/vad.pyservices/avatar.py
Responsibilities:
LLMService: online model calls via OpenAI-compatible clientTTSService: speech synthesisAvatarService: audio-to-controls mapping for mouth/viseme/head motion
3.4 Frontend
web/index.htmlweb/app.jsweb/style.css
Responsibilities:
- Three.js scene setup and camera controls
- VRM/GLTF model loading (URL or local file)
- Animation buffering and frame application
- Idle body pose + talking expressions
- WebRTC audio playback
4. Animation Data Contract
Backend pushes animation chunks shaped like:
type:animation_chunk/animation_reset/animation_statefps,duration_ms,frame_countframes[]with:seqtime_mscontrols
Typical controls include:
jawOpenviseme_aa,viseme_ee,viseme_ohmouthPuckerheadYaw,headPitch,headRoll
Frontend behavior:
- buffers frames for stable playback
- applies VRM expressions when available
- falls back to morph targets or bone motion
5. Configuration
Configuration file:
.env(root)
5.1 LLM Settings
Supported API key aliases:
LLM_API_KEYDEEPSEEK_API_KEYOPENAI_API_KEY
Recommended DeepSeek settings:
LLM_BASE_URL=https://api.deepseek.com/v1LLM_MODEL=deepseek-chat
5.2 Server Settings
WEBRTC_HOST(default0.0.0.0)WEBRTC_PORT(default8018)SSL_CERTFILESSL_KEYFILE
5.3 Avatar Settings
AVATAR_DRIVER_MODE=blendshape_streamAVATAR_CONTROL_PROTOCOL=wsAVATAR_BLENDSHAPE_SCHEMA=arkit
6. Startup and Process Control
New process script:
scripts/service-8018.sh
Usage:
bash scripts/service-8018.sh start
bash scripts/service-8018.sh status
bash scripts/service-8018.sh logs
bash scripts/service-8018.sh restart
bash scripts/service-8018.sh stop
Behavior:
- Loads environment from
.env - Starts uvicorn from project venv if available
- Supports HTTPS cert/key from
.env - Writes pid and log to
.run/ - Cleans stale python listeners on target port
Runtime files:
.run/visual-chat-8018.pid.run/visual-chat-8018.log
7. API and Web Endpoints
7.1 Health and Metadata
GET /healthGET /meta
7.2 Chat and Session
POST /chat/textPOST /chat/reset
7.3 Streaming Channels
GET /events(SSE)GET /ws/subtitles(WebSocket)GET /ws/animation(WebSocket)
7.4 WebRTC
POST /webrtc/offer
8. Validation Checklist
8.1 Service Up
bash scripts/service-8018.sh statusshould show runningGET /healthshould return valid JSON
8.2 LLM Online
Health fields should indicate:
llm.ready = truellm.error = nulllast_llm_source = onlineafter at least one chat turn
8.3 Frontend Motion and Audio
- Model loads successfully
- Mouth motion follows replies
- Body remains in non-T-pose idle stance
- Remote audio is audible via WebRTC
9. Troubleshooting Guide
9.1 LLM stays fallback
Symptoms:
last_llm_source = fallbackllm.ready = false
Checks:
- Confirm
.envexists in workspace root. - Confirm key value is set in
LLM_API_KEY(or alias). - Restart service after any
.envupdate. - Verify
llm.base_urlandllm.modelin/health.
9.2 Model load errors
Symptoms:
- Web UI shows model fetch failures
Checks:
- Use reachable URL or local
.vrmfile. - Confirm browser can access external CDN.
- Prefer VRM full-body models for body-pose control.
9.3 Mouth not moving
Checks:
- Confirm animation websocket connected.
- Confirm animation frame count increases.
- Confirm TTS is ready and not in silence fallback.
9.4 HTTPS/microphone issues on LAN
Checks:
- Use valid cert paths in
.env. - Trust self-signed cert on browser/device.
- Ensure firewall allows target port.
10. Security and Operations Notes
- Keep
.envout of source control. - Rotate API keys regularly.
- Restrict exposed port by network policy if internet-facing.
- Consider reverse proxy and managed TLS for production.
11. Suggested Next Production Steps
- Add structured request tracing (request id, turn id).
- Add persistent metrics export (Prometheus/OpenTelemetry).
- Add automatic reconnect and health watchdog.
- Add integration tests for LLM online/fallback branches.
- Add model asset mirror to avoid public CDN instability.