Skip to content

Repository files navigation

Audio Analyzer

A powerful iOS and watchOS app for real-time audio analysis using the device microphone.

🎵 iOS App: Full-featured audio analysis with BPM, key detection, SPL meter, and Shazam integration
Apple Watch App: Optimized companion app with BPM monitoring, SPL meter, haptic feedback, and complications

Features

iOS App Features

  • BPM Detection: Real-time tempo detection using autocorrelation and onset detection

    • Circular waveform visualization with animated beat pulse
    • Gradient ring animations synchronized to detected tempo
    • Range: 60-200 BPM with 0.1 BPM precision
  • Key Detection: Musical key identification using chromagram analysis and Krumhansl-Schmuckler algorithm

    • Interactive chromagram wheel showing all 12 pitch classes
    • Real-time pitch energy visualization
    • Detects 24 keys (12 major + 12 minor)
  • SPL Meter: Sound Pressure Level measurement with visual indicators and safety warnings

    • Real-time frequency spectrum bars (64 bands)
    • Animated waveform visualization
    • Color-coded safety levels with threshold markers
    • Range: 0-120 dB with danger warnings at 85+ dB
  • Shazam Integration: Music recognition powered by ShazamKit

    • Real-time song identification from microphone audio
    • Album artwork display with song/artist info
    • Direct links to Apple Music and Shazam
    • Toggle on/off with animated listening indicator
    • Genre information and metadata

Apple Watch App Features

  • BPM Monitor: Real-time tempo detection optimized for Watch

    • Large, readable display perfect for workouts
    • Haptic feedback on each detected beat
    • Mini waveform visualization
    • Swipe-based navigation between views
  • Key Detection: Simplified musical key identification

    • Large text display showing detected key (e.g., C, A♯m)
    • Color-coded: Pink for major, Purple for minor
    • Animated background and note indicators
    • Less frequent updates (every 3s) for battery optimization
  • SPL Meter: Sound level monitoring on your wrist

    • Circular gauge with color-coded levels
    • Instant visual feedback (green → yellow → orange → red)
    • Safety warnings for dangerous sound levels
    • Perfect for monitoring noise exposure throughout the day
  • Watch Complications: Quick glance data on your watch face

    • BPM complication (Circular, Corner, Rectangular)
    • SPL complication (Circular, Corner, Rectangular)
    • Always-on display support
    • Updates in real-time when app is active
  • Haptic Feedback: Feel the beat

    • Gentle tap on wrist for each detected beat
    • Helps maintain rhythm without looking at screen
    • Perfect for musicians and DJs

Modern UI Design

  • Glassmorphic cards with gradient borders and shadows
  • Real-time visualizations for all three analysis features
  • Smooth animations with spring physics and easing
  • Color-coded feedback (blue/cyan for BPM, purple/pink for Key, green→red for SPL)
  • Large navigation bar with floating control button
  • Recording indicator with pulsing animation
  • Responsive layout optimized for iOS devices

Technology Stack

  • SwiftUI: Modern, declarative UI framework
  • AVFoundation: Core audio capture and processing
  • Accelerate: Apple's optimized DSP and FFT functions
  • ShazamKit: Apple's music recognition framework
  • Custom Shape paths for circular and waveform visualizations
  • Native Swift implementation (no Python dependencies)

Project Structure

AudioAnalyzer/
├── Sources/
│   └── AudioAnalyzer/
│       ├── AudioAnalyzerApp.swift     # App entry point
│       ├── ContentView.swift          # Main view with modern UI
│       ├── Services/
│       │   ├── AudioEngine.swift      # Audio capture & processing + viz data
│       │   ├── BPMDetector.swift      # Tempo detection
│       │   ├── KeyDetector.swift      # Musical key detection + chromagram
│       │   └── SPLMeter.swift         # Sound level measurement
│       ├── Views/
│       │   ├── BPMView.swift          # BPM card with visualization
│       │   ├── KeyView.swift          # Key card with chromagram wheel
│       │   ├── SPLMeterView.swift     # SPL card with spectrum
│       │   ├── ShazamResultView.swift # Shazam card with song info
│       │   └── Visualizations/
│       │       ├── BPMVisualization.swift      # Circular waveform + pulse
│       │       ├── KeyVisualization.swift      # Chromagram wheel
│       │       └── SPLVisualization.swift      # Frequency bars + waveform
│       ├── Models/
│       │   └── ShazamResult.swift     # Song metadata model
│       └── Utilities/                 # (Future: helpers)
├── Tests/
│   └── AudioAnalyzerTests/
├── Info.plist                         # Privacy permissions
├── Package.swift                      # SPM configuration
└── README.md

