Independent audio journal
AI & Audio Technology

How Machines Describe Sound: From Spectrograms to Audio Embeddings

Learn how spectrograms, mel frequency representations and embeddings let machine learning systems compare, classify and search audio.

7 min read
Dark studio desk with a laptop displaying abstract spectral patterns and a silver audio interface

Imagine giving a program three files: the sound of a bass drum, a man speaking a sentence and a distant thunderclap. They are all digital arrays of numbers. At a sampling rate of 48 kHz, one second of each mono file contains 48,000 measurements. The numbers alone do not arrive with labels explaining which sound is speech and which has a repeating bass pattern. The program must turn the waveform into a representation that makes its relevant differences easier to recognize.

Audio classification has used engineered features for many years. By the end of the 2010s, learned representations were becoming prominent in machine listening research, with practical uses that ranged from identifying everyday sounds to finding similar pieces of music. These methods matter to sound producers because they are increasingly present in tools that promise automatic searches, categorization and analysis. An understanding of the representation helps an engineer interpret the output of such a tool without treating a category as a description of objective truth.

Why a waveform is difficult to compare

Look at a sine wave shown on a timeline. If a second recording of the same tone begins a quarter of a cycle later, the displayed peaks happen at different positions. Comparing corresponding samples could suggest a large difference, even though a listener hears the same pitch. A musical note played twice by a human may have different onset timing, level and phase. A useful representation often reduces sensitivity to these irrelevant variations while retaining information that distinguishes a string from a flute.

Frequency analysis supplies part of the answer. A Fourier transform decomposes a segment into sinusoidal components. For an audio signal that changes over time, a short-time Fourier transform performs the analysis on overlapping blocks. Plotted as a spectrogram, time runs along one axis and frequency along the other, with brightness or color representing magnitude. A harmonic instrument produces a recognizable set of parallel bands; a click may appear as a narrow vertical line with energy across a wide range.

Choosing the analysis window introduces a tradeoff. Longer windows provide finer frequency resolution but make timing changes harder to locate. Shorter ones distinguish quick events at the expense of frequency precision, particularly at the bottom of the spectrum. The spacing of the frames, the window function and the interpretation of magnitude all matter. A useful visualization therefore depends on the task. One configuration that makes drum transients easy to see may make the fundamental of a quiet bass note less distinct.

Compressing frequency information

The ear does not resolve a one-hertz difference equally across all frequencies. A difference of ten hertz near the bottom of a musical scale is quite significant, whereas a change of that size at 8 kHz is relatively small. Mel-scale features use frequency bands spaced to approximate aspects of human pitch perception. The spectral energy within these bands is commonly summarized and converted to a logarithmic scale. The resulting time-frequency image has fewer frequency values than a full linear spectrum, making it economical for a model to process.

Mel-frequency cepstral coefficients, or MFCCs, represent aspects of the smoothed spectral envelope. They have a long history in speech analysis and can be helpful in distinguishing different sounds despite changes in the underlying pitch. The precise calculation depends on choices such as the number of filters, sampling rate and the inclusion of additional information about timing and energy. Simply describing a file as a set of MFCCs does not mean every property of its sound is retained.

There is unavoidable information loss whenever a representation discards phase or averages spectral energy. Sometimes this is exactly what a classification problem needs. For example, a search for recordings of handclaps should not require exact alignment of every clap waveform. For other jobs, such as reconstructing a particular mixture accurately, the omitted details may become a problem. Representation design is an engineering decision, not a competition to retain the largest array.

What a learned embedding represents

A neural system can be developed to convert a short audio segment into a vector, sometimes hundreds of numeric values long. Such a vector is known as an embedding. During training, the system receives examples and an objective: distinguish classes, predict another part of a signal, or associate audio with some related information. It adjusts its parameters to encode differences that help satisfy that objective. Once trained, the resulting vectors can be compared using distance measures to support similarity searches.

Embeddings do not require an individual dimension to correspond to an intuitive control such as brightness or reverberation. Their meaning may depend on many values considered together. Two sounds that are close in the embedding space may be similar in a way that matters to the training objective, yet differ in the way an engineer cares about. A sound-effects library organizer who wants alternate versions of timbres might welcome one model's grouping, while a dialogue editor wishing to distinguish speakers would need another.

Consider the problem of identifying instruments in a dense mix. A classifier trained largely on solo recordings may recognize a clean acoustic guitar but behave less consistently when the same guitar is heard beneath a vocal and drums. Some instruments share overlapping spectral characteristics. The recording microphone, room, performance style and mastering can further alter the representation. A confidence score reported by a classifier is not automatically the probability that an arbitrary input really belongs to that class.

Time frequency display and a set of compact audio feature vectors

Searching a personal sample library

A useful workflow for sound design starts by identifying the kind of similarity that matters. A collection of percussion loops might be searched by rhythmic density, tempo, sound source or spectral balance. These are separate properties. A producer looking for a kick compatible with a particular mix will often care more about the length and envelope of its low-frequency tail than whether a model groups it with other kick drums.

Scan a small subset of the library first. Use examples that vary in format, length and level. Check whether files containing silence at the beginning are treated differently from tightly trimmed clips, and whether a loop is represented by its entire duration or by several short segments. A library containing both one-shots and complete songs can produce confusing nearest-neighbor results if all files are represented using the same assumptions. Segmenting longer files can improve retrieval without altering their original audio.

Keep conventional metadata alongside any learned features. Recording date, ownership, license, sample rate, musical key and the name of the original session are valuable even if a search model does not use them. Automatic tags should be easy to correct. A local database can store tags and pointers to source files rather than renaming them based on a guess. There is little reason to sacrifice a well-understood archival system for an experimental search interface.

Training examples shape the result

When evaluating classification tools, test them with audio drawn from the actual production environment. Broadcast speech, location dialogue, clean studio narration and whispered conversation can have very different characteristics. A model intended to recognize household noises might learn clues from the recording devices and rooms in its development dataset instead of the intended sound categories. The effect becomes obvious when the same event is captured using a different microphone or from a different distance.

Comparisons require independent examples. If an hour-long recording is split into hundreds of clips before allocating material for training and evaluation, clips from the same original recording may appear in both groups. The resulting performance can look more impressive than it will be on an entirely new recording session. Grouping by source recording or contributor can reduce this overlap. For a practical buyer, the most interesting evaluation is often a small collection of personally relevant examples whose expected tags are already understood.

Where visualization helps

Use a spectrogram as a diagnostic view when automatic categorization gives unexpected results. A loop attributed to a pitched instrument might reveal a low, resonant frequency lasting through most of its duration. A supposedly quiet segment might contain narrowband interference. Even a sophisticated model cannot correct a microphone problem merely by labeling the resulting audio.

For comparisons between embeddings, a projected two-dimensional scatter plot may reveal clusters or isolated points, but the projection itself can distort distances. Inspect the actual audio in each cluster rather than assuming visible separation corresponds to a meaningful acoustic difference. An engineer may discover that the grouping follows production quality or noise rather than instrumentation. That observation leads to a better search strategy and a clearer idea of what the software is measuring.

Every representation emphasizes some aspects of audio and leaves others behind. A producer who recognizes this can use automatic analysis as a powerful index into a collection: fast, imperfect and most valuable when paired with ordinary listening.