Skip to content

michielhdoteth/ThereminCam

Repository files navigation

🎵 Web Theremin

A browser-based theremin synthesizer controlled by hand gestures using webcam and computer vision. Play music with your hands in the air! Experience the magic of the theremin - the world's first electronic musical instrument - in your browser.

Build Status License Bundle Size TypeScript Vite Tone.js

📖 Table of Contents

✨ Features

🎹 Core Functionality

  • Gesture Control: Use right hand for pitch, left hand for volume
  • Real-time Audio: Professional Web Audio API synthesis with multiple waveforms
  • Visual Feedback: Live frequency, volume, and FPS display with pitch visualization
  • Customizable Settings: Adjustable pitch/volume ranges, smoothing, and presets
  • Zero Installation: Runs entirely in your browser, no plugins required
  • Responsive Design: Works on desktop and tablet devices
  • Performance Monitoring: Built-in FPS tracking and optimization

🎛️ Advanced Features

  • Multiple Waveforms: Sine, sawtooth, square, and triangle waves
  • Smoothing Controls: Adjustable gesture smoothing for clean performance
  • Preset System: Quick configurations for different playing styles
  • Hold Function: Freeze current note with spacebar
  • Settings Panel: Advanced controls accessible via keyboard shortcut
  • Error Handling: Graceful fallbacks for camera and audio issues

🎨 User Experience

  • Intuitive Interface: Clean, modern design with clear visual feedback
  • Accessibility: Keyboard shortcuts and screen reader support
  • Mobile Friendly: Responsive design for tablet use
  • Performance Warnings: Visual indicators for low FPS or tracking issues

🎯 Demo

Experience the Web Theremin live:

What You'll Experience

  • Immediate Response: Low-latency hand tracking and audio synthesis
  • Musical Expression: Full control over pitch and volume dynamics
  • Visual Learning: Real-time frequency and volume displays
  • Creative Freedom: Experiment with different waveforms and settings

🚀 Quick Start

Prerequisites

  • Browser: Chrome 122+, Edge 122+, or Firefox 124+
  • Webcam: Any webcam for hand tracking (720p+ recommended)
  • Node.js: 16+ for development (optional for users)
  • Audio Output: Speakers or headphones

For Users

  1. Visit the live demo at https://web-theremin.vercel.app
  2. Allow camera access when prompted
  3. Click "Start Theremin" and begin playing!

For Developers

  1. Clone the repository:

    git clone https://github.com/d00merog/web-theremin.git
    cd web-theremin
  2. Install dependencies:

    npm install
  3. Start development server:

    npm run dev
  4. Open in browser: Navigate to http://localhost:5173

  5. Allow camera access when prompted

  6. Click "Start Theremin" and start playing!

🎮 How to Play

Basic Controls

  • Right Hand: Move up/down to control pitch (frequency)
  • Left Hand: Move up/down to control volume (amplitude)
  • Both Hands: Use together for expressive performance

Hand Positioning

Camera View:
┌─────────────────┐
│    🖐️ Right     │  ← Pitch Control
│     Hand        │
│                 │
│    🖐️ Left      │  ← Volume Control
│     Hand        │
└─────────────────┘

Keyboard Shortcuts

Key Action Description
Fist Gesture Hold current note Freeze pitch and volume
H Toggle settings panel Access advanced controls
Escape Stop theremin Return to start screen
R Reset settings Return to default configuration

Settings Panel

Press H to access advanced controls:

Pitch Range

  • Min Freq: 32-220 Hz (C1-A3)
  • Max Freq: 440-2000 Hz (A4-C7)
  • Default: C2 (65.4 Hz) to C6 (1047 Hz)

Volume Range

  • Min Vol: -60 to -10 dB (quietest level)
  • Max Vol: -20 to 0 dB (loudest level)
  • Default: -40 dB to -6 dB

Waveform Selection

  • Sine: Smooth, pure tone (default)
  • Sawtooth: Bright, buzzy sound
  • Square: Digital, hollow sound
  • Triangle: Mellow, flute-like tone

Smoothing

  • 0.05: Very responsive, may be jittery
  • 0.2: Balanced (default)
  • 0.5: Very smooth, less responsive

Presets

Preset Frequency Range Waveform Use Case
Default C2-C6 Sine General playing
Deep C1-C4 Triangle Bass tones
Bright C3-C7 Sawtooth Lead melodies
Classical A2-A5 Sine Traditional theremin
Experimental C0-C8 Square Electronic music

🛠️ Development

Project Structure

web-theremin/
├── src/
│   ├── lib/
│   │   ├── theremin.ts       # Audio engine using Tone.js
│   │   └── tracking.ts       # MediaPipe hand tracking
│   ├── components/
│   │   ├── overlay.ts        # HUD and visual feedback
│   │   └── settings.ts       # Settings panel
│   ├── test/
│   │   ├── theremin.test.ts  # Unit tests for audio engine
│   │   └── overlay.test.ts   # UI component tests
│   └── main.ts              # Application entry point
├── public/
│   ├── index.html           # Main HTML file
│   └── favicon.ico          # Site icon
├── docs/                    # Documentation
├── dist/                    # Production build
├── package.json             # Dependencies and scripts
├── vite.config.ts          # Build configuration
├── tailwind.config.js      # CSS framework config
├── tsconfig.json           # TypeScript configuration
└── README.md               # This file

