英文:
TarsosDSP, IllegalStateException
问题
我在一个安卓项目中使用TarsosDSP,遇到了这个错误:
无法启动活动 ComponentInfo{com.example.song2sheet/com.example.song2sheet.RecordingActivity}:java.lang.IllegalStateException:在未初始化的 AudioRecord 上调用 startRecording()。
根据我所阅读的,要开始获取样本,我只需要这些代码:
AudioDispatcher dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(22050, 1024, 0);
PitchDetectionHandler detectionHandler = new PitchDetectionHandler() {
@Override
public void handlePitch(PitchDetectionResult pitchDetectionResult, AudioEvent audioEvent) {
final float pitchInHz = pitchDetectionResult.getPitch();
runOnUiThread(new Runnable() {
@Override
public void run() {
sampledFrequency = pitchInHz;
}
});
}
};
AudioProcessor pitchProcessor = new PitchProcessor(PitchProcessor.PitchEstimationAlgorithm.FFT_PITCH, 22020, 1024, detectionHandler);
dispatcher.addAudioProcessor(pitchProcessor);
Thread recordingThread = new Thread(dispatcher, "Recording Thread");
recordingThread.start();
但是如上所示,我遇到了一个 IllegalStateException。
我从这段代码中漏掉了什么吗?因为错误是在第一行抛出的。
任何帮助将不胜感激。
谢谢。
英文:
I'm using TarsosDSP for an android project, and I'm getting this error:
Unable to start activity ComponentInfo{com.example.song2sheet/com.example.song2sheet.RecordingActivity}: java.lang.IllegalStateException: startRecording() called on an uninitialized AudioRecord.
From what I've read, to start taking samples all I need is this
AudioDispatcher dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(22050, 1024, 0);
PitchDetectionHandler detectionHandler = new PitchDetectionHandler() {
@Override
public void handlePitch(PitchDetectionResult pitchDetectionResult, AudioEvent audioEvent) {
final float pitchInHz = pitchDetectionResult.getPitch();
runOnUiThread(new Runnable() {
@Override
public void run() {
sampledFrequency = pitchInHz;
}
});
}
};
AudioProcessor pitchProcessor = new PitchProcessor(PitchProcessor.PitchEstimationAlgorithm.FFT_PITCH, 22020, 1024, detectionHandler);
dispatcher.addAudioProcessor(pitchProcessor);
Thread recordingThread = new Thread(dispatcher, "Recording Thread");
recordingThread.start();
but as seen above I'm getting an IllegalStateException.
Am I missing something from this code, as the error is being thrown on the first line?
Any help would be grand.
Thanks.
专注分享java语言的经验与见解,让所有开发者获益!
评论