Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare two audio files [duplicate]

Tags:

python

audio

mp3

Basically, I have a lot of audio files representing the same song. However, some of them are worse quality than the original, and some are edited to where they do not match the original song anymore. What I'd like to do is programmatically compare these audio files to the original and see which ones match up with that song, regardless of quality. A direct comparison would obviously not work because the quality of the files varies.

I believe this could be done by analyzing the structure of the songs and comparing to the original, but I know nothing about audio engineering so that doesn't help me much. All the songs are of the same format (MP3). Also, I'm using Python, so if there are bindings for it, that would be fantastic; if not, something for the JVM or even a native library would be fine as well, as long as it runs on Linux and I can figure out how to use it.

like image 812
Sasha Chedygov Avatar asked Jul 03 '10 21:07

Sasha Chedygov


People also ask

What is Audio Dedupe?

Audio Dedupe is an innovative tool that can recognize duplicate audio files even if they are stored in different file formats and are not marked with ID3 tags. Audio Dedupe will help you to find fast all similar or exact duplicate audio files in a folder and its subfolders.

Can I combine two audio files?

When you need to merge several songs into a single composition, the easiest way is to use our Online Audio Joiner application. It works in a browser window and you can join MP3 and other format files without installing the software on your computer. Open Online Audio Joiner website.


1 Answers

This is actually not a trivial task. I do not think any off-the-shelf library can do it. Here is a possible approach:

  1. Decode mp3 to PCM.
  2. Ensure that PCM data has specific sample rate, which you choose beforehand (e.g. 16KHz). You'll need to resample songs that have different sample rate. High sample rate is not required since you need a fuzzy comparison anyway, but too low sample rate will lose too much details.
  3. Normalize PCM data (i.e. find maximum sample value and rescale all samples so that sample with largest amplitude uses entire dynamic range of data format, e.g. if sample format is signed 16 bit, then after normalization max. amplitude sample should have value 32767 or -32767).
  4. Split audio data into frames of fixed number of samples (e.g.: 1000 samples per frame).
  5. Convert each frame to spectrum domain (FFT).
  6. Calculate correlation between sequences of frames representing two songs. If correllation is greater than a certain threshold, assume the songs are the same.

Python libraries:

  • PyMedia (for step 1)
  • NumPy (for data processing) -- also see this article for some introductory info

An additional complication. Your songs may have a different length of silence at the beginning. So to avoid false negatives, you may need an additional step:

3.1. Scan PCM data from the beginning, until sound energy exceeds predefined threshold. (E.g. calculate RMS with a sliding window of 10 samples and stop when it exceeds 1% of dynamic range). Then discard all data until this point.

like image 137
atzz Avatar answered Oct 04 '22 03:10

atzz