Getting Started

Requirements

  • iOS 17.0+ / watchOS 10.0+
  • Xcode 15.0+
  • Device with microphone (simulator has limited audio support)

Setup

  1. Open in Xcode:

    open AudioAnalyzer/Package.swift
  2. Set up Xcode Project:

    • Create a new iOS App project in Xcode
    • Add the Swift files from Sources/AudioAnalyzer/ to your project
    • Copy Info.plist content to your project's Info.plist
    • Ensure microphone permission is configured
  3. Build and Run:

    • Select your target device
    • Build and run (⌘R)
    • Grant microphone permission when prompted

Using Swift Package Manager

Add to your Package.swift:

dependencies: [
    .package(url: "path/to/AudioAnalyzer", from: "1.0.0")
]

Usage

iOS App

  1. Launch the app - Permission prompt will appear for microphone access
  2. Tap the play button (top right) to start audio analysis
  3. View real-time metrics:
    • BPM: Displays detected tempo with visual pulse indicator
    • Key: Shows detected musical key (e.g., C, A♯m)
    • SPL: Shows sound level in dB with color-coded safety warnings
    • Shazam: Toggle on to identify songs playing nearby

Apple Watch App

  1. Launch the Watch app - Swipe between four views:
    • BPM View: Large tempo display with haptic beat feedback
    • Key View: Musical key with animated background
    • SPL View: Circular gauge showing sound levels
    • Controls View: Start/stop recording and quick stats
  2. Add complications to your watch face:
    • Long press your watch face → Edit → Add Complication
    • Select "Audio Analyzer" for BPM or SPL
  3. Feel the beat - Haptic taps sync with detected tempo

Technical Details

BPM Detection

  • Uses energy envelope extraction with RMS windowing
  • Autocorrelation to find periodicity
  • Valid range: 60-200 BPM
  • Updates every 1.5 seconds

Key Detection

  • FFT-based chromagram calculation
  • Krumhansl-Schmuckler key-finding algorithm
  • Tests all 24 keys (12 major + 12 minor)
  • Updates every 2 seconds

SPL Meter

  • RMS amplitude calculation
  • Reference: 20 micropascals
  • Range: 0-120 dB
  • Optional A-weighting for perceptual accuracy
  • Real-time updates (sub-second)

Safety Levels

  • Quiet (0-40 dB): Safe
  • Moderate (40-70 dB): Comfortable
  • Loud (70-85 dB): Extended exposure caution
  • Very Loud (85-100 dB): Hearing damage risk
  • Dangerous (100+ dB): Immediate risk

Future Enhancements

Planned Features

  • Tempo tap input for manual BPM
  • Tuner with pitch detection
  • Metronome with configurable haptic patterns
  • Recording and playback
  • History tracking and data export
  • Workout integration (Apple Health)
  • iPhone ↔ Watch sync via WatchConnectivity
  • Chord detection beyond single keys
  • SPL meter calibration per device
  • Background audio processing
  • Siri shortcuts and voice control

Optimization Ideas

  • Implement AudioKit for enhanced DSP
  • Add Core ML for improved key detection accuracy
  • Use Metal for GPU-accelerated FFT
  • Implement background audio processing
  • Add Siri shortcuts integration

Privacy

This app requires microphone access to function. Audio is processed locally on-device and is not recorded or stored. All analysis happens in real-time.

Shazam Integration: When music recognition is enabled, audio fingerprints are sent to Apple's Shazam service to identify songs. No raw audio is transmitted—only acoustic signatures. See Apple's ShazamKit Privacy for details.

License

MIT License - See LICENSE file for details

Contributing

Contributions welcome! Please feel free to submit issues or pull requests.

Acknowledgments

  • Krumhansl-Schmuckler Algorithm: Key detection algorithm
  • Apple Accelerate Framework: Optimized DSP functions
  • AVFoundation: Audio capture infrastructure

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages