You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于FFT的语音文件cross-correlation匹配实现异常求助

语音文件互相关相似性匹配异常问题

我需要用互相关(cross-correlation)比较两个语音文件的相似性,目前已经完成了带静音段去除的录音工具,也实现了FFT可以获取幅值和峰值频率。参考公式自行实现了互相关逻辑,但运行后结果完全不符合预期。

互相关核心实现代码

private int intersection(File file1, File file2) {
    int intersections = 0;
    try {
        Complex[] Sfft = getFFT(file1);
        Complex[] Tfft = getFFT(file2);
        for (int i = 0; i < Tfft.length; i++) {
            Tfft[i] = Tfft[i].conjugate();
        }
        Complex[] correlation = new Complex[Sfft.length];
        for (int i = 0; i < correlation.length; i++) {
            correlation[i] = Sfft[i].times(Tfft[i]);
        }
        FFT.ifft(correlation);
        intersections = CrossCorrelation.argmax(correlation);
        System.out.println(correlation.length);
    } catch (UnsupportedAudioFileException | IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return intersections;
}

辅助方法argmax实现

public static int argmax(Complex[] a)
{
    double y = Double.MIN_VALUE;
    int idx = -1;

    for(int x = 0; x < a.length; x++)
    {
        if(a[x].abs() > y)
        {
            y = a[x].abs();
            idx = x;
        }
    }

    return idx;
}

我使用了第三方的FFT类和对应的Complex类完成FFT相关计算。

内容的提问来源于stack exchange,提问作者Mislav Babic

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 03:26:12