views:

1743

answers:

4

Is there any way to programatically compare two sound files to determine if they are identical, or nearly identical? These are not mp3 files and do not have any ID3 or other meta data, but plain wav files. Comparing the checksum values may not work as they may not be completely identical.

+1  A: 

You could compare the two WAV files sample-by-sample, and calculate an average per-sample difference. To speed things up, you could use the same method but compare every 10th sample, or every 100th sample and come up with essentially the same value (two files that aren't the same or even close will have a huge per-sample average difference).

MusiGenesis
this doesn't work if one file has 1 second of silence added to the front of it, but are otherwise identical.
rmeador
You need to do add pattern recognition then, and try to align them temporally before you check the samples
Eran Galperin
I agree with both points, but that takes this problem from the realm of the simple to the realm of the hideously complex.
MusiGenesis
A: 

One thing that you could try that would give you a fairly decent fingerprint of the file is taking a Fourier transform and looking at the distribution of different frequencies present in the file. It's still very possible to make two very different sound files that have the same Fourier transform, but that's somewhat unlikely if your files are coming from a non-contrived source...

rmeador
+3  A: 

The wikipedia article on acoustic fingerprinting mentions a number of products, including the opensource libfooid. Basically you're looking at going into the frequency domain, taking rough levels over a relatively small number of bands (say 32), to give you a string that represents something like 25ms of sound, doing that for the whole file, then doing a fuzzing comparison of those strings for different files. It's fairly complex, but needs doing - comparing the actual samples won't get you anywhere as something as simple as a volume shift by a few percent will throw out the whole match.

U62
Good link. OQ seemed to suggest that the files could be identical or nearly so, which indicated that sample-by-sample comparison could work.
MusiGenesis
A: 

The process for comparing a set of sounds for similarities is called Content Based Audio Indexing, Retrieval, and Fingerprinting in computer science research.

One method of doing this is to:

1) Run several bits of signal processing on each audio file to extract features, such as pitch over time, frequency spectrum, autocorrelation, dynamic range, transients, etc.

2) Put all the features for each audio file into a multi-dimensional array and dump each multi-dimensional array into a database

3) Use optimization techniques (such as gradient descent) to find the best match for a given audio file in your database of multi-dimensional data.

The trick to making this work well is which features

There are several projects that do stuff like this, including MusicBrainz, and EchoNest.

Echonest has one of the simplest APIs I've seen in this space. Very easy to get started.

P.S. No I do not work for Echonest, nor do I know anyone who works there.

Nick Haddad