androidPorcupine - Android Quick Start

Platforms

  • Android (4.4+)

Requirements

Picovoice Account & AccessKey

Signup or Login to Picovoice Console to get your AccessKey. Make sure to keep your AccessKey secret.

Quick Start

Setup

  1. Install Android Studio.

  2. Include mavenCentral() repository in the top-level build.gradle. Then add the following to the app's build.gradle:

dependencies {
// ...
implementation 'ai.picovoice:porcupine-android:${LATEST_VERSION}' // replace with latest version
}
  1. 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() {
@Override
public 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

  1. Open the Android Activity demo using Android Studio.
  2. Copy your AccessKey from Picovoice Console into the ACCESS_KEY variable in MainActivity.java.
  3. 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.

Resources

Packages

API

GitHub

Benchmark

Further Reading


Issue with this doc? Please let us know.