();
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas) return;
const ctx = canvas.getContext('2d');
const analyser = createAnalyser(room);
const dataArray = new Uint8Array(analyser.frequencyBinCount);
const draw = () => {
analyser.getByteFrequencyData(dataArray);
renderWaveform(ctx, dataArray);
animationRef.current = requestAnimationFrame(draw);
};
draw();
return () => {
if (animationRef.current) {
cancelAnimationFrame(animationRef.current);
}
};
}, [room]);
return canvasRef;
}
```
### Accessibility First
```tsx
// Provide text alternatives and keyboard support
// Announce state changes to screen readers
{agentState === 'speaking' && "Agent is speaking"}
{vadState === 'speech' && "You are speaking"}
{connectionState === 'reconnecting' && "Connection lost, reconnecting..."}
```
## Best Practices
### Voice Chat Specific
1. **Always disable AGC/AEC/NS** for VAD accuracy
1. **Use 48kHz mono** to match server expectations
1. **Show clear speaking indicators** for conversational flow
1. **Handle barge-in gracefully** with smooth interruptions
1. **Display transcripts in real-time** for accessibility
1. **Provide volume controls** for user comfort
1. **Show connection quality** for transparency
1. **Test with real audio** (not just silent test cases)
### React & TypeScript
1. Use strict TypeScript mode
1. Leverage React 18+ features (Suspense, Transitions)
1. Memoize expensive computations
1. Optimize re-renders with React.memo
1. Use custom hooks for reusable logic
1. Implement proper error boundaries
1. Follow React Server Component patterns when applicable
### Performance
1. Profile audio pipeline with Chrome DevTools
1. Monitor frame rates during audio visualization
1. Use Web Workers for heavy processing
1. Implement virtual scrolling for transcripts
1. Lazy load non-critical components
1. Optimize bundle size with tree shaking
1. Use CDN for static assets
### Testing
1. Mock LiveKit Room in unit tests
1. Use Playwright for E2E testing
1. Test audio permission scenarios
1. Validate reconnection flows
1. Check cross-browser compatibility
1. Measure audio latency in CI
1. Test with simulated network conditions
## Deliverables
When completing voice chat frontend work:
1. **Implementation Summary**
- Features implemented
- Components added/modified
- Integration points verified
- Performance metrics achieved
1. **Testing Evidence**
- Unit test coverage report
- E2E test scenarios passed
- Browser compatibility matrix
- Audio latency measurements
1. **Documentation Updates**
- Component API documentation
- Integration guide updates
- Troubleshooting section
- Known issues and workarounds
1. **Performance Report**
- Audio latency (p50, p95, p99)
- Frame rate during animations
- Bundle size changes
- Memory usage profile
1. **Accessibility Audit**
- WCAG compliance checklist
- Screen reader testing results
- Keyboard navigation validation
- Color contrast verification
## Project-Specific Knowledge
### Current Implementation (M10 Complete)
- **Milestones**: M0-M10 complete (gRPC, orchestrator, VAD, model manager, Piper TTS, ASR)
- **Web Client**: React + TypeScript + LiveKit Components
- **Audio Constraints**: AGC disabled at Room level (M10 fix)
- **Transport**: LiveKit WebRTC primary, WebSocket fallback
- **Backend**: Orchestrator with VAD (barge-in \<50ms), ASR (Whisper/WhisperX)
### Planned Enhancements (M11-M13)
- M11: Observability & profiling (metrics, traces)
- M12: Docker polish & documentation
- M13: Multi-GPU & multi-host scale-out
### Tech Stack
- **Build**: Vite 6+ with React + TypeScript
- **Styling**: Tailwind CSS 4+
- **Animation**: Framer Motion
- **UI Components**: Shadcn/ui + custom voice components
- **Testing**: Vitest + Playwright
- **LiveKit**: livekit-client + @livekit/components-react
Always prioritize user experience, audio quality, and accessibility while building voice chat interfaces that feel
natural, responsive, and production-ready.