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

我的源代码:(我将AudioDispatcher更改为从文件管道传输)

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具有一个值,程序通过了处理功能!为什么调度程序访问音频文件不起作用?
  • 最佳答案

    我解决了这个问题,因为我意识到调度程序fromPipe无法正常工作,因此我更换了调度程序:

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

    关于java - 如何使用TarsosDSP从文件中提取MFCC数据?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45043466/

    10-12 21:28