A mobile-optimized React web app that plays HLS and MP4 video and performs real-time speech recognition on the audio. When trigger phrases are detected, visual effects fire as transparent overlays on top of the playing video.
| Phrase | Effect |
|---|---|
| "like and subscribe" | Like button pulses with a glowing bounce animation |
| "buy now" | Floating $ signs rise from the bottom with green glow |
| "coffee" | Coffee mug emojis rain from the top with rotation and amber glow |
| "hi" or "hello" | A large waving hand emoji pops in, waves 3 times, then pops out |
- HLS + MP4 playback — hls.js for HLS on Chrome/Firefox, native HLS on Safari/iOS, direct
srcfor MP4/WebM - User-configurable URL — paste any
.m3u8or.mp4URL to load it - Real-time speech detection — Whisper (tiny.en) running in a Web Worker via
@huggingface/transformers, with WebGPU acceleration where available, WASM fallback otherwise - 4 distinct visual effects — each triggered by a different phrase, all rendered as transparent canvas overlays
- Word-boundary matching — "hi" doesn't false-trigger on "while"
- Per-phrase cooldowns — 5s debounce prevents rapid re-triggering
- Debug panel — toggleable overlay with FPS counter, live transcript, and manual trigger buttons for all effects
| Platform | Video | Speech detection |
|---|---|---|
| Chrome (desktop) | hls.js / native (MP4) | ✅ Whisper (WebGPU or WASM) |
| Firefox (desktop) | hls.js / native (MP4) | ✅ Whisper (WASM) |
| Android Chrome | hls.js / native (MP4) | ✅ Whisper (WebGPU or WASM) |
| Safari (desktop) | Native HLS / native (MP4) | ✅ Whisper (WASM) |
| iOS Safari | Native HLS / native (MP4) | ❌ Not supported |
iOS Safari limitation: Speech detection requires HTMLMediaElement.captureStream() to pipe video audio into the Whisper worker. iOS Safari does not implement this API, so the audio pipeline cannot start and the speech toggle has no effect. Video playback works normally.
| Layer | Choice |
|---|---|
| Framework | React 19 + TypeScript + Vite 6 |
| Styling | Tailwind CSS v4 |
| Video | hls.js (HLS, non-Safari) / native HLS (Safari) / direct src (MP4) |
| Speech | Whisper tiny.en via @huggingface/transformers in a Web Worker |
| Canvas effects | Transparent overlay — canvas clears to transparent each frame, only particles/sprites are drawn |
| Testing | Vitest + React Testing Library + jsdom |
npm install
npm run devOpen http://localhost:5173. The app loads a public Mux HLS test stream by default. Paste any .m3u8 or .mp4 URL in the top bar to switch videos.
- Click Speech Off in the controls bar to toggle it on
- Unmute the video (bottom-right button)
- Speak "like and subscribe", "buy now", "coffee", "hi", or "hello"
The first time you enable speech detection the Whisper model (~40 MB) is downloaded and cached in the browser. A loading progress indicator is shown during this step. Subsequent uses load instantly from cache.
Open the Debug panel (top-right corner) and click any trigger button to fire the effect manually.
npm run dev # Dev server at localhost:5173
npm run build # Production build
npm run preview # Preview production build
npm run test # Run all tests (Vitest)
npm run test:watch # Watch modesrc/
├── components/
│ ├── VideoPlayer.tsx # Video + canvas container, mute control
│ ├── LikeButton.tsx # Animated heart toggle
│ ├── StatusIndicator.tsx # Speech engine status badge
│ └── DebugPanel.tsx # Debug overlay with manual trigger buttons
├── hooks/
│ ├── useVideoSource.ts # HLS + MP4 detection and attachment
│ ├── useAudioRouting.ts # video.captureStream() → MediaStream pipeline
│ ├── useSpeechTriggers.ts # MediaStream → Whisper → phrase detection → callbacks
│ ├── useCanvasEffects.ts # Manages all canvas effects (dollars, coffee, wave)
│ ├── useWhisperFallback.ts # Audio chunking + Web Worker bridge
│ └── useDebouncedCallback.ts
├── workers/
│ └── whisper.worker.ts # Whisper transcription via @huggingface/transformers
├── utils/
│ ├── whisperPipeline.ts # createTranscriberHandler factory (WebGPU → WASM fallback)
│ ├── phraseMatching.ts # Normalize transcript, word-boundary phrase detection
│ ├── particleSystem.ts # Shared pool logic + dollar sign rendering
│ ├── coffeeEffect.ts # Coffee-specific spawn (falling, rotating) + render
│ ├── waveEffect.ts # Hand wave animation (elastic pop-in, pendulum, pop-out)
│ ├── audioRouting.ts # captureStream() → audio track extraction
│ ├── canvasHelpers.ts # DPR scaling, ResizeObserver setup
│ ├── hlsConfig.ts # hls.js configuration defaults
│ └── constants.ts # URLs, phrase configs, pool sizes, durations
├── types/
│ └── index.ts # Shared interfaces and types
└── __tests__/ # 125 tests across 15 files
The canvas element is positioned over the video with pointer-events: none. Each animation frame clears to transparent (clearRect) and draws only the active effect's particles or sprites. The <video> element stays fully visible and plays uninterrupted — effects appear as a filter layer on top of live playback.
Multiple effects can run simultaneously on the same canvas. The rAF loop only runs when at least one effect is active.
Dollar signs ($) — 50-particle pool, float upward from bottom, sinusoidal horizontal drift, green shadowBlur glow, 3-5s lifetime.
Coffee mugs (☕) — 30-particle pool, fall from above viewport, gravity-based acceleration, individual rotation per mug, staggered spawn in 4 waves for a "pouring" feel, amber glow, slow down and fade near bottom.
Hand wave (👋) — Single sprite, not a particle system. Elastic overshoot pop-in, 3-cycle pendulum swing with squash/stretch deformation, quick scale-down exit. 2.5s total.
video.captureStream()
└─ audio tracks → MediaStream
└─ AudioContext (16 kHz) + ScriptProcessor
└─ 5s chunks (2s overlap) → Float32Array
└─ Web Worker: @huggingface/transformers
├─ WebGPU pipeline (if available)
└─ WASM pipeline (fallback)
└─ Whisper tiny.en → transcript text
└─ detectPhrases() → debounced callbacks
Audio chunks are gated by a "ready" flag — no audio is sent to the worker until the model finishes loading, avoiding stale pre-load audio being transcribed.
URL ends in .m3u8 → HLS path:
Safari/iOS → native HLS (video.src)
Other → hls.js (attach + loadSource)
Any other URL (.mp4, .webm, etc.) → video.src directly
- All animation state in refs — no React re-renders inside the rAF loop
React.memoon LikeButton- GPU-friendly CSS (
transform,filter,opacityonly) - rAF loop only runs during active effects
- Whisper model loaded on demand and cached by the browser
- hls.js worker-based demuxing
Edit src/utils/constants.ts to change the default stream, trigger phrases, or cooldowns:
export const DEFAULT_HLS_URL = 'https://your-stream.example.com/stream.m3u8';
export const PHRASE_CONFIGS: PhraseConfig[] = [
{ pattern: 'like and subscribe', cooldownMs: 5000 },
{ pattern: 'buy now', cooldownMs: 5000 },
{ pattern: 'coffee', cooldownMs: 5000 },
{ pattern: 'hi', cooldownMs: 5000 },
{ pattern: 'hello', cooldownMs: 5000 },
];