Before deep learning, a machine named a sound from a few hand-designed numbers per 25 ms frame and a small statistical model. On the ESC-50 benchmark that stack reached 44%. People reach 81%.
Pick a sound and press Play. Each frame becomes one dot from two features, the ring is their average, and a Gaussian for each class names the clip. Then raise the noise and watch the ring walk away. Then we build every part from zero: frames, features, MFCCs, three classifiers, a sequence model and the honest score.
You need a little Python and the idea that a sound is a list of pressure samples. We build the rest from zero.
Illustrative: your browser synthesizes the five sounds (0.4 s at 16 kHz) and 12 training clips per class the same way. The features are real: zero crossings and the centroid of a 512-point FFT of each Hann-windowed 400-sample frame. The 44% and 81% are the ESC-50 baseline and human figures (Piczak, 2015).
Chapter 0
Measure two recordings of one tone and find the tone closer to silence than to itself
A city puts a microphone on a lamppost. Your job is to raise an alarm on a scream and stay quiet for a siren, a bus or a pigeon. It is 2008. You have a laptop, a few hundred labelled clips and no pretrained model.
The first idea is template matching. Store a recorded scream as its list of samples. Call a new clip a scream if its samples are close.
Test it on the simplest sound there is. Take a pure tone sampled 8 times per cycle and call that list x. Record it again, started s samples later, and call it y. The delay is a phase angle φ = 2πs/8. How far apart are x and y?
The squared distance between x and y equals 8 times one minus cos phi.
Each copy has energy 4. Their overlap is 4 cos φ. The squared distance is 4 + 4 minus twice the overlap.
A delay of s = 2 samples gives φ = 90° and cos φ = 0. The squared distance is 8, so the distance is 2.828. Silence (all zeros) sits only 2.000 from x.
The same tone, delayed by a quarter of a cycle, is farther from itself than from nothing. At 16 kHz that delay is 0.125 ms. Slide it below. The teal bar is a distance built on two features, numbers computed from the sound: its loudness and how often it crosses zero.
Blue is the tone, grey is the delayed copy. The bars are the two distances; the dashed line is the distance to silence. Drag the delay until the raw bar crosses the line.
One cycle of 8 samples, as in the worked example. The feature distance compares RMS loudness and zero-crossing rate over a whole number of cycles, so delay leaves it at 0.
| Delay s | φ | Distance | Verdict |
|---|---|---|---|
| 1 sample | 45° | 1.531 | closer than silence |
| 1.33 samples | 60° | 2.000 | tied with silence |
| 2 samples | 90° | 2.828 | worse than silence |
| 4 samples | 180° | 4.000 | as far as it can be |
The failure. Symptom: a template matcher misses the same sound recorded twice. Measure: compute the distance between a clip and a copy shifted by one sample. Fix: describe the sound with numbers that ignore phase, length and gain. Halving the gain alone moves the copy to distance 1.000, closer than the shifted one.
Raw samples fail three ways. They change with phase, which the ear ignores. Clips have different lengths, so you cannot subtract their vectors. And 16,000 numbers per second is far too many to learn from 300 clips. The classical pipeline fixes all three in five stages.
Chapter 1
Cut the signal into short overlapping windows and count the frames, the frame rate and the frequency resolution
Average the brightness of a whole four-second clip and you mix a word, a siren sweep and a passing bus into one number. One sample alone has no brightness at all. The answer lies between, for a physical reason.
A vocal tract, a string or an engine changes shape slowly, over tens of milliseconds. So over 20 to 40 ms the spectrum of a sound stays roughly fixed. This is quasi-stationarity. We cut the signal into overlapping frames, treat each as a still photograph, and describe each one. Framing is filming: the frame length is the shutter time and the hop is the time between photographs.
| Setting | Speech value | What it controls |
|---|---|---|
| Frame length L | 25 ms = 400 samples at 16 kHz | time against frequency detail |
| Hop h | 10 ms = 160 samples | frames per second (here 100) |
| Window | Hann | tapers the edges to stop leakage |
How many frames does a clip give? Call the clip length in samples N, the frame length L and the hop h. The last frame must end inside the clip.
n-frames equals one plus the floor of N minus L, over h.
The first frame takes L samples. Each later frame starts h samples on. Count how many hops fit in the N minus L samples left, round down, and add the first frame.
A 4 s clip at 16 kHz: N = 64,000, L = 400, h = 160. (64,000 − 400) / 160 = 397.5, round down to 397, add 1: 398 frames. The array is (398, 400).
The frame length also fixes the frequency resolution: FFT bins sit sr/L apart, where sr is the sample rate. At 16,000 / 400 that is 40 Hz. Zero-padding to 512 points draws the same 40 Hz detail more smoothly. It adds no information.
The signal changes character at 0.5 s. Each purple hump is one Hann-windowed frame. Lengthen the frames and find where one frame swallows the change.
Illustrative signal at 16 kHz: a low tone, then a brighter buzz. Counts use the formula above.
The failure. Symptom: your frame count for a 4 s clip is 401, not 398. Measure: check the library call; librosa.stft pads the clip by half a frame at each end by default (center=True). Fix: pick one convention and use it for training and test.
Chapter 2
Describe a frame with a sum and a sign test, and see how a constant offset breaks one of them
Two features need no Fourier transform at all. They answer the two coarsest questions about a frame: is anything here, and is it smooth or hissy? Phone voice detectors still run them because they cost one operation per sample.
Short-time energy E is the sum of the squared samples. The RMS is the square root of E over L, and engineers report it in decibels, 10 log10(E/L). The log turns a gain change into a fixed offset: halve the gain and every frame drops 6.02 dB.
The second feature counts sign changes. Call the samples of one frame xn, for n from 0 to L − 1.
ZCR equals the count of n where the sign of x-n differs from the sign of x-n-minus-one, over L minus one.
Walk the frame one pair at a time. Count the pairs where the signal changes sign. Divide by the L minus 1 pairs. A fast wiggle gives a high ZCR.
The frame 0.1, 0.6, −0.4, −0.8, 0.2, 0.9, −0.1, −0.5 has signs + + − − + + − −: 3 changes in 7 pairs, so ZCR = 0.429. Over 7 / 16,000 s that is 6,857 crossings a second, like a 3.4 kHz tone.
The same frame has E = 2.28, RMS = √(2.28 / 8) = 0.534 and −5.45 dB. Libraries differ on ZCR: librosa divides by L and returns 0.375 for this frame. Check the convention before you compare papers.
Teal ticks mark each zero crossing. The teal dot is this frame in the (ZCR, dB) plane. Push toward noise, then lower the level, then add a DC offset.
Illustrative 400-sample frame: a 300 Hz tone mixed with white noise. Regions are rough guides, not a trained model. The ZCR here does not remove the mean, so you can see the failure.
The failure. Symptom: ZCR reads 0 on a frame that sounds normal. Measure: print the frame mean; a badly coupled preamp adds a constant offset. Fix: subtract the frame mean before counting. Add 0.9 to the worked frame and every sample is positive, so ZCR falls from 0.429 to 0.
Chapter 3
Summarise one magnitude spectrum with numbers that match the words bright, thin, changing and noisy
Energy and ZCR cannot tell a violin from a flute. Both are loud and periodic. We need to know which frequencies carry the energy. So take the FFT of the windowed frame and keep only the magnitudes, dropping phase for the reason in Chapter 0. A 400-sample frame gives 201 magnitudes, one per bin, 40 Hz apart.
The most useful summary is the balance point. Call the frequency of bin k fk and its magnitude mk.
The centroid equals the sum over k of f-k times m-k, over the sum over k of m-k.
Treat each magnitude m-k as a weight placed at its frequency f-k. Multiply, add, and divide by the total weight. The result is where the spectrum balances.
With a made-up five-bin spectrum: magnitudes 1, 3, 4, 1.5, 0.5 at 0, 2, 4, 6, 8 kHz. The top sum is 0 + 6,000 + 16,000 + 9,000 + 4,000 = 35,000. Divide by the total 10: centroid = 3,500 Hz.
Three more numbers finish the set. Each one comes from the same five bins.
| Feature | Question | Recipe | Toy value |
|---|---|---|---|
| Rolloff | where is the top? | first bin where the running total reaches 85% | 6,000 Hz |
| Flux | how fast is it changing? | distance to the previous frame’s magnitudes | 2.550 |
| Flatness | tone or noise? | geometric mean over arithmetic mean, 0 to 1 | 0.776 |
The running total is 1, 4, 8, 9.5, 10, so the total first reaches 85% of 10 at bin 3, 6 kHz. Flux uses a next frame of 1, 2, 3, 3, 2: the differences 0, −1, −1, 1.5, 1.5 give √6.5 = 2.550. Keep only the increases (3.0) and flux fires on onsets but not on decays.
Blue bars are this frame; grey outlines are the last one. The teal line is the centroid and the dashed line is the rolloff. Move brightness fast and watch flux jump.
Illustrative 24-bin spectrum from 0 to 8 kHz. The features use the recipes in the table.
The failure. Symptom: NaN in the clip’s mean centroid. Measure: find frames whose magnitudes sum to about 0; the centroid divides by that sum. Fix: skip frames below an energy threshold and add a small constant to every divisor.
Chapter 4
Warp frequency, take a log, then a cosine transform, and keep 13 numbers that describe the vowel
Centroid and rolloff cannot tell “ah” from “eh”. The vowels differ in where the spectrum’s bumps sit. Davis and Mermelstein (1980) gave the answer that ran speech recognition for thirty years: mel-frequency cepstral coefficients (MFCCs).
The vocal folds make a buzz, the source, which sets the pitch. The throat and mouth shape it, the filter, which sets the vowel. The spectrum is their product, and a log turns it into a sum. The pitch part wiggles fast across frequency and the vowel part moves slowly, so a second transform separates them.
The mel scale spaces the triangles the way the ear hears pitch. Call the frequency f and its mel value m.
m equals 2595 times log base ten of one plus f over 700.
Below 700 Hz, m grows almost in step with f. Above it, m grows with the log of f.
f = 1,000 gives m = 1,000. f = 4,000 gives 2,146 and f = 8,000 gives 2,840. The top 4 kHz span only 694 mel, so the triangles there are wide.
After the log, a discrete cosine transform (DCT) measures each cosine ripple in the log-mel shape. Call the log band energies sn, for N bands, and coefficient k ck.
c-k equals the sum over n of s-n times cos of pi k times n plus one half, over N.
For each k, lay a cosine with k half cycles across the bands. Multiply it by the log energies s-n and add.
With made-up band energies 2, 8, 4, 1, the logs are 0.693, 2.079, 1.386, 0. Then c-0 = 4.159, c-1 = 0.906 (tilted low), c-2 = −1.961 (a middle bump), c-3 = −0.375.
Why the DCT? Neighbouring mel bands move together, and the DCT nearly decorrelates them. Then a Gaussian needs one variance per dimension: 39 numbers, not the 780 of a full covariance (Chapter 6). Add the first and second time differences of the 13 to get the classic 39 per frame.
Left: 40 log-mel bands. Right: their 40 DCT coefficients, the kept ones in teal. Move the formant, then the pitch, and see which coefficients react.
Illustrative: a smooth envelope (warm curve) times a comb whose spacing stands for pitch. The DCT is the formula above with N = 40.
The failure. Symptom: your MFCCs differ from a colleague’s. Measure: check the DCT scaling (scipy with no norm doubles every value) and the mel formula (librosa defaults to the Slaney mel; this formula is htk=True). Fix: pin both.
Chapter 5
Turn a clip into one fixed vector, put every feature on the same scale, and let the nearest clips vote
A clip is now an array of shape (T, 39), and T depends on the clip’s length. A classifier wants one fixed vector. Statistics pooling takes the mean and the standard deviation of each feature over time: (78,) for any length. Four frames with ZCR 0.42, 0.30, 0.55, 0.33 pool to mean 0.400 and standard deviation 0.097.
The simplest classifier stores every labelled clip. To label a new one, it finds the k closest stored clips and lets them vote. This is k-nearest neighbours (k-NN). It has no training step, so it is the fastest test of whether your features separate the classes at all.
| Clip | ZCR | Centroid (kHz) | Label | Raw distance to Q |
|---|---|---|---|---|
| A | 0.10 | 1.5 | speech | 1.300 |
| B | 0.14 | 2.0 | speech | 0.802 |
| C | 0.05 | 3.0 | music | 0.204 |
| D | 0.07 | 3.6 | music | 0.800 |
| Q | 0.09 | 2.8 | ? |
Look inside one distance. To A, the ZCR difference squared is 0.0001 and the centroid difference squared is 1.69. The centroid is about 17,000 times louder in the sum. The distance ignores ZCR. The fix gives each feature the same scale. Call a feature’s value v, its training mean μ and its training standard deviation σ.
z equals v minus mu, over sigma.
Subtract the training mean mu from the value v. Divide by the training spread sigma. Every feature now has mean 0 and spread 1, whatever its unit.
ZCR has μ = 0.090 and σ = 0.0339, so A’s 0.10 becomes +0.295. Centroid has μ = 2.525 and σ = 0.823, so A’s 1.5 becomes −1.246. In z units the nearest clip to Q changes from C (1.204) to D (1.137).
Drag the ink ring or tap the plane. Lines join it to its k nearest clips. Turn standardizing off and watch the neighbours line up along the centroid axis.
Illustrative clips: speech (purple), music (pink) and rain (teal), 14 each, drawn from fixed Gaussians.
The failure. Symptom: test accuracy drops several points when a colleague reruns your split. Measure: check where μ and σ came from. Fix: fit them on the training clips only and reuse them on test clips; make_pipeline(StandardScaler(), ...) does this for you.
Chapter 6
Describe each class as a few weighted bells, and fit them by guessing soft memberships and refitting
k-NN memorises. A better plan describes each class as a probability density over feature space, then labels a new clip by asking which density scores it highest. From about 1990 to 2012, every speech recognizer did this with Gaussian mixtures (GMMs).
One Gaussian is one bell with a mean and a variance. A class like “dog” holds yaps and woofs, two lumps, and one bell would put its peak in the empty valley. So use K bells, each with a weight πk, a mean μk and a variance σk2. The catch: nobody tells us which bell made which point. The EM algorithm guesses that softly, then refits.
The guess is Bayes’ rule. Call data point n xn and the bell-shaped density N(x | μ, σ2).
r-n-k equals pi-k times N of x-n given mu-k and sigma-k squared, over the sum over j of the same thing for bell j.
For point x-n, multiply each bell’s weight pi-k by its height at the point. Divide each product by their total. That is the E-step. The M-step refits each mean, variance and weight with every point counted r-n-k times.
With made-up points 2, 3, 8, 9, start with μ = 4 and 7, σ2 = 4, π = 0.5. At x = 2 the heights are in the ratio e−0.5 : e−3.125 = 0.607 : 0.044. So r = 0.9325 and 0.0675.
Finish the step by hand. The responsibilities for bell 1 are 0.9325, 0.8670, 0.1330, 0.0675. They sum to 2.000.
The means moved out toward the clusters. Run to the end and they reach 2.5 and 8.5 with variance 0.25. EM never lowers the log-likelihood, the log of how probable the data is under the model. It can stop on a poor peak, so real systems start from k-means.
Each point blends purple and pink by its responsibilities. Press E-step, then M-step. Then set the start gap to 0 and press Run.
The toy set is the worked example; gap 3 starts the means at 4 and 7. The 40-point set is illustrative. A variance floor of 0.05 stops collapse.
The failure. Symptom: training reports an absurdly good likelihood. Measure: print the smallest variance; one bell has shrunk onto a single point, and its height runs to infinity. Fix: a variance floor (reg_covar in scikit-learn) and restarts.
Chapter 7
Choose the boundary with the widest empty corridor, and reach a large feature space without building it
A GMM models what each class looks like. If you only need the answer, model the boundary. Many straight lines split two separable classes with zero training error. The support vector machine (SVM) picks the one with the widest empty corridor, the margin, because features are noisy and a wide corridor tolerates noise.
The classifier is f(x) = w · x + b, where w is a weight vector and b an offset; it says +1 when f(x) > 0. Real classes overlap, so the SVM lets points violate the corridor at a price. Call the label of clip i yi, +1 or −1, and the price per unit of violation C.
Minimize one half the squared length of w, plus C times the sum over i of the max of zero and one minus y-i times f of x-i.
Charge for a narrow corridor through the length of w. Charge C for every unit a clip falls short of its side. Pick the w and b with the smallest total charge.
With made-up points (3, 3) labelled +1 and (1, 1) labelled −1, take w = (0.5, 0.5) and b = −2. Then f = +1 and −1, so both hinges are 0. ‖w‖ = 0.707 and the margin is 2.828, the whole gap. A clip with f = 0.4 pays 0.6; one with f = −0.3 pays 1.3.
Only clips on or inside the corridor change w. They are the support vectors. The solution touches the data only through dot products. So you can swap in a kernel K(u, v) that equals a dot product in a bigger space.
The cheap side never builds φ. The RBF kernel exp(−γ‖u − v‖2) goes further: for these vectors and γ = 0.5 it gives e−2.5 = 0.082. Its knob γ sets how far one support vector reaches.
The pale band is the corridor. Ringed points are support vectors. Switch to RBF and push γ up until the regions break into islands.
Illustrative standardized 2-D data, 14 clips per class, trained in your browser by simplified SMO on the dual problem.
The failure. Symptom: training accuracy 100%, test near chance. Measure: count support vectors; near every clip means memorising. Fix: grid-search C and γ under cross-validation, and standardize first, because the RBF distance is the unit bug of Chapter 5 again.
Chapter 8
Add a prior that sounds continue, and score a whole sequence by sharing work across paths
Classify each 10 ms frame alone and the labels flicker: speech, speech, music, speech. No real sound switches 100 times a second. A hidden Markov model (HMM) fixes this. A hidden state moves from frame to frame by a transition probability, and each state emits what we observe. In speech, each emission model was a GMM from Chapter 6.
| State | Start | To S | To M | Emits H | Emits L |
|---|---|---|---|---|---|
| S (speech) | 0.6 | 0.7 | 0.3 | 0.8 | 0.2 |
| M (music) | 0.4 | 0.4 | 0.6 | 0.3 | 0.7 |
H means high ZCR and L means low. We observe H, L, L. How likely is that under the model? Any of 23 = 8 state paths could make it, and for 100 frames with 3 states there are 3100, about 5 × 1047.
The forward pass shares work. Call αt(j) the chance of the first t observations with state j at time t. Call aij the chance of moving from i to j. Call bj(ot) the chance that j emits observation ot.
Alpha-t of j equals the sum over i of alpha-t-minus-one of i times a-i-j, all times b-j of o-t.
To be in state j now, you came from some state i. Multiply each old alpha by its move chance a-i-j and add them. Then multiply by the chance b-j that j shows what you observed. Repeat for each frame. The sum of the last alphas is the sequence chance.
Start: α1(S) = 0.6 × 0.8 = 0.48 and α1(M) = 0.4 × 0.3 = 0.12. Next, after L: α2(S) = (0.48 × 0.7 + 0.12 × 0.4) × 0.2 = 0.0768, and α2(M) = (0.48 × 0.3 + 0.12 × 0.6) × 0.7 = 0.1512. One L flipped the belief to music.
One more step gives α3 = 0.022848 and 0.079632, so P(H, L, L) = 0.10248. Adding all 8 paths gives the same number. Swap the sum for a max and keep pointers, and you get the Viterbi path: S, M, M, with chance 0.042336, only 41% of the total.
Each column is a frame; each node holds α. Press Step to send α along the edges, then apply the emission. Raise the stay-chance and see one odd frame stop flipping the belief.
The model in the table. The stay chance sets S to S; M to M is 0.6 shifted by the same amount. At 0.70 the numbers match the worked example.
The failure. Symptom: the forward pass returns exactly 0 on a long clip. Measure: 1,000 frames at about 0.1 each gives 10−1000, below the smallest double (about 10−308). Fix: work in logs with log-sum-exp, or rescale α every frame and add up the log scale factors.
Chapter 9
Trace one clip from 64,000 numbers to 78, score it honestly, and see what pooling throws away
| Stage | Shape | What it throws away |
|---|---|---|
| Waveform, 4 s at 16 kHz | (64000,) | nothing yet |
| Frames, 25 ms / 10 ms | (398, 400) | nothing; overlap adds copies |
| Magnitude spectrum | (398, 201) | phase |
| Mel bands, log, DCT, keep 13 | (398, 13) | fine detail and pitch |
| Plus deltas | (398, 39) | nothing; adds motion |
| Mean and std pooling | (78,) | time order, all of it |
Mean and standard deviation do not care about order. Shuffle a clip’s frames and the pooled vector stays bit for bit the same. So a siren rising and the same siren falling are one input. This is the bag of frames assumption. HMMs were the classical way around it.
Top: the centroid of each frame over time. Below: the pooled mean and standard deviation, and the response of one small diagonal filter that a CNN could learn. Switch the order.
Illustrative 32-frame siren from 0.8 to 2.4 kHz. The filter is a slope detector: the mean sign of each frame-to-frame change.
Honest scoring matters as much as the model. ESC-50 (Piczak, 2015) has 2,000 five-second clips in 50 classes, 40 each, in 5 fixed folds. UrbanSound8K (Salamon et al., 2014) has 8,732 slices of up to 4 s in 10 classes and 10 fixed folds. Both cut several clips from one recording, so a random split lets the model learn a recording’s background hum. Use the fixed folds.
Accuracy can also lie. A detector tested on 80 background, 15 alarm and 5 glass-break clips gets 72, 3 and 0 right: 75% accuracy. The per-class recalls are 0.90, 0.20 and 0. Their mean, the balanced accuracy, is 36.7%. On a balanced set like ESC-50, plain accuracy is fair.
| System on ESC-50 | Accuracy |
|---|---|
| k-NN on pooled MFCC and ZCR | 32.2% |
| SVM, same features | 39.6% |
| Random forest, same features | 44.3% |
| Human listeners | 81.3% |
| CNN on log-mel (Piczak, 2015) | 64.5% |
| PANNs CNN14, fine-tuned (2020) | 94.7% |
| Audio Spectrogram Transformer (2021) | 95.6% |
The best hand-feature system reached 44% where people reach 81%. In music the gap was smaller: Tzanetakis and Cook (2002) classified ten genres at 61% with timbre, rhythm and pitch features. Where hand features match the task, the classical stack competes.
Four things stopped it. Only the classifier learned; every feature was fixed in advance. MFCCs drop pitch and high detail, which non-speech sounds need. No stage could see a 2-D time-frequency shape such as a chirp. And it had no way to use more data, such as AudioSet’s two million clips (2017).
The failure. Symptom: 60% on ESC-50 with MFCCs and an SVM. Measure: check the split; clips from one source file sit in train and test. Fix: GroupKFold on the official folds. Expect the high 30s to mid 40s.
Chapter 10
Keep the terms, numbers, checks and the whole pipeline in one place
A classical audio classifier frames the sound at 25 ms and 10 ms. It describes each frame with energy, ZCR, spectral shape and 13 MFCCs. It pools mean and spread over time, standardizes, and hands one vector to k-NN, a GMM or an SVM. An HMM puts order back when order matters.
| Term | What it is | Number on this page |
|---|---|---|
| Frame count | 1 + ⌊(N − L) / h⌋ | 398 for 4 s at 16 kHz |
| Bin spacing | sr / L | 40 Hz |
| ZCR | sign changes / (L − 1) | 3/7 = 0.429 |
| Centroid | Σ f m / Σ m | 3,500 Hz on the toy |
| Mel | 2595 log10(1 + f / 700) | 8 kHz = 2,840 mel |
| MFCC | DCT of log mel energies, keep 13 | 4.159, 0.906, −1.961, −0.375 |
| z-score | (v − μ) / σ, fit on train | nearest changes C to D |
| EM step | responsibilities, then weighted refit | means 4, 7 → 3.069, 7.931 |
| SVM margin | 2 / ‖w‖ | 2.828 |
| Forward pass | αt(j) = [Σ αt−1(i) aij] bj(ot) | P(H, L, L) = 0.10248 |
center), mel variant and DCT scaling.pythonimport numpy as np, librosa, glob, os from sklearn.pipeline import make_pipeline from sklearn.preprocessing import StandardScaler from sklearn.svm import SVC from sklearn.model_selection import GroupKFold, cross_val_score SR, N_FFT, HOP = 16000, 400, 160 # ch 1: 25 ms frames, 10 ms hop def clip_features(path): x, _ = librosa.load(path, sr=SR) # (n_samples,) mf = librosa.feature.mfcc(y=x, sr=SR, n_mfcc=13, n_fft=N_FFT, hop_length=HOP) # ch 4: (13, T) d1, d2 = librosa.feature.delta(mf), librosa.feature.delta(mf, order=2) zcr = librosa.feature.zero_crossing_rate(x, frame_length=N_FFT, hop_length=HOP) # ch 2 cen = librosa.feature.spectral_centroid(y=x, sr=SR, n_fft=N_FFT, hop_length=HOP) # ch 3 F = np.vstack([mf, d1, d2, zcr, cen / SR]) # (41, T) return np.concatenate([F.mean(1), F.std(1)]) # ch 5: (82,) files = sorted(glob.glob('ESC-50/audio/*.wav')) # names: fold-source-take-class.wav X = np.stack([clip_features(f) for f in files]) y = np.array([int(os.path.basename(f)[:-4].split('-')[3]) for f in files]) folds = np.array([int(os.path.basename(f).split('-')[0]) for f in files]) clf = make_pipeline(StandardScaler(), SVC(kernel='rbf', C=10)) # ch 5, ch 7 print(cross_val_score(clf, X, y, groups=folds, cv=GroupKFold(5)).mean()) # ch 9: official folds
The front end in full is in Audio Representations. EE269: Cepstrum and MFCC derives the cepstrum, and EE269: The DFT the DFT. HMMs get their own lesson in Hidden Markov Models; the same recursion runs in the Bayes filter. EM gets a full treatment in EM and GMMs, SVMs in EE269: SVM. The moment a network replaced the GMM is in DNN-GMM-HMM Hybrids.
Acoustic Scene Classification · PANNs · AST · Self-Supervised Speech · BEATs · CLAP · Whisper
Sources: Piczak, “ESC: Dataset for Environmental Sound Classification” (ACM MM 2015) and the ESC-50 repository; Salamon, Jacoby and Bello, UrbanSound8K (ACM MM 2014); Kong et al., PANNs; Gong et al., AST; Davis and Mermelstein (1980); Tzanetakis and Cook (2002). All toy numbers are illustrative and checked by script.
Now press Present or Teach and explain from memory: why raw samples fail, what the 13 MFCCs keep, how one EM step moves the means, and why pooling cannot hear a siren reversed. Then go back to the hero, pick Speech, and find the noise level where the verdict flips.