How chandailrc/talkingheadrc works
Project type and purpose
• This is a client-side JavaScript 3D avatar library (“TalkingHead”) plus a demo/web-app (index.html and examples/) showcasing how to integrate it with various external AI and TTS services.
• Purpose: render a 3D avatar in the browser (ThreeJS/WebGL), fetch synthesized speech (visemes + audio), and drive real-time lip-sync and animations.
File structure
Top-level:
• modules/ – ES‐module files: talkinghead.mjs core class and lipsync-xx language modules
• index.html – full demo/test web-app integrating all features
• examples/ – minimal usage samples for hobbyists (static HTML/JS)
• animations/, poses/, avatars/, audio/, views/, fonts/ – static assets consumed by the library/demo
• siteconfig.js – configuration for the demo app (i18n, background media, API endpoints)
• eslint.config.mjs, jsconfig.json – linting/IDE support
• README.md – description, usage, architecture, proxy setup, appendices
Extracted architecture insights from README
• Core class: TalkingHead – loads GLB avatar, plays FBX Mixamo animations, manages camera & lighting (ThreeJS).
• Lip-sync modules (lipsync-en/fi/lt) transform text → visemes.
• speakText() uses Google TTS via a proxy endpoint to get word timestamps.
• speakAudio() supports Azure/Elevenlabs via WebSocket.
• The demo app (index.html) configures API proxies for OpenAI, Azure, ElevenLabs, Google TTS, Vertex AI, secured by JWT SSO.
Components
a. Main components:
1. Browser-based Web Client
2. TalkingHead JS Library (talkinghead.mjs)
– LipSync Modules (modules/lipsync-xx.mjs)
– ThreeJS Renderer & Scene Manager
– Animation Controller (Mixamo FBX loader)
– Audio Manager & Viseme Scheduler
3. Static Asset Store (avatars/, animations/, poses/, audio/, views/, fonts/)
4. Demo Web App (index.html + siteconfig.js + examples/)
5. Proxy Layer (Node or Apache CGI)
– JWT Auth Service
– REST/WebSocket Proxies for:
• Google TTS API
• Microsoft Azure Speech SDK
• ElevenLabs WebSocket TTS
• OpenAI API (Chat, Whisper, Moderation)
• Vertex AI (Gemini)
6. External AI/TTS Services
– Google Cloud TTS
– Microsoft Speech Services
– ElevenLabs
– OpenAI / Whisper / ChatGPT
– Vertex AI / Gemini
b. Relationships & data flows:
1. User interacts with demo UI → Web Client
2. Web Client loads TalkingHead library (ES modules)
3. TalkingHead fetches 3D model & assets from Static Asset Store
4. Browser calls speakText()/speakAudio()
5. Audio Manager forwards text/audio request to Proxy Layer
6. Proxy authenticates via JWT and routes to External Service
7. External Service returns audio + word-timestamp or viseme stream
9. ThreeJS renderer drives WebGL animation in real time
10. Demo UI displays subtitles (Marked markdown parser) and stats
c. Architectural patterns & design principles:
• Modular ES‐module design: core + pluggable lip-sync modules
• Separation of concerns: rendering vs. audio processing vs. networking
• Proxy pattern for service integration and centralized auth (JWT)
• Asynchronous pipelines: Promises/async‐await for asset loading and TTS/network calls
• Extensibility: new lip-sync languages or TTS services can be added via modules and proxies
d. Key technologies & libraries:
• ThreeJS (WebGL rendering)
• Marked + DOMPurify (subtitles/Markdown)
• Mixamo FBX loader (animations/poses)
• Web Audio API (audio playback, viseme sync)
• ES Modules (talkinghead.mjs, lipsync-xx.mjs)
• JWT + Apache/NGINX proxy for secured service integration
Final remarks
• Essential elements but avoid clutter: group similar services (e.g., OpenAI APIs)
• Error path / fallback (e.g., missing visemes → default lip-sync) if relevant
• Top: User & UI
• Middle: Core Library & Renderer
• Bottom left: Asset Store
• Bottom right: Proxy Layer & External Services