如何使用TarsosDSP获取MFCC? [英] How to get MFCC with TarsosDSP?
本文介绍了如何使用TarsosDSP获取MFCC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我到处搜索,但无法弄清楚如何使用Android上的TarsosDSP提取MFCC功能.我知道如何从文件中获取FFT. 有帮助吗?
I searched everywhere and I couldn't figure out how to extract MFCC feature using TarsosDSP on Android. I know how to get FFT out of a file. Any help?
推荐答案
请参见官方 MFCC测试文件
public class MFCCTest {
// private static int counter = 0;
@Test
public void MFCCForSineTest() throws UnsupportedAudioFileException{
int sampleRate = 44100;
int bufferSize = 1024;
int bufferOverlap = 128;
final float[] floatBuffer = TestUtilities.audioBufferSine();
final AudioDispatcher dispatcher = AudioDispatcherFactory.fromFloatArray(floatBuffer, 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) {
return true;
}
});
dispatcher.run();
}
}
和TestUtilities audioBufferSine()
and TestUtilities audioBufferSine()
public class TestUtilities {
/**
* Constructs and returns a buffer of a two seconds long pure sine of 440Hz
* sampled at 44.1kHz.
*
* @return A buffer of a two seconds long pure sine (440Hz) sampled at
* 44.1kHz.
*/
public static float[] audioBufferSine() {
final double sampleRate = 44100.0;
final double f0 = 440.0;
final double amplitudeF0 = 0.5;
final double seconds = 4.0;
final float[] buffer = new float[(int) (seconds * sampleRate)];
for (int sample = 0; sample < buffer.length; sample++) {
final double time = sample / sampleRate;
buffer[sample] = (float) (amplitudeF0 * Math.sin(2 * Math.PI * f0 * time));
}
return buffer;
}
这篇关于如何使用TarsosDSP获取MFCC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文