This section contains the source code for Android demo application. The application uses a high-level library, PorcupineManager, for wake word detection. The library can be used on its own to build always-listening Android applications. It manages all aspects of wake word detection including configuring Porcupine, recording input audio, and sending notifications.
Consult the prerequisites section of Android binding.
Using Android Studio open demo/android as an android project and then run the application. Note that you need an android phone with developer options enabled connected to your machine in order to run the application.
If you'd like to run tests navigate to androidTest using Android Studio,
right click, and select Run Tests in ai.picovoice.porcupine.demo
from drop down menu.
You can add PorcupineManager as a dependency to your Android app by consulting the documentation on Android Developers website.
PorcupineManager requires RECORD_AUDIO
user permission. Be sure it is granted to your App.
Furthermore, Porcupine performs data-intensive operations such as recording/processing audio which should not be run on the
UI thread. Make sure you are following the best practices for data-intensive operations.
The library can be initialized using
final String modelFilePath = ... // It is available at lib/common/porcupine_params.pv
final String keywordFilePath = ...
final float sensitivity = 0.5f;
PorcupineManager manager = new PorcupineManager(
modelFilePath,
keywordFilePath,
sensitivity,
new KeywordCallback() {
@Override
public void run() {
// detection event logic/callback
}
});
When initialized, input audio can be monitored using manager.start()
. When done be sure to stop the manager using
manager.stop()
. modelFilePath
should point to model parameter file which contains
neural network parameters. This file is shipped separately to reduce the size of library while supporting all ABIs. Furthermore,
keywordFilePath
should point to an Android keyword file available at resources/keyword_files. Custom
keyword files for Android are provided with purchase of the commercial license. In order to purchase a commercial license please
contact us at contact@picovoice.ai. For more information about keyword files refer to
tools/optimizer. Finally, sensitivity
is the parameter that enables developers to trade miss rate for false alarm. It is a floating number within
[0, 1]. A higher sensitivity reduces miss rate at cost of increased false alarm rate. For more information about this parameter
refer to include/pv_porcupine.h.
If you'd like to run the tests navigate to androidTest using Android Studio,
right click, and select Run Tests in ai.picovoice.porcupinemanager
from drop down menu.