Here is one second of sound as a computer first receives it:
0.0012, 0.0031, 0.0047, 0.0052, 0.0038, 0.0009, −0.0024, …
and so on for 16,000 numbers. Each is the air pressure at the microphone at one instant, measured sixteen thousand times a second. Somewhere in that list is a dog barking. This article follows the list through the stages that let a program find it.
Stage one: sampling
Sound is a continuous change in pressure. To store it, we measure at regular intervals and keep the measurements. The number of measurements per second is the sample rate.
One rule governs the choice. To capture a frequency, you must sample at more than twice that frequency. Sample too slowly and high tones are not merely lost; they reappear disguised as lower ones, an effect called aliasing. Human hearing reaches about 20,000 hertz, which is why music is commonly stored at 44,100 samples a second. Speech carries most of its information below 8,000 hertz, so 16,000 is the usual rate for recognition.
Stage two: why the raw wave is awkward
One could feed those 16,000 numbers straight into a learning algorithm, and some modern systems do. But the raw wave is an inconvenient description.
Record the same bark twice and the two lists will share almost no values. Shift a recording by a thousandth of a second and every number changes. What makes a bark a bark is not in the individual pressures. It is in which frequencies are present and how they change over a few tenths of a second.
Our own ears work on that principle. The inner ear is a frequency analyser: different positions along it respond to different pitches. The brain receives something much closer to a moving chart of frequencies than to a list of pressures.
Stage three: frames and the Fourier transform
So we convert. Cut the signal into short overlapping frames, typically 25 milliseconds long and starting every 10 milliseconds. Within so short a slice, the sound is roughly steady.
Each frame then goes through the Fourier transform. The idea behind it is that any wave can be described as a sum of pure tones of different frequencies and strengths. The transform takes the 400 pressure values of one frame and returns how much of each frequency is present.
Before transforming, each frame is multiplied by a smooth curve that fades it in and out. Without this, the abrupt edges of the slice would themselves register as frequencies that were never in the sound.
There is an unavoidable trade-off here. A longer frame separates neighbouring frequencies more finely but blurs when things happened. A shorter one does the opposite. No setting gives both, and 25 milliseconds is a compromise that suits speech.
Stage four: the spectrogram
Stand the results for successive frames side by side and you have a picture. Time runs left to right. Frequency runs bottom to top. Brightness shows how much energy is present at that frequency at that moment.
This is a spectrogram, and it is the most useful picture in audio. In it a whistle is a thin line that rises and falls. A vowel is a stack of horizontal bands, a clap a vertical stripe, a bark a short, broad smear with harmonics above it. People who work with them learn to read words from them by eye.
Stage five: bending it towards the ear
Two adjustments make the picture more like what we hear.
First, pitch. We perceive the step from 100 to 200 hertz as large and the step from 8,000 to 8,100 as nothing. So the frequency axis is squeezed, keeping detail at the bottom and merging it at the top. The usual scale for this is the mel scale, and the result is a mel spectrogram, often with forty to eighty bands in place of several hundred.
Second, loudness. We also hear loudness in ratios, so the energies are converted to a logarithmic scale, as decibels are.
One second of sound has gone from 16,000 pressure values to an image of about 100 columns by 64 rows. It is smaller, far more stable from one recording to the next, and organised the way hearing is.
Stage six: a network that looks at pictures
Recognising a sound has now become recognising a pattern in an image, and there are well-developed tools for that.
A convolutional neural network slides small filters across the picture. In the early layers, the filters come to respond to simple things: an edge, a rising streak, a horizontal band. Later layers respond to combinations: a stack of bands that begins abruptly and decays. The final layer outputs a score for each category it was trained on.
Nobody writes the filters. The network starts with random ones and is shown thousands of labelled examples: this picture is a dog, this is a doorbell, this is rain. After each, its numbers are nudged in whatever direction would have made its answer slightly more right. Over many passes, useful filters emerge.
Speech recognition extends the same idea to sequences, producing a stream of sounds or letters, with a language model helping to choose between candidates that sound alike. Newer systems use transformer networks and are often trained first on enormous quantities of unlabelled audio, learning to predict hidden portions of it, before being refined on a smaller labelled set.
Where it goes wrong
The microphone and the room. A model trained on clean studio recordings often fails on a phone in a kitchen. Echo, background noise and cheap microphones change the spectrogram a great deal. The standard remedy is to train on deliberately degraded audio: add noise, add reverberation, shift the pitch, stretch the time.
Shortcuts. If every recording of the dog was made outdoors and every recording of the doorbell indoors, a network may learn to distinguish outdoors from indoors. It will score perfectly in testing and be useless. Always check what a model is really responding to, and test on recordings made somewhere else, by someone else.
Overlap. The spectrogram of two sounds at once is roughly the two pictures laid over each other. A bark during traffic is much harder than a bark alone.
What was not in the training data. A system trained mainly on some accents recognises others worse. A bird classifier trained in one region is unreliable in another. The model's world is its examples.
Confidence. Most classifiers will pick one of the categories they know, even for a sound that belongs to none of them.
Trying it yourself
Any free audio editor will display a spectrogram. Record yourself saying a few words and look. Whistle a rising note. Clap. It takes about ten minutes for the picture to start making sense, and after that the rest of the chain is easier to believe.
For the next step, open-source libraries in Python will compute a mel spectrogram in a couple of lines, and public datasets of everyday sounds are free to download. A small network that tells ten kinds of sound apart can be trained on an ordinary laptop in an evening.
The whole chain is six steps long: pressure, samples, frames, frequencies, a picture, a pattern. The complicated part is the amount of data needed to train the last step well.



