One of Flutter's strengths is the ability to target multiple platforms with a single codebase, but sometimes integrating features that require low-level device capabilities can be tricky.
Wake word detection—recognizing a specific phrase to "wake up" an app—is one such feature. Fortunately, Picovoice's Porcupine Wake Word Detection SDK for Flutter provides an easy, on-device solution. Your Flutter app can respond instantly when a user says a custom wake word, without sending audio to the cloud. The SDK makes it easy to implement cross-platform wake word detection, ensuring both speed and privacy.
This guide shows how to add custom, on-device wake word detection to a Flutter app with Porcupine Wake Word.
What you'll learn:
- How to set up audio recording permissions for iOS and Android
- How to add Porcupine Wake Word to your Flutter app
What you need:
- Flutter SDK (2.8.1+)
- Android SDK (21+)
- JDK (11+)
- Xcode (13+)
Enable Microphone Permissions
This tutorial requires recording audio, so before we begin, you'll need to configure your Flutter project to request audio recording permissions from the user. Make sure the appropriate permissions are enabled for each platform:
iOS
Add the following block to Info.plist:
Android
Add the following block to AndroidManifest.xml:
Internet is required only for licensing and usage tracking. Audio remains on-device, and is not streamed. Once Porcupine has been initialized, it can run offline.
Add Wake Word Detection with Porcupine
- Add Porcupine Flutter Plugins: To use Porcupine Wake Word in your Flutter project, add the flutter_voice_processor and porcupine_flutter plugins to your project's dependencies. Open your project's pubspec.yamlfile and add the following:
- Get Your Picovoice Access Key: Sign up for a free Picovoice Console account and obtain your - AccessKey. The- AccessKeyis only required for authentication and authorization.
- Train Custom Keyword: Create a custom keyword using the Picovoice Console. We've written a guide on choosing a wake word to help you choose a - wake wordthat performs optimally.
If you'd like to see a video walkthrough for this step, check out Picovoice Console Tutorial: Porcupine Wake Word.
- Add Keyword Files to Your Project: Once you have chosen your keyword, download the keyword files. You will need to download two keyword files—one for Android, and one for iOS. The files will have a .ppnextension. Place the files into your project'sassets/folder and add the file path to yourpubspec.yaml:
- Using Non-English Model Files (Optional): If you created a non-English keyword, you will also need to add the corresponding model file for the language you chose. Also place the model file into your project's assets/folder and add the file path to yourpubspec.yaml:
Step-by-Step Code Walkthrough
- Define a function to handle keyword detection. You can pass in more than one keyword when initializingPorcupine(see next step), and the detection callback function will give you the index of the keyword detected.
- Create an instance of PorcupineManager. Be sure to replace the placeholders, and pass in your_detectionCallback()function.
- To start listening for wake words, callstart().
- To stop listening for wake words, callstop().
- Once you no longer need PorcupineManager, be sure to release the resources acquired by callingdelete().
Flutter Wake Word Code Example
Below is a fully implemented widget you can add to your project to see Porcupine in action. Be sure to replace '{ACCESS_KEY}' with your own AccessKey from Picovoice Console, '{KEYWORD_FILE}' with your keyword files, and '{MODEL_FILE}' with your model file (if applicable).
This is a simplified example that includes all the essential code to get you started. If you'd like to see a complete working app, check out the Porcupine Flutter demo on our GitHub repository.
This tutorial uses the following packages:
You can also explore our documentation for more details:
Start Building






