Complete working React application demonstrating LipSyncEngine.js integration with a modern dark mode UI.
- ποΈ Record Audio - Record from microphone with adjustable duration (5-60 seconds)
- π Load Audio File - Load any audio file (MP3, WAV, etc.)
- π Dialog Text Input - Provide optional text for better accuracy
- β‘ Three Execution Modes:
- Single Thread - Traditional blocking mode
- Web Worker - Non-blocking with single worker
- Chunked Workers - Parallel processing with multiple workers
- π Performance Metrics - View execution time, cue count, and worker usage
- ποΈ Adjustable Settings - Control recording duration and chunk size
- π Real-time Viseme Display - Animated mouth shapes synchronized with audio playback
βΆοΈ Replay Button - Play back animations on demand- π Results Timeline - View all detected mouth cues with timestamps
- π Timestamped Logs - Terminal-style logs showing all processing steps
- π¨ Modern Dark Mode UI - Professional, contemporary interface
# Install dependencies
npm install
# Start development server
npm run devThen open http://localhost:3000
No configuration needed! WASM files are automatically loaded from unpkg.com CDN. Just call init() with no parameters:
await lipSyncEngine.init(); // That's it!The library automatically uses the correct version from the package. For production, you can optionally pin to a specific version:
await lipSyncEngine.init({
wasmPath: 'https://unpkg.com/lip-sync-engine@1.0.3/dist/wasm/lip-sync-engine.wasm',
dataPath: 'https://unpkg.com/lip-sync-engine@1.0.3/dist/wasm/lip-sync-engine.data',
jsPath: 'https://unpkg.com/lip-sync-engine@1.0.3/dist/wasm/lip-sync-engine.js'
});Works with all bundlers - Vite, Webpack, Rollup, esbuild, etc. No special bundler configuration required!
examples/react/
βββ public/
β βββ visemes/ # Symlink to shared viseme images
βββ src/
β βββ hooks/
β β βββ useLipSyncEngine.ts # Custom React hook
β βββ App.tsx # Main application
β βββ App.css # Dark mode styles
β βββ main.tsx # Entry point
β βββ index.css # Global styles
βββ index.html # HTML template
βββ package.json # Dependencies
βββ tsconfig.json # TypeScript config
βββ vite.config.ts # Vite config
The useLipSyncEngine hook provides a clean API:
import { useLipSyncEngine } from './hooks/useLipSyncEngine';
import { recordAudio } from 'lip-sync-engine';
function MyComponent() {
const {
analyze,
result,
isAnalyzing,
error,
reset,
mode,
setMode,
recordingDuration,
setRecordingDuration
} = useLipSyncEngine();
const handleRecord = async () => {
const { pcm16 } = await recordAudio(recordingDuration * 1000);
await analyze(pcm16, { dialogText: "Hello world" });
};
return (
<div>
<select value={mode} onChange={(e) => setMode(e.target.value)}>
<option value="single">Single Thread</option>
<option value="worker">Web Worker</option>
<option value="chunked">Chunked Workers</option>
</select>
<input
type="range"
min="5"
max="60"
step="5"
value={recordingDuration}
onChange={(e) => setRecordingDuration(Number(e.target.value))}
/>
<button onClick={handleRecord} disabled={isAnalyzing}>
{isAnalyzing ? 'Analyzing...' : `Record ${recordingDuration}s`}
</button>
</div>
);
}The example demonstrates synchronized viseme animation:
const [currentViseme, setCurrentViseme] = useState('X');
const [audioBuffer, setAudioBuffer] = useState<AudioBuffer | null>(null);
// Play animation synchronized with audio
function playAnimation(mouthCues, buffer) {
const audioContext = new AudioContext();
const source = audioContext.createBufferSource();
source.buffer = buffer;
source.connect(audioContext.destination);
source.start(0);
// Animate visemes frame by frame
function updateViseme() {
const elapsed = audioContext.currentTime - startTime;
// Update current viseme based on elapsed time
setCurrentViseme(mouthCues[currentCueIndex].value);
requestAnimationFrame(updateViseme);
}
}- Mode-Based Initialization - Different engines initialize based on selected mode
- Worker Pool Warmup - Pre-initialize workers for chunked mode performance
- Adjustable Recording Duration - User-controlled recording time (5-60s)
- Performance Metrics - Track execution time, cues, workers, and chunks
- Cleanup on Unmount - Resources are properly freed
- Error Handling - Comprehensive error states
- TypeScript - Full type safety
- Audio Playback - Web Audio API integration for synchronized animation
- Timestamped Logging - Detailed logs with color-coded types
npm run build
npm run preview- React 18
- TypeScript
- Vite
- LipSyncEngine.js (via npm + CDN for WASM)
- Web Audio API