java - Wav 比较,相同的文件

标签 java audio comparison fft wav

我目前感到困惑。我一直在环顾四周并尝试音频比较。我找到了相当多的 Material ,以及大量对不同库和方法的引用资料。

截至目前,我已经使用 Audacity 并导出了一个名为“long.wav”的 3 分钟 wav 文件,然后将其前 30 秒拆分为一个名为“short.wav”的文件。我发现沿线的某个地方我可以通过 java 为每个数据直观地记录 (log.txt) 数据,并且至少应该能够看到值之间的一些视觉相似性....这是一些代码

主要方法:

        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();

然后执行FFT:

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;
}

此时我已经尝试在所有地方记录日志:转换前的 audioBytes、复数值和 FFT 结果。

问题:无论我记录什么值,每个wav文件的log.txt都是完全不同的。我不明白。鉴于我从 large.wav 中取出了 small.wav(并且它们具有所有相同的属性),原始 wav byte[] 数据...或 Complex[][] fft 数据之间应该有非常大的相似性。 .. 或者到目前为止..

如果在这些计算的任何一点上数据都不接近相似,我怎么可能尝试比较这些文件。

我知道我缺少很多关于音频分析的知识,这就是我来董事会寻求帮助的原因!感谢您提供的任何信息、帮助或修复!!

最佳答案

你看过MARF了吗? ?它是一个用于音频识别的文档齐全的 Java 库。

它用于识别说话者(用于转录或保护软件),但相同的功能应该能够用于对音频样本进行分类。我不熟悉它,但看起来你想使用 FeatureExtraction类从每个音频样本中提取一组特征,然后创建一个唯一的 ID。

关于java - Wav 比较,相同的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11604518/

相关文章:

python - 具有相对频率或密度曲线的计数图

python - Python 中的字符串相等失败。是什么赋予了?

Java inputstreamreader 解析为 int 然后反转数组并打印为格式化字符串

java - 如何对 map 集合的层次键进行排序?

java - 如何在 Java 中打印对齐列中的字符串?

android - 带有Android Media Player的DSP(数字声音处理)

java - Ignite Spring Data 支持 Spring Boot 2 吗?

javascript - 如何通过函数获取 audio.duration 值

java - java中的平滑音量变化

c++ - C/C++ : Float comparison speed