Porcupine - Android Quick Start
Platforms
- Android (4.4+)
Requirements
- Picovoice Account and AccessKey
- Android Studio
- Android device with USB debugging enabled or Android simulator
Picovoice Account & AccessKey
Signup or Login to Picovoice Console to get your AccessKey
.
Make sure to keep your AccessKey
secret.
Quick Start
Setup
Install Android Studio.
Include
mavenCentral()
repository in the top-levelbuild.gradle
. Then add the following to the app'sbuild.gradle
:
dependencies {// ...implementation 'ai.picovoice:porcupine-android:${LATEST_VERSION}' // replace with latest version}
- Add the following to the app's
AndroidManifest.xml
file to enable recording with an Android device's microphone:
<uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.RECORD_AUDIO" />
Usage
Use the PorcupineManager Builder
to create an instance of PorcupineManager
that detects the included built-in wake words porcupine
and bumblebee
:
import ai.picovoice.porcupine.*;PorcupineMananger porcupineManager = new PorcupineManager.Builder().setAccessKey("${ACCESS_KEY}").setKeywords([Porcupine.BuiltInKeyword.PORCUPINE, Porcupine.BuiltInKeyword.BUMBLEBEE]).build(context, wakeWordCallback);PorcupineManagerCallback wakeWordcallback = new PorcupineManagerCallback() {@Overridepublic void invoke(int keywordIndex) {if (keywordIndex == 0) {// porcupine detected} else if (keywordIndex == 1) {// bumblebee detected}}}
Start audio capture and wake word detection with:
porcupineManager.start();
Stop with:
porcupineManager.stop();
Free resources used by PorcupineManager
:
porcupineManager.delete();
Custom Keywords
Create custom keyword using the Picovoice Console. Download the custom wake word file (.ppn
) and create an instance of PorcupineManager
using the .setKeywordPaths
build method:
PorcupineManager porcupineManager = new PorcupineManager.Builder().setAccessKey("${ACCESS_KEY}").setKeywordPaths(["${KEYWORD_FILE_PATH}"]).build(context, wakeWordCallback);
Non-English Languages
Use the corresponding model file (.pv
), to detect non-English wake words.
The model files for all supported languages are available
on the Porcupine GitHub repository.
Pass in the model file using the setModelPath
builder method to change the detection language:
PorcupineManager porcupineManager = new PorcupineManager.Builder().setAccessKey("${ACCESS_KEY}").setKeywordPaths(["${KEYWORD_FILE_PATH}"]).setModelPath("${MODEL_FILE_PATH}").build(context, wakeWordCallback);
Demo
For the Porcupine Android SDK, we offer demo applications that demonstrate how to use the Wake Word engine on real-time audio streams (i.e. microphone input).
Setup
Clone the Porcupine repository from GitHub using HTTPS:
git clone --recurse-submodules https://github.com/Picovoice/porcupine.git
Usage
- Open the Android Activity demo using Android Studio.
- Copy your
AccessKey
from Picovoice Console into theACCESS_KEY
variable in MainActivity.java. - Run the application using a connected Android device or using an Android simulator.
The demo detects the chosen keyword only when the application is in focus. To run the demo in the background or use in conjunction with Android's Speech-To-Text API, head over to our Github repository.