This is a "buildless" web application that performs real-time audio analysis directly in the browser. It uses the Web Audio API to capture microphone input, visualizes the frequency spectrum on an HTML Canvas, and implements the Harmonic Product Spectrum (HPS) algorithm for robust musical pitch detection.
This project is built with a modular, scalable architecture, separating the UI, application logic, and core DSP (Digital Signal Processing) utilities.
(https://swarsaga.netlify.app/)
- Real-Time Spectrum Analyzer: A smooth, live visualization of the audio frequency spectrum.
- Accurate Pitch Detection: Uses the Harmonic Product Spectrum (HPS) algorithm, which is more robust against noise and overtones than simple peak detection.
- Musical Note Display: Converts the detected frequency into the closest musical note (e.g.,
C#4). - Precision Tuner: Shows tuning deviation in "cents" (e.g.,
-10.5cents flat or+8.2cents sharp) with color-coded feedback (Red/Flat, Yellow/Sharp, Green/In-Tune). - Secure & Serverless: Uses Firebase for anonymous user authentication.
- Zero Dependencies: A "buildless" project that requires no
npm installor build step.
- Frontend: HTML5, CSS3, JavaScript (ES6 Modules)
- Core Audio: Web Audio API (
AudioContext,AnalyserNode) - Styling: Tailwind CSS (via CDN)
- Backend: Firebase (for Anonymous Authentication)
- Algorithm: Harmonic Product Spectrum (HPS) for pitch detection.
To run this project, you must connect it to your own Firebase project for authentication.
- Go to the Firebase Console.
- Create a new project.
- Register a new Web App (click the
</>icon). - Give it a nickname (e.g., "Audio Analyzer") and register the app.
- Firebase will show you a
firebaseConfigobject. Copy this object.
-
Open the
firebase-config.jsfile. -
Paste your
firebaseConfigobject, replacing the placeholder values:const firebaseConfig = { apiKey: "YOUR_API_KEY", authDomain: "YOUR_AUTH_DOMAIN", projectId: "YOUR_PROJECT_ID", storageBucket: "YOUR_STORAGE_BUCKET", messagingSenderId: "YOUR_MESSAGING_SENDER_ID", appId: "YOUR_APP_ID" };
- In your Firebase project dashboard, go to Authentication.
- Click the Sign-in method tab.
- Find "Anonymous" in the list, click it, and Enable it.
This project is a static site and can be deployed for free in seconds.
You can use any static site host. The easiest are:
- GitHub Pages:
- Go to your repo's Settings > Pages.
- Deploy from the
mainbranch and the/ (root)folder.
- Netlify:
- Sign up with your GitHub account.
- Import your repository.
- Click "Deploy". (Leave all build settings blank).
THIS STEP IS CRITICAL. Your app will not work until you do this.
- Go back to your Firebase project's Authentication section.
- Click the Settings tab.
- Go to the "Authorized domains" list.
- Click "Add domain".
- Add the domain of your live site (e.g.,
your-username.github.iooryour-app-name.netlify.app).
- Open your live website URL.
- Click the "Start Analysis" button.
- Your browser will ask for microphone permission. Click "Allow".
- Sing, hum, or play an instrument into your microphone.
- Watch the analyzer display the live spectrum, detected note, and tuning information.
- Click "Stop Analysis" to turn off the microphone.
/
├── 📄 index.html
│ └── The main HTML structure, UI elements, and script links.
├── 🎨 styles.css
│ └── Custom styles that complement Tailwind CSS.
├── 🚀 app.js
│ └── The main application "brain." Handles DOM, event listeners,
│ and the Web Audio API setup. Manages the animation loop.
├── 🎵 audio-utils.js
│ └── All core DSP logic. Contains the pure functions for pitch
│ detection (HPS), frequency-to-note conversion, and canvas drawing.
└── 🔥 firebase-config.js
└── Handles Firebase initialization and anonymous authentication.