Complete working Svelte 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:3002
This example uses unpkg.com CDN to load WASM files - this is the recommended approach for end users as it requires no additional configuration or file copying.
The initialization uses CDN URLs:
await lipSyncEngine.init({
wasmPath: 'https://unpkg.com/lip-sync-engine@latest/dist/wasm/lip-sync-engine.wasm',
dataPath: 'https://unpkg.com/lip-sync-engine@latest/dist/wasm/lip-sync-engine.data',
jsPath: 'https://unpkg.com/lip-sync-engine@latest/dist/wasm/lip-sync-engine.js'
});For production, pin to a specific version:
await lipSyncEngine.init({
wasmPath: 'https://unpkg.com/lip-sync-engine@1.0.2/dist/wasm/lip-sync-engine.wasm',
dataPath: 'https://unpkg.com/lip-sync-engine@1.0.2/dist/wasm/lip-sync-engine.data',
jsPath: 'https://unpkg.com/lip-sync-engine@1.0.2/dist/wasm/lip-sync-engine.js'
});examples/svelte/
βββ public/
β βββ visemes/ # Symlink to shared viseme images
βββ src/
β βββ stores/
β β βββ lipSyncEngine.ts # Svelte store
β βββ App.svelte # Main application (dark mode)
β βββ main.ts # Entry point
β βββ app.css # Global styles
βββ index.html # HTML template
βββ package.json # Dependencies
βββ tsconfig.json # TypeScript config
βββ svelte.config.js # Svelte config
βββ vite.config.ts # Vite config
The lipSyncEngineStore provides reactive state management:
<script>
import { lipSyncEngineStore } from './stores/lipSyncEngine';
import { recordAudio } from 'lip-sync-engine';
async function handleRecord() {
const { pcm16 } = await recordAudio(5000);
await lipSyncEngineStore.analyze(pcm16, { dialogText: "Hello world" });
}
</script>
<button on:click={handleRecord} disabled={$lipSyncEngineStore.isAnalyzing}>
{$lipSyncEngineStore.isAnalyzing ? 'Analyzing...' : 'Record'}
</button>The example demonstrates synchronized viseme animation with Svelte reactivity:
<script lang="ts">
let currentViseme = 'X';
let audioBuffer: 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
currentViseme = mouthCues[currentCueIndex].value;
requestAnimationFrame(updateViseme);
}
}
// Auto-play when result is available
$: if ($lipSyncEngineStore.result && audioBuffer) {
playAnimation($lipSyncEngineStore.result.mouthCues, audioBuffer);
}
</script>
<div class="viseme-images">
{#each ['X', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'] as viseme}
<img
src="/visemes/{viseme}.png"
alt={viseme}
class:active={currentViseme === viseme}
/>
{/each}
</div>- Reactive Store - Automatic reactivity with Svelte stores
- Simple API - Subscribe with
$syntax - Reactive Statements -
$:for auto-play functionality - Error Handling - Comprehensive error states
- TypeScript - Full type safety
- Async Analysis - Non-blocking UI with
analyzeAsync() - Audio Playback - Web Audio API integration for synchronized animation
- Timestamped Logging - Detailed logs with color-coded types
npm run build
npm run preview- Svelte 4
- TypeScript
- Vite
- LipSyncEngine.js (via npm + CDN for WASM)
- Web Audio API