Technology Stack

Technology Version Purpose
TypeScript 5.2+ Type-safe JavaScript
Vite 4.5+ Fast build tool and dev server
Tone.js 14.7+ Web Audio API wrapper
MediaPipe 0.10+ Hand tracking and computer vision
WebGPU 1.0+ GPU-accelerated graphics and computation
Tailwind CSS 3.4+ Utility-first CSS framework
Vitest 0.34+ Unit testing framework
PostCSS 8.4+ CSS processing

Available Scripts

# Development
npm run dev          # Start dev server with hot reload
npm run build        # Build for production
npm run preview      # Preview production build

# Testing
npm run test         # Run tests in watch mode
npm run test:run     # Run tests once
npm run test:ui      # Open test UI

# Quality Assurance
npm run lint         # Check code style
npm run type-check   # TypeScript checking
npm run format       # Format code with Prettier

Development Workflow

  1. Fork and clone the repository
  2. Install dependencies with npm install
  3. Start development with npm run dev
  4. Write tests for new features
  5. Run tests with npm run test
  6. Build for production with npm run build
  7. Submit a pull request

Code Quality Standards

  • TypeScript: Strict mode enabled
  • ESLint: Code style enforcement
  • Prettier: Code formatting
  • Vitest: Unit and integration tests
  • Bundle Size: Keep under 110KB gzipped
  • Update documentation for new features
  • Follow the existing code style

Commit Message Format

type(scope): description

[optional body]

[optional footer]

Examples:

  • feat(audio): add new waveform option
  • fix(tracking): resolve hand detection issues
  • docs(readme): update installation instructions

Code of Conduct

This project follows the Contributor Covenant Code of Conduct. By participating, you are expected to uphold this code.

📚 Documentation

User Documentation

Developer Documentation

Video Tutorials

🎵 Performance

Target Specifications

Metric Target Current
Latency ≤120ms end-to-end (p95) ~100ms
Frame Rate ≥30 FPS hand tracking 30-60 FPS
Bundle Size ≤103KB gzipped ~98KB
Memory Usage ≤50MB ~35MB
CPU Usage ≤15% on modern hardware ~10%

Browser Support

Feature Chrome Edge Firefox Safari
Web Audio API ✅ 122+ ✅ 122+ ✅ 124+ ⚠️ 15+
MediaPipe Hands
getUserMedia
Canvas API
ES6 Modules

Optimization Features

  • Exponential Smoothing: Reduces gesture jitter
  • Performance Monitoring: Visual FPS warnings
  • Efficient Rendering: Canvas-based hand visualization
  • Memory Management: Proper cleanup of audio resources
  • Lazy Loading: Load MediaPipe only when needed
  • Bundle Splitting: Separate vendor and app code

🔧 Configuration

Audio Engine Options

new ThereminEngine({
  minFreq: 65.41,      // Minimum frequency (Hz) - C2
  maxFreq: 1046.50,    // Maximum frequency (Hz) - C6
  minVol: -40,         // Minimum volume (dB)
  maxVol: -6,          // Maximum volume (dB)
  waveform: 'sine',    // Oscillator waveform
  smoothing: 0.2,      // EMA smoothing factor
  attack: 0.1,         // Volume attack time (seconds)
  release: 0.3,        // Volume release time (seconds)
});

Hand Tracking Options

HandLandmarker.createFromOptions(vision, {
  runningMode: 'VIDEO',
  numHands: 2,                    // Track up to 2 hands
  minHandDetectionConfidence: 0.5, // Minimum detection confidence
  minHandPresenceConfidence: 0.5,  // Minimum presence confidence
  minTrackingConfidence: 0.5,      // Minimum tracking confidence
});

Performance Tuning

// For low-end devices
const lowEndConfig = {
  smoothing: 0.3,     // More smoothing
  minFreq: 110,       // Higher minimum frequency
  maxFreq: 880,       // Lower maximum frequency
  frameRate: 15,      // Lower frame rate
};

// For high-end devices
const highEndConfig = {
  smoothing: 0.1,     // Less smoothing
  minFreq: 32,        // Lower minimum frequency
  maxFreq: 2000,      // Higher maximum frequency
  frameRate: 60,      // Higher frame rate
};

🎯 Tips for Best Performance

Camera Setup

  • Lighting: Use good lighting, avoid backlighting
  • Background: Plain background improves tracking
  • Distance: Sit 2-3 feet from camera
  • Position: Center hands in camera view
  • Resolution: 720p or higher recommended

Playing Techniques

  • Smooth Movements: Avoid jerky motions for clean sound
  • Hand Separation: Keep hands apart for clear tracking
  • Finger Position: Extend fingers for better detection
  • Practice: Start with slow movements, build up speed
  • Breathing: Use natural breathing rhythm for expression

Musical Practice

  • Scales: Practice major and minor scales
  • Intervals: Work on octaves, fifths, fourths
  • Vibrato: Small oscillating hand movements
  • Glissando: Smooth pitch slides
  • Dynamics: Coordinate both hands for expression

Technical Optimization

  • Browser: Use Chrome or Edge for best performance
  • Tabs: Close unnecessary browser tabs
  • Applications: Close other audio/video applications
  • Hardware: Use dedicated graphics if available
  • Network: Wired connection for web-based versions

🐛 Troubleshooting

Common Issues

Camera Problems

Camera not working:

  • Check browser permissions
  • Refresh page and try again
  • Ensure camera isn't used by another app
  • Try different browser

No hand detection:

  • Improve lighting conditions
  • Move closer to camera
  • Check hand position in frame
  • Try different hand gestures

Performance Issues

Low FPS (red warning):

  • Close other browser tabs
  • Check system resources
  • Try lower camera resolution
  • Restart browser

Audio latency:

  • Use Chrome/Edge for best performance
  • Close unnecessary applications
  • Use wired headphones
  • Check audio drivers

Audio Problems

No sound:

  • Check if theremin is started
  • Verify browser audio isn't muted
  • Try different waveform settings
  • Check hand tracking is working

Distortion or clicks:

  • Lower max volume setting
  • Increase smoothing
  • Check audio hardware
  • Try different browser

Browser-Specific Issues

Browser Known Issues Solutions
Chrome None Best performance
Edge None Excellent performance
Firefox Occasional audio glitches Update to latest version
Safari No MediaPipe support Use Chrome/Edge
Mobile Limited performance Use desktop version

Performance Diagnostics

The application includes built-in diagnostics:

  • FPS Counter: Shows hand tracking frame rate
  • Status Indicator: Current application state
  • Error Messages: Clear feedback for issues
  • Performance Warnings: Visual alerts for problems

🤝 Contributing

We welcome contributions from the community! Here's how you can help:

Ways to Contribute

  • 🐛 Bug Reports: Report issues with detailed information
  • 💡 Feature Requests: Suggest new features or improvements
  • 📝 Documentation: Improve docs and add examples
  • 🎨 UI/UX: Enhance the user interface
  • ⚡ Performance: Optimize code and reduce bundle size
  • 🧪 Testing: Add tests and improve test coverage
  • 🌐 Localization: Add translations for different languages

Development Setup

  1. Fork the repository
  2. Clone your fork: git clone https://github.com/your-username/web-theremin.git
  3. Install dependencies: npm install
  4. Create a feature branch: git checkout -b feature/amazing-feature
  5. Make your changes
  6. Test your changes: npm run test
  7. Commit changes: git commit -m 'Add amazing feature'
  8. Push to branch: git push origin feature/amazing-feature
  9. Open a Pull Request

Development Guidelines

  • Write tests for new features
  • Follow TypeScript strict mode
  • Use semantic commit messages
  • Ensure bundle size stays under 110KB
  • Update documentation for new features
  • Follow the existing code style

Commit Message Format

type(scope): description

[optional body]

[optional footer]

Examples:

  • feat(audio): add new waveform option
  • fix(tracking): resolve hand detection issues
  • docs(readme): update installation instructions

Code of Conduct

This project follows the Contributor Covenant Code of Conduct. By participating, you are expected to uphold this code.

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

License Summary

  • Commercial Use: ✅ Allowed
  • Modification: ✅ Allowed
  • Distribution: ✅ Allowed
  • Private Use: ✅ Allowed
  • Liability: ❌ No warranty provided
  • Warranty: ❌ No warranty provided

🙏 Acknowledgments

Core Technologies

  • MediaPipe team for hand tracking technology
  • Tone.js community for Web Audio abstractions
  • Theremin inventors for the original inspiration
  • Web Audio API specification contributors

Open Source Libraries

  • Vite for fast development and building
  • Tailwind CSS for utility-first styling
  • Vitest for modern testing framework
  • TypeScript for type safety

Community

  • Early testers and feedback providers
  • Music educators for educational insights
  • Theremin enthusiasts for historical context
  • Web developers for technical guidance

Historical Context

  • Léon Theremin (1896-1993) - Inventor of the theremin
  • Clara Rockmore (1911-1998) - Virtuoso theremin performer
  • Robert Moog (1934-2005) - Theremin kit manufacturer

🔗 Links

Project Links

Documentation

Related Projects

Social Media


🎵 Made with ♥️ for music and technology enthusiasts

Experience the magic of the theremin - the world's first electronic musical instrument - in your browser. No installation required, just pure musical expression through hand gestures.

About

Create real-time music through ThereminCam the gesture theremin: intuitive, visual, and fully browser-based.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors