如何使用TarsosDSP从文件中提取MFCC数据?

时间:2017-07-11 19:55:41

标签: java android audio mfcc tarsosdsp

我基于Stack Overflow上的example创建了我的代码的MFCC提取部分,它创建了两个AudioProcessor个实例。但是,在Android studio上使用调试器,我发现代码快速进入processingFinished函数,同时跳过两者的进程函数。在第二个AudioProcessor函数的mfcc函数期间,实例中的processingFinished变量保持为null。为什么数据永远不会处理?这是获得MFCC的正确方法吗?

我的源代码:(我将theAudioDispatcher更改为来自文件的管道)

private void onMFCC() {

    int sampleRate = 44100;
    int bufferSize = 1024;
    int bufferOverlap = 128;
    //final AudioDispatcher dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(22050,1024,512);
    String path = getExternalCacheDir().getAbsolutePath() + "/saytest.mp4";
    new AndroidFFMPEGLocator(this);
    final AudioDispatcher dispatcher = AudioDispatcherFactory.fromPipe(path, sampleRate, bufferSize, bufferOverlap);
    final MFCC mfcc = new MFCC(bufferSize, sampleRate, 40, 50, 300, 3000);

    dispatcher.addAudioProcessor(mfcc);
    dispatcher.addAudioProcessor(new AudioProcessor() {

        @Override
        public void processingFinished() {

            //vvv error b/c mfcc instance variable is null
            //float[] mfccArr = mfcc.getMFCC();  
            System.out.println("DONE");
        }

        @Override
        public boolean process(AudioEvent audioEvent) {
            // breakpoint or logging to console doesn't enter function
            return true;
        }
    });
    dispatcher.run();

}

由于管道AudioDispatcher与此有关,是否有可能出现错误?

Starting piped decoding process for /storage/emulated/0/Android/data/com.example.audiorecorder/cache/saytest.mp4
I/PipeDecoder:  with command: "/data/user/0/com.example.audiorecorder/cache/ffmpeg" -ss 0.0   -i "/storage/emulated/0/Android/data/com.example.audiorecorder/cache/saytest.mp4" -vn -ar 44100 -ac 1 -sample_fmt s16 -f s16le pipe:1
I/PipeDecoder: CANNOT LINK EXECUTABLE "/data/user/0/com.example.audiorecorder/cache/ffmpeg": /data/data/com.example.audiorecorder/cache/ffmpeg: has text relocations
I/PipeDecoder: Aborted 
I/PipeDecoder: Finished piped decoding process

任何帮助将不胜感激。非常感谢你!

修改 我尝试通过将此行添加到方法的末尾来独立调用过程函数:

mfcc.process(new AudioEvent(new TarsosDSPAudioFormat(sampleRate, bufferSize, 1, true, true)));

然而,这给了我一个NullPointerException。

  • 我还使用两个不同的音频文件比较了mfcc实例,但我发现它们具有完全相同的数据,因此它们没有处理结果。当我将调度程序更改回麦克风时,mfcc有一个值,程序通过了进程函数!为什么调度员访问音频文件不起作用?

1 个答案:

答案 0 :(得分:2)

我解决了这个问题,因为我意识到调度员fromPipe没有工作,所以我更换了调度员:

InputStream inStream = new FileInputStream(path);
AudioDispatcher dispatcher = new AudioDispatcher(new UniversalAudioInputStream(inStream, new TarsosDSPAudioFormat(sampleRate, bufferSize, 1, true, true)), bufferSize, bufferOverlap);