比较wav文件并返回匹配 [英] compare wav files and return the match

查看:89
本文介绍了比较wav文件并返回匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友....



我需要匹配两个音频文件,它应该返回多少匹配......

请帮帮我....我想在c#.net中做这件事............



i录音使用MCI的音频文件。

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.

推荐答案

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+' %.');


引用:

在Visual C中创建文件比较函数#

create a File-Compare function in Visual C#







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.


这篇关于比较wav文件并返回匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