我正在开发一个分析声音文件音调的程序。我遇到了一个非常好的 API,称为“TarsosDSP”,它提供了各种音高分析。然而,我在设置它时遇到了很多麻烦。有人可以向我展示一些有关如何使用此 API(特别是 PitchProcessor 类)的快速指南吗?一些代码片段将非常感激,因为我在声音分析方面确实很新。
Thanks
编辑:我在以下位置找到了一些文件http://husk.eecs.berkeley.edu/courses/cs160-sp14/index.php/Sound_Programming http://husk.eecs.berkeley.edu/courses/cs160-sp14/index.php/Sound_Programming其中有一些示例代码展示了如何设置 PitchProcessor,...
int bufferReadResult = mRecorder.read(mBuffer, 0, mBufferSize);
// (note: this is NOT android.media.AudioFormat)
be.hogent.tarsos.dsp.AudioFormat mTarsosFormat = new be.hogent.tarsos.dsp.AudioFormat(SAMPLE_RATE, 16, 1, true, false);
AudioEvent audioEvent = new AudioEvent(mTarsosFormat, bufferReadResult);
audioEvent.setFloatBufferWithByteBuffer(mBuffer);
pitchProcessor.process(audioEvent);
…我很迷茫,mBuffer 和 mBufferSize 到底是什么?我如何找到这些值?我在哪里输入我的音频文件?
TarsosDSP 框架中的音频基本流程如下:读取源自音频文件或麦克风的传入音频流并将其切成例如帧。 1024 个样本。每个帧都会通过一个管道进行修改或分析(例如音调分析)。
在 TarsosDSP 中AudioDispatcher
负责将音频切成帧。它还将音频帧包装成AudioEvent
目的。这AudioEvent
对象是通过链发送的AudioProcessors
.
因此,在您引用的代码中,mBuffer 是音频帧,mBufferSize 是样本中缓冲区的大小。您可以自己选择缓冲区大小,但对于音高检测,2048 个样本是合理的。
对于音调检测,您可以使用 TarsosDSP 库执行以下操作:
PitchDetectionHandler handler = new PitchDetectionHandler() {
@Override
public void handlePitch(PitchDetectionResult pitchDetectionResult,
AudioEvent audioEvent) {
System.out.println(audioEvent.getTimeStamp() + " " pitchDetectionResult.getPitch());
}
};
AudioDispatcher adp = AudioDispatcherFactory.fromDefaultMicrophone(2048, 0);
adp.addAudioProcessor(new PitchProcessor(PitchEstimationAlgorithm.YIN, 44100, 2048, handler));
adp.run();
在此代码中,首先创建一个处理程序,该处理程序仅打印检测到的音高。这AudioDispatcher
连接到默认麦克风,缓冲区大小为 2048。检测音高的音频处理器被添加到AudioDispatcher
。处理程序也在那里使用。
最后一行启动该过程。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)