TIMBRE
INSTRUMENT LAB v2.1
KNN • cosine • k=3 — readyAnalyze →
NEWEXPLAINABLE AUDIO INTELLIGENCE • IRMAS 11K+
Identify instruments
in any audio —
with proof.
Upload a clip & get a 26-dimensional spectral fingerprint (13 MFCCs + Δ, Chroma, Centroid, Rolloff, ZCR, Bandwidth, Flatness, RMS…) classified by K-Nearest Neighbours with cosine similarity. Every prediction is explainable: radar, probabilities, waveform & CSV export.
Accuracy
61.9%
±0.92% 5-fold CV
Precision
62.05%
macro avg
Classes
11
IRMAS family
Features
26-D
DSP vector
Model card — KNN-Cosine
K=3 • DIST-WEIGHTEDDistance
Cosine
Scaler
StandardScaler
Hop
1024
SR
22.05kHz
Window
Hanning 2048
Max
30s clip
Class balance3724 samples
Saxophone
626
Flute
447
Cello
388
Organ
356
Violin
330
Elec. Guitar
308
Clarinet
269
Piano
250
Acoustic Gtr
250
Voice
250
Trumpet
250
Trained on IRMAS • Evaluated with 5-Fold Stratified CV — no black box. See pipeline.
Analyze — drop audio here or click to browse
WAV • MP3 • OGG • FLAC • M4A
Click to browse or drag & drop
Auto-converts to mono 22.05kHz • Max 30s • Hanning 2048 • hop 1024
Choose file
MFCC 1-13
timbre texture
Chroma + Centroid
harmonic & brightness
ZCR • Flatness • RMS
percussive & energy
Browser mic → direct 26-D extraction (no upload)
Mic uses WebAudio decode • same pipelineNo file yet — try the demo board or drop an audio file above
Uploads never leave your browser in Vercel mode. Python backend is optional for exact librosa parity.
Flask API optionalClient-side KNN identicalExplainable by design
Demo soundboard — tap to audition synthetic timbres
11 classes • WebAudioThese are procedurally synthesized previews (not IRMAS). Upload real audio for true inference.
Pipeline — 4 stages from raw signal to explainable prediction
01Step 01
Upload Audio
Drag & drop WAV/MP3/OGG/FLAC/M4A ≤30s. Auto mono-22.05kHz conversion, Hanning 2048.
mono22.05kHz30s max
02Step 02
Feature Extraction
Librosa DSP → 26-D fingerprint: 13 MFCC, Δ, Chroma, Centroid, Rolloff, ZCR, Bandwidth, Flatness, RMS…
MFCC 13ChromaSpectral
03Step 03
Normalize & Classify
StandardScaler (fit on 3724) → KNN K=3 cosine distance, distance-weighted vote.
K=3CosineWeighted
04Step 04
Explain Results
Radar (input vs DB avg), all-class bars, waveform, 26-D table, CSV export.
RadarBarsCSV
Model performance — 5-Fold Stratified CV
Accuracy
61.9% ±0.92%
Precision
62.05%
Recall
61.9%
F1
61.73%
K-tuning (grid search)
K=1 Euclidean
57.2%
K=3 Cosine ★
61.9%
K=5 Cosine
60.4%
K=7 Manhattan
58.1%
K=11 Cosine
55.8%
Confusion drivers (from evaluation)
Best: Saxophone (626 samples) — distinctive reed harmonics.
Hardest: Violin vs Cello and Acoustic vs Electric Guitar — overlapping MFCC space.
Voice is well-separated via formant variance (MFCC var).
Hardest: Violin vs Cello and Acoustic vs Electric Guitar — overlapping MFCC space.
Voice is well-separated via formant variance (MFCC var).
Files & features
SR 22050 Hz • mono
Hop 1024 • Win 2048
Hanning • 40 mel
DCT-II → 13 MFCC
Backend training script:
ml/train.py reproduces this table.Recent history (local)
No analyses yet — your runs will appear here.
Stored in localStorage • 12 max • CSV export per run above.
API documentation — Flask + Next.js dual stack
POST /api/analyze200 JSON
Request — multipart/form-data
curl -X POST http://localhost:5000/analyze \ -F "audioFile=@sample.wav" # Vercel (Next API, no Python needed) curl -X POST /api/analyze \ -F "audio=@sample.mp3"
Response
{
"instrument": "Piano",
"confidence_score": 87.34,
"knn_probabilities": [
{"name":"Piano","score":87.34}, {"name":"Organ","score":5.21}
],
"feature_vector": [26 floats],
"compared_vector": [26 floats],
"waveform": {"time":[1000], "amplitude":[1000]}
}GET /health & /model/info
GET /health → {"status":"ok","model_ready":true}GET /model/info → {"k":3,"metric":"cosine","scaler":"StandardScaler", "accuracy":61.9,"samples":3724}Vercel deployment
- Frontend auto-deploys (Next.js). No Python required — inference runs in browser via audioFeatures.ts.
- Optional Python backend on Render/Railway: set
NEXT_PUBLIC_API_URL. - Or use Vercel Python functions:
api/index.py(FLASK) is included.
PORT
5000
FLASK_DEBUG
true
CORS
*
ML note: Backend uses librosa 0.10 for exact 26-D extraction; frontend approximates with a hand-rolled FFT + mel-filterbank so the demo works offline. Cosine KNN is identical.