【问题标题】:How to get MFCC with TarsosDSP?如何使用 TarsosDSP 获得 MFCC?
【发布时间】:2017-03-19 01:53:10
【问题描述】:

我到处搜索,但不知道如何在 Android 上使用 TarsosDSP 提取 MFCC 功能。我知道如何从文件中获取 FFT。 有什么帮助吗?

【问题讨论】:

    标签: android mfcc tarsosdsp


    【解决方案1】:

    见官方github page

    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()

    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;
        }
    

    【讨论】:

      【解决方案2】:

      可以在进程事件下获取mfcc,我认为是针对每一帧的

          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();
      

      【讨论】:

        猜你喜欢
        • 2017-12-16
        • 2015-08-14
        • 1970-01-01
        • 2011-08-15
        • 1970-01-01
        • 2018-04-13
        • 1970-01-01
        • 2017-12-26
        • 1970-01-01
        相关资源
        最近更新 更多