Abstract
In this paper, we focus on the problem of content-based retrieval for audio, which aims to retrieve all semantically similar audio recordings for a given audio clip query. This problem is similar to the problem of query by example of audio, which aims to retrieve media samples from a database, which are similar to the user-provided example. We propose a novel approach which encodes the audio into a vector representation using Siamese Neural Networks. The goal is to obtain an encoding similar for files belonging to the same audio class, thus allowing retrieval of semantically similar audio. Using simple similarity measures such as those based on simple euclidean distance and cosine similarity we show that these representations can be very effectively used for retrieving recordings similar in audio content.
Introduction
The challenge of content-based audio retrieval lies in bridging the gap between exact audio fingerprinting and semantic similarity. While systems like Shazam excel at identifying a specific recording, they often fail to retrieve semantically related sounds—such as different instances of a siren or various recordings of a cough. Humans naturally group these sounds together based on their acoustic properties and meaning. This research proposes a method to learn compact, 128-dimensional embeddings that capture these semantic relationships, enabling the retrieval of varied but related audio clips from diverse and noisy environments.
Methodology
The core of the proposed system is a Siamese Neural Network (SNN). This architecture utilizes two identical subnetworks with shared weights to process pairs of audio inputs.
Network Architecture and Training
Each subnetwork is a multi-layer perceptron (MLP) consisting of three layers with 512, 256, and 128 neurons, respectively. The input to the network is a log-frequency spectrogram of a 2-second audio clip, flattened into a 13,509-dimensional vector.
The network is trained using a contrastive loss function. This function is designed to minimize the Euclidean distance between embeddings of audio clips from the same semantic class while maximizing the distance (up to a defined margin) for clips from different classes. Once trained, the network serves as a feature extractor, mapping any audio clip to a 128-dimensional vector.
Dataset
To evaluate the system in real-world conditions, a dataset of 76 sound event classes was compiled from ESC-50, US8K, and TUT 2016 benchmarks. To increase diversity and noise levels, 100 recordings per class were sourced from YouTube, totaling approximately 7,600 files. This dataset presents significant challenges due to high intra-class variation and environmental noise.
Experimental Results
The effectiveness of the learned representations was evaluated using Mean Precision at 1 ($MP^1$) and Top-K retrieval metrics.
Retrieval Performance
The model achieved an overall $MP^1$ between 0.3 and 0.4, indicating that the first retrieved result is semantically correct in 30-40% of cases. Performance varied significantly across classes; for instance, "Sheep" and "Pig" showed high precision (0.753 and 0.724, respectively). Interestingly, Euclidean distance was found to be a more effective similarity measure than Cosine similarity, likely because the contrastive loss function directly optimizes for Euclidean distances during training.
Embedding Visualization
To verify the semantic quality of the embeddings, the high-dimensional vectors were projected into 2D space using t-SNE.
The visualization confirms that the network learns to group similar sounds (e.g., "Clock Tick" or "Brushing Teeth") into distinct clusters, effectively creating a "semantic fingerprint" for different audio events.
Conclusion
This work demonstrates that Siamese Neural Networks can effectively learn content-based representations for audio retrieval. By mapping complex spectrograms to compact 128-dimensional embeddings, the system enables efficient semantic search. Future work will focus on resolving label ambiguities between datasets—such as "Dog bark" vs. "Dog sound"—to further improve retrieval accuracy and robustness.
Summary updated