如何使用 TarsosDSP 从文件中提取 MFCC 数据?
How do you extract MFCC data from file using TarsosDSP?
我基于这个 在 Stack Overflow 上创建了代码的 MFCC 提取部分,它创建了两个 AudioProcessor
实例。但是,使用 Android studio 上的调试器,我发现代码很快进入了 processingFinished
函数,同时跳过了两者的处理函数。在第二个 AudioProcessor 函数的 processingFinished
函数期间,实例中的 mfcc
变量保留为空。为什么数据从不处理?这是获得 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);
我基于这个 AudioProcessor
实例。但是,使用 Android studio 上的调试器,我发现代码很快进入了 processingFinished
函数,同时跳过了两者的处理函数。在第二个 AudioProcessor 函数的 processingFinished
函数期间,实例中的 mfcc
变量保留为空。为什么数据从不处理?这是获得 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);