我基于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。
答案 0 :(得分:2)
我解决了这个问题,因为我意识到调度员fromPipe
没有工作,所以我更换了调度员:
InputStream inStream = new FileInputStream(path);
AudioDispatcher dispatcher = new AudioDispatcher(new UniversalAudioInputStream(inStream, new TarsosDSPAudioFormat(sampleRate, bufferSize, 1, true, true)), bufferSize, bufferOverlap);