在这个例子中(答案): 如何使用 TarsosDSP 获得 MFCC?
他们展示了如何在来自浮点数组的 android @Test 中使用 MFCC,我试图将它与来自麦克风的数据一起使用:
int sampleRate = 44100;
int bufferSize = 8192;
int bufferOverlap = 128;
final AudioDispatcher dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(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() {
}
@Override
public boolean process(AudioEvent audioEvent) {
float[] audioBuffer = audioEvent.getFloatBuffer();
textView.setText(Arrays.toString(audioBuffer));
return true;
}
});
dispatcher.run();
我想打印输出,但这没有打印任何东西,我无法调试它!我需要帮助。
编辑:
经过一番努力,我已将代码更改为:(但仍然无法正常工作)
int sampleRate = 44100;
int bufferSize = 8192;
int bufferOverlap = 128;
final AudioDispatcher dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(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() {
float audio_float[] = mfcc.getMFCC();
textView.setText(Arrays.toString(audio_float));
}
@Override
public boolean process(AudioEvent audioEvent) {
mfcc.process(audioEvent);
final float audio_float[] = mfcc.getMFCC();
//textView.setText(Arrays.toString(audio_float));
textView.setText("TESTING");
runOnUiThread(new Runnable() {
@Override
public void run() {
textView.setText(Arrays.toString(audio_float));
}
});
return true;
}
});
new Thread(dispatcher,"Audio MFCC").start();
编辑:完成:
dispatcher.addAudioProcessor(new AudioProcessor() {
@Override
public void processingFinished() {
textView.setText("Finish");
}
@Override
public boolean process(AudioEvent audioEvent) {
mfcc.process(audioEvent);
final float audio_float[] = mfcc.getMFCC();
runOnUiThread(new Runnable() {
@Override
public void run() {
textView.setText(Arrays.toString(audio_float));
textView.invalidate();
}
});
return true;
}
});
new Thread(dispatcher,"Audio MFCC").start();
}