TarsosDSP 拍手检测
TarsosDSP Clap Detection
我决定尝试为 android 工作室进行开发,并设计了一个应用程序来侦听拍手然后执行某种动作。我的问题在于使用 TarsosDSP。
我想 运行 Listener
class 作为 IntentService
,这样我就可以锁定我的 phone 它仍然在听。但是我在设置 AudioDispatcher
和 TarsosDSPAudioInputStream
.
时遇到问题
这是 onHandleIntent
到目前为止:
protected void onHandleIntent(Intent Intent) {
AudioDispatcher mDispatcher = new AudioDispatcher(TarsosDSPAudioInputStream, SAMPLE_RATE, BUFFER_OVERLAP);
double threshold = 8;
double sensitivity = 20;
PercussionOnsetDetector mPercussionDetector = new PercussionOnsetDetector(22050, 1024,
new OnsetHandler() {
@Override
public void handleOnset(double time, double salience) {
Log.d(TAG, "Clap detected!");
}
}, sensitivity, threshold);
mDispatcher.addAudioProcessor(mPercussionDetector);
new Thread(mDispatcher).start();
}
我想更具体地说,我不确定应该如何定义 TarsosDSPAudioInputStream
对象。 The documentation 说它是一个接口,但我不知道它是如何工作的。我是 Android Studio 和 java 的超级新手,但有一年的 C++ 经验,因为它是我专业的一部分。
TarsosDSP 已经有 android 的实现。他们有一个 AudioDispatcherFactory class 和 fromDefaultMicrophone(...) 方法。
因此您可以使用此方法初始化音频调度程序实例并向其添加任何可用的处理器。在你的情况下 PercussionOnsetDetector
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) {
Log.d(TAG, "Clap detected!");
}
}, sensitivity, threshold);
mDispatcher.addAudioProcessor(mPercussionDetector);
new Thread(mDispatcher,"Audio Dispatcher").start();
我决定尝试为 android 工作室进行开发,并设计了一个应用程序来侦听拍手然后执行某种动作。我的问题在于使用 TarsosDSP。
我想 运行 Listener
class 作为 IntentService
,这样我就可以锁定我的 phone 它仍然在听。但是我在设置 AudioDispatcher
和 TarsosDSPAudioInputStream
.
这是 onHandleIntent
到目前为止:
protected void onHandleIntent(Intent Intent) {
AudioDispatcher mDispatcher = new AudioDispatcher(TarsosDSPAudioInputStream, SAMPLE_RATE, BUFFER_OVERLAP);
double threshold = 8;
double sensitivity = 20;
PercussionOnsetDetector mPercussionDetector = new PercussionOnsetDetector(22050, 1024,
new OnsetHandler() {
@Override
public void handleOnset(double time, double salience) {
Log.d(TAG, "Clap detected!");
}
}, sensitivity, threshold);
mDispatcher.addAudioProcessor(mPercussionDetector);
new Thread(mDispatcher).start();
}
我想更具体地说,我不确定应该如何定义 TarsosDSPAudioInputStream
对象。 The documentation 说它是一个接口,但我不知道它是如何工作的。我是 Android Studio 和 java 的超级新手,但有一年的 C++ 经验,因为它是我专业的一部分。
TarsosDSP 已经有 android 的实现。他们有一个 AudioDispatcherFactory class 和 fromDefaultMicrophone(...) 方法。
因此您可以使用此方法初始化音频调度程序实例并向其添加任何可用的处理器。在你的情况下 PercussionOnsetDetector
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) {
Log.d(TAG, "Clap detected!");
}
}, sensitivity, threshold);
mDispatcher.addAudioProcessor(mPercussionDetector);
new Thread(mDispatcher,"Audio Dispatcher").start();