我在使用TarsosDSP检测拍手声音方面有问题。PitchDetectioHandler在某种程度上起作用,但是当涉及到使用PercussionOnsetDetector时,它不会检测到任何东西。
我在这里做错什么了吗?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Checks Permission
checkPermission(Manifest.permission.RECORD_AUDIO,REQUEST_RECORD_AUDIO_PERMISSION);
pitchText = (TextView) findViewById(R.id.pitch);
noteText = (TextView) findViewById(R.id.note);
/*PitchDetectionHandler pdh = new PitchDetectionHandler() {
@Override
public void handlePitch(PitchDetectionResult res, AudioEvent e){
final float pitchInHz = res.getPitch();
runOnUiThread(new Runnable() {
@Override
public void run() {
processPitch(pitchInHz);
}
});
}
};
AudioProcessor pitchProcessor = new PitchProcessor(PitchProcessor.PitchEstimationAlgorithm.FFT_YIN, 22050, 1024, pdh);
dispatcher.addAudioProcessor(pitchProcessor);
Thread audioThread = new Thread(dispatcher, "Audio Thread");
audioThread.start(); */
AudioDispatcher dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(22050,1024,0);
double threshold = 8;
double sensitivity = 20;
PercussionOnsetDetector mPercussionDetector = new PercussionOnsetDetector(22050, 1024,
new OnsetHandler() {
@Override
public void handleOnset(double time, double salience) {
runOnUiThread(new Runnable() {
@Override
public void run() {
System.out.println("YAAAYYY");
}
});
}
}, sensitivity, threshold);
dispatcher.addAudioProcessor(mPercussionDetector);
new Thread(dispatcher,"Audio Dispatcher").start();
}发布于 2022-06-17 21:37:07
下面的代码使用塔索斯DSP检测clap
final AudioDispatcher fromDefaultMicrophone = AudioDispatcherFactory.fromDefaultMicrophone(22050, 1024, 0);
double threshold = 6; // lower it a bit
double sensitivity = 20;
PercussionOnsetDetector mPercussionDetector = new PercussionOnsetDetector(22050, 1024,
new OnsetHandler() {
@Override
public void handleOnset(double time, double salience) {
Log.d(TAG, "Clap detected!");
startAlarm();
}
}, sensitivity, threshold);
fromDefaultMicrophone.addAudioProcessor(mPercussionDetector);
new Thread(fromDefaultMicrophone,"Audio Dispatcher").start();https://stackoverflow.com/questions/58896302
复制相似问题