WAV比较,相同的文件 [英] Wav comparison, same file

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

问题描述

我目前的难倒。我一直在四处寻找,并与音频比较试验。我发现相当多的材料,一吨到不同的库和方法的引用来做到这一点。

I'm currently stumped. I've been looking around and experimenting with audio comparison. I've found quite a bit of material, and a ton of references to different libraries and methods to do it.

截至目前我已经采取的无畏的并远销称为long.wav一个3分钟的WAV文件,然后的第一30秒分割成一个名为short.wav的文件。我通过Java想通某处沿线,我可以在视觉上登录(log.txt中)中的数据为每应该能够看到的值中至少有一些相似的视觉....这里的一些code

As of now I've taken Audacity and exported a 3min wav file called "long.wav" and then split the first 30seconds of that into a file called "short.wav". I figured somewhere along the line I could visually log (log.txt) the data through java for each and should be able to see at least some visual similarities among the values.... here's some code

主要方式:

        int totalFramesRead = 0;
        File fileIn = new File(filePath);
        BufferedWriter writer = new BufferedWriter(new FileWriter(outPath));
        writer.flush();
        writer.write("");
        try {
            AudioInputStream audioInputStream = 
                    AudioSystem.getAudioInputStream(fileIn);
            int bytesPerFrame = 
                    audioInputStream.getFormat().getFrameSize();
            if (bytesPerFrame == AudioSystem.NOT_SPECIFIED) {
                // some audio formats may have unspecified frame size
                // in that case we may read any amount of bytes
                bytesPerFrame = 1;
            } 
            // Set an arbitrary buffer size of 1024 frames.
            int numBytes = 1024 * bytesPerFrame; 
            byte[] audioBytes = new byte[numBytes];
            try {
                int numBytesRead = 0;
                int numFramesRead = 0;
                // Try to read numBytes bytes from the file.
                while ((numBytesRead = 
                        audioInputStream.read(audioBytes)) != -1) {
                    // Calculate the number of frames actually read.
                    numFramesRead = numBytesRead / bytesPerFrame;
                    totalFramesRead += numFramesRead;
                    // Here, do something useful with the audio data that's 
                    // now in the audioBytes array...

                    if(totalFramesRead <= 4096 * 100)
                    {                           

                    Complex[][] results = PerformFFT(audioBytes);
                    int[][] lines = GetKeyPoints(results);
                    DumpToFile(lines, writer);      

                    }   
                }
            } catch (Exception ex) { 
                // Handle the error...
            }
            audioInputStream.close();
        } catch (Exception e) {
            // Handle the error...
        }
        writer.close();

PerformFFT

public static Complex[][] PerformFFT(byte[] data) throws IOException
    {
        final int totalSize = data.length;

        int amountPossible = totalSize/Harvester.CHUNK_SIZE;

        //When turning into frequency domain we'll need complex numbers:
        Complex[][] results = new Complex[amountPossible][];

        //For all the chunks:
        for(int times = 0;times < amountPossible; times++) {
            Complex[] complex = new Complex[Harvester.CHUNK_SIZE];
            for(int i = 0;i < Harvester.CHUNK_SIZE;i++) {
                //Put the time domain data into a complex number with imaginary part as 0:
                complex[i] = new Complex(data[(times*Harvester.CHUNK_SIZE)+i], 0);
            }
            //Perform FFT analysis on the chunk:
            results[times] = FFT.fft(complex);
        }
            return results;
}

在这一点上我已经试过记录无处不在:转换,复杂的价值观和FFT结果之前audioBytes

At this point I've tried logging everywhere: audioBytes before transforms, Complex values, and FFT results.

问题:不管我记录的内容值,每个wav文件的log.txt的是完全不同的。我不理解它。鉴于我把small.wav从large.wav(他们都相同的属性)应该有任何的原始WAV字节[]数据...或者复杂的[] [] FFT数据中一个非常沉重的相似性。 ..或东西迄今..

The problem: No matter what values I log, the log.txt of each wav file is completely different. I'm not understanding it. Given that I took the small.wav from the large.wav (and they have all the same properties) there should be a very heavy similarity among either the raw wav byte[] data... or Complex[][] fft data... or something thus far..

我怎么可能尝试比较这些文件如果数据甚至还没有接近类似在这些计算中的任何一点。

How can I possibly try to compare these files if the data isn't even close to similar at any point of these calculations.

我知道我错过了不少知识与问候音频分析的,这就是为什么我来给董事会的帮助!感谢您的任何信息,帮助或修补你可以提供!

I know I'm missing quite a bit of knowledge with regards to audio analysis, and this is why I come to the board for help! Thanks for any info, help, or fixes you can offer!!

推荐答案

你有没有看 MARF ?它是用于音频识别一个证据充分的Java库。

Have you looked at MARF? It is a well-documented Java library used for audio recognition.

有用于识别扬声器(用于转录或固定软件),但相同的特征应当能够被用于音频样本进行分类。我不熟悉它,但它看起来像你想使用的<一个href=\"http://marf.sourceforge.net/docs/marf/0.3.0.6/api-dev/marf/FeatureExtraction/FeatureExtraction.html\"相对=nofollow> FeatureExtraction 类从每一个音频采样中提取一系列的功能,然后创建一个唯一的ID。

It is used to recognize speakers (for transcription or securing software) but the same features should be able to be used to classify audio samples. I'm not familiar with it but it looks like you'd want to use the FeatureExtraction class to extract an array of features from each audio sample and then create a unique id.

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

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