Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello friend....

I need to match two audio files and it should return how much it matches......
please help me....i am trying to do this in c# .net............

i recording the audio file using MCI.
Posted

C#
function compareAudio(){
var audio1 = "Source1Path";
var audio2 = "Source2Path";
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+' %.');
 
Share this answer
 
Quote:
create a File-Compare function in Visual C#


ASM
Create a new Visual C# Windows Application project. By default, Form1 is created.
Add two textbox controls to the form.
Add a command button to the form.
On the View menu, click Code.
Add the following USING statement to the Form1 class:

using System.IO;


Add the following method to the Form1 class:



// This method accepts two strings the represent two files to
// compare. A return value of 0 indicates that the contents of the files
// are the same. A return value of any other value indicates that the
// files are not the same.
private bool FileCompare(string file1, string file2)
{
     int file1byte;
     int file2byte;
     FileStream fs1;
     FileStream fs2;

     // Determine if the same file was referenced two times.
     if (file1 == file2)
     {
          // Return true to indicate that the files are the same.
          return true;
     }

     // Open the two files.
     fs1 = new FileStream(file1, FileMode.Open);
     fs2 = new FileStream(file2, FileMode.Open);

     // Check the file sizes. If they are not the same, the files
        // are not the same.
     if (fs1.Length != fs2.Length)
     {
          // Close the file
          fs1.Close();
          fs2.Close();

          // Return false to indicate files are different
          return false;
     }

     // Read and compare a byte from each file until either a
     // non-matching set of bytes is found or until the end of
     // file1 is reached.
     do
     {
          // Read one byte from each file.
          file1byte = fs1.ReadByte();
          file2byte = fs2.ReadByte();
     }
     while ((file1byte == file2byte) && (file1byte != -1));

     // Close the files.
     fs1.Close();
     fs2.Close();

     // Return the success of the comparison. "file1byte" is
     // equal to "file2byte" at this point only if the files are
        // the same.
     return ((file1byte - file2byte) == 0);
}


Paste the following code in the Click event of the command button:

private void button1_Click(object sender, System.EventArgs e)
{
   // Compare the two files that referenced in the textbox controls.
   if (FileCompare(this.textBox1.Text, this.textBox2.Text))
      {
         MessageBox.Show("Files are equal.");
      }
   else
      {
         MessageBox.Show("Files are not equal.");
      }
}


Save and then run the sample.
Supply the full paths to the two files in the textboxes, and then click the command button.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900