# How to compare two audio files?

I have two recorded audio voice WAV files I have recorded by saying "Good Morning" twice.

I want to compare the two audio files and say both are identical.

How can I do that?
What is the right approach to achieve this?

-
Are you saying they are exact duplicates of each other (like literally copy/paste) or just determine it is the same words or same person? –  Kellenjb Oct 27 '10 at 5:48
How sensitive do you want the comparison to be? File comparison is easy, but voice recognition - not so much. –  Tim Oct 27 '10 at 5:50
Its not exact copy past of audio files,to determine same words.even it can be different person –  Warrior Oct 27 '10 at 5:52
There are a few different ways that the files could be identical. They could be binary equal, including the headers. They could be the same audio data, but in different formats with different headers. They could be the same waveform, but sampled differently. They could be the same words spoken by different people. For all of these cases, I think the question belongs on stackoverflow.com, not here. –  endolith Oct 27 '10 at 14:08
Note: this site is primarily for questions related to embedded development, like solving this problem with a microcontroller connected to a voice recognition chip or a dedicated DSP. The algorithm to determine if the two "files" are similar, or you want to do this strictly in software, this is a question best asked on stackoverflow. But if you want to get ideas on how to implement this in a quasi-hardware based way, this is a good place. –  J. Polfer Oct 27 '10 at 23:08

I do agree with the comments about how this question is very difficult to answer in this community, but I would like to provide a few of the more simple methods for you to look into. Ultimately a good and robust system will require the use of many different techniques and many many hours. This is why there is tons and tons of money put into voice recognition, and as you may know, still isn't great.

In general, people will speak within about the same frequency range every time they say a command word. If you look at the frequency domain of your signal, you can record what range was used when the person recorded their command word and then look for that in the future. You can get to the frequency domain using the FFT, wikipedia and some google search can help you with what this means and how to do it.

You can expand the frequency method to determine what the frequency is for each part of the word. For example, some people will raise the pitch of their voice as they finish a word. This could be another "signature" to look at.

Also people will generally speak the same speed for the same command word. For this you can look at amplitude of your signal to determine how long it took them to say each word and even the pause between two words. Then you can compare these pauses to your future signal.

Again, these are just a few basic methods, but should get you a sense of the type of things that can be done.

-

Try search for AI methods on Audio processing, and possibly wavelets. Also use Matlab to develop your algorithms first before try to code it within an application.

-

See some example open source code: http://wiki.musicbrainz.org/AudioFingerprint

It's a non-trivial problem.

-

You could look at integrating a voice recognition module into your project.

But I guess it depends on what results your after, IMO speech recognition is still pretty basic, one of the first issues is differentiating ambient sound from vocal commands - the best current solution is when the person issuing commands has been close mic'ed with a kinda Madonna style headset.

Ah....it brings back memories of my first Macbook, I spent the first week or so shouting "Mac.......What time is it!" just for it to turn around and reply ".....opening safari" - or some other unrelated operation.

-
@Joby - dude that's funny, not seen that image in a long time! –  Jim Oct 27 '10 at 11:43

I am using one javascript function for compare tow audio file. By using the same logic you are able to compare any file in any language.

function compireAudio(){
var audio1 = "http://soundjax.com/reddo/86502%5Ealarm.mp3";
var audio2 = "http://soundjax.com/reddo/44368%5EALARME.mp3";
var i,j,d;
var matching = 0;
var t = 0;var i,j,d;
var matching = 0;
var t = 0;
var audio1Arr = Array();
var audio1Len = audio1.length;
for (i = 1; i<=audio1Len; i++)
{
//reverse so its like a stack
d = audio1.charCodeAt(audio1Len-i);
for (j = 0; j < 8; j++)
{
audio1Arr.push(d%2);
d = Math.floor(d/2);
}
}
var audio2Len = audio2.length;
for (i = 1; i<=audio2Len; i++)
{
//reverse so its like a stack
d = audio2.charCodeAt(audio2Len-i);
for (j = 0; j < 8; j++)
{
if(d%2 == audio1Arr[t])
{
matching++;
}
d = Math.floor(d/2);
t++;
}
}
var avarage = Number(matching)/((Number(t)+Number(audio1Arr.length))/Number(2))*Number(100);
alert('The Matching with the two audio is '+avarage+' %.');


}

-
Thanks for the answer! Could you add a bit of description about the code, possibly some theory? –  clabacchio May 24 '12 at 12:56
This code measures what percentage of the bits match up in each file, using a very roundabout and inefficient algorithm. Unfortunately, this is completely useless in the context of the question. –  Dave Tweed Oct 20 '12 at 0:09
Where is it actually loading the files? At a first glance, I would say that it is comparing the file URLs... –  Ale Sep 18 at 22:26