No Way, Google: Build Your Own Wake Word Service on Android

Ian Lavery
Picovoice
Published in
3 min readApr 15, 2021

The pre-baked Android wake word offerings from Google are great, but limited, to say the least. The phrases ‘OK Google’ and ‘Hey Google’ are your two keyword options and there is only a small handful of features your app can expose to the Google Assistant. What if you have an idea for voice control that doesn’t fit this mould? What if you require a special trigger word for your app? In these cases, Google says too bad. Well, let’s see what we can do without them and implement a background service with Picovoice’s offline wake word solution: Porcupine.

1 — Add the Porcupine Wake Word Library

Ensure you have a reference to Maven Central in your project’s build.gradle file:

repositories {
mavenCentral()
}

Add the following reference to your app’s build.gradle file:

dependencies {
implementation 'ai.picovoice:porcupine-android:${LATEST_VERSION}'
}

2 — Create a Background Service

First, create a class that extends the Service class:

Then, in your MainActivity, add code to start and stop the PorcupineService:

3 — Request Audio Recording Permissions

In your app’s AndroidManifest.xml, add the following lines:

<uses-permission android:name="android.permission.RECORD_AUDIO"/>

Now we need to check if we have permission to record audio in the MainActivity and if not, we need to ask the user for it. Add the following code to achieve this:

4 — Launch Wake Word Engine from a Service

To run Porcupine in our service, we first need to tell it what word to detect. Porcupine comes with a selection of pre-trained wake words out-of-the-box, including some popular voice assistant keywords like ‘Alexa’, ‘Hey Siri’, and ‘OK Google’. For this demo, use one of the more generic built-in keywords, ‘Computer’.

We’ll also need to grab a Picovoice AccessKey by signing up for a free account on Picovoice Console.

In our PorcupineService class, we’ll create an instance of PorcupineManager, which will handle audio capture and processing for us. Using its builder, we can specify which built-in phrase we want it to detect, as well as the sensitivity of the detection engine (a higher sensitivity reduces miss rate at cost of increased false alarm rate). Our service class now looks like this:

Now we have a service that detects the wake word ‘Computer’. As you can see in the above code, we’ve left the wake word detection callback blank, but you can trigger any action from there. If you have a fitness app, you could show the user how many steps they’ve taken; a navigation app could show them how far they are from their destination; a cooking app could show them the next recipe step. You can let your imagination take it from there!

The full source code from this tutorial can be found on GitHub. For more information regarding Picovoice’s SDKs and products, visit the website, docs or explore the GitHub repositories. If your project requires custom wake words, sign up for the Picovoice Console.

--

--