首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用TarsosDSP来获取MFCC?

如何用TarsosDSP来获取MFCC?
EN

Stack Overflow用户
提问于 2016-11-05 08:06:38
回答 2查看 2.4K关注 0票数 5

我到处搜索,我想不出如何在安卓系统上使用TarsosDSP提取MFCC功能。我知道如何从文件中提取FFT。有什么帮助吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-03-18 22:10:17

见官方github页面

MFCC测试文件

代码语言:javascript
复制
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()

代码语言:javascript
复制
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;
    }
票数 1
EN

Stack Overflow用户

发布于 2017-10-30 08:08:56

您可以在流程事件下获得mfcc,我认为它是针对每个帧的。

代码语言:javascript
复制
    int sampleRate = 16000;
    int bufferSize = 512;
    int bufferOverlap = 128;
    new AndroidFFMPEGLocator(this);
    final List<float[]>mfccList = new ArrayList<>(200);
    InputStream inStream = new FileInputStream(audioFilePath);
   AudioDispatcher dispatcher = new AudioDispatcher(new UniversalAudioInputStream(inStream, new TarsosDSPAudioFormat(sampleRate, bufferSize, 1, true, true)), bufferSize, bufferOverlap);
    final MFCC mfcc = new MFCC(bufferSize, sampleRate, 20, 50, 300, 3000);
    dispatcher.addAudioProcessor(mfcc);
    dispatcher.addAudioProcessor(new AudioProcessor() {

        @Override
        public void processingFinished() {
        }

        @Override
        public boolean process(AudioEvent audioEvent) {
            mfccList.add( mfcc.getMFCC());
            return true;
        }
    });
    dispatcher.run();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40436075

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档