🚀 Best-in-class Voice AI!
Build compliant and low-latency AI applications running entirely on mobile without sharing user data with 3rd parties.
Start Free

Hands-free voice control is increasingly important for mobile apps, supporting use cases like accessibility features, smart home control, and in-car interactions. Flutter makes it easy to build cross-platform apps, but it doesn't include built-in wake word detection, and most open-source engines weren't designed for mobile performance. Cloud-based wake word detection solutions also have several drawbacks, including added latency, the need for a constant internet connection, and potential privacy issues, making them less suitable for many apps.

On-device wake word detection solves these challenges by running entirely on the user's device, enabling faster, more reliable response times and improved privacy. In this guide, you'll learn how to build a keyword detection application in Flutter using Porcupine Wake Word.

Key Takeaways

  • Cloud-based wake-word detection can be slow, unreliable, and raises privacy concerns.
  • Offline engines exist, but most aren't optimized for mobile performance.
  • Porcupine runs fully on-device, offering fast, accurate, and privacy-friendly wake-word recognition.

How to Add Wake Word Detection in Flutter

Prerequisites

1. Install Dependencies

Add the flutter_voice_processor and porcupine_flutter plugins to your project's pubspec.yaml:

2. Train a Custom Keyword Model

Create a Picovoice Console account and train a custom keyword.

Useful guides:

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 .ppn extension.

3. Add Your Keyword File

Place your downloaded keyword files into your project's assets/ folder and add the file path to your pubspec.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 your pubspec.yaml:

4. Configure Microphone Permissions

iOS Setup

In Info.plist:

Android Setup

In AndroidManifest.xml:

5. Define Keyword Detection Callback

Define a function to handle keyword detection. You can pass in more than one keyword when initializing Porcupine (see next step), and the detection callback function will give you the index of the keyword detected.

6. Initialize Keyword Detection Engine in Flutter

Copy your AccessKey from the Picovoice Console. The AccessKey is only required for authentication and authorization.

Create an instance of PorcupineManager. Replace {ACCESS_KEY} with your Picovoice AccessKey, keywordPath and modelPath with the correct paths, and pass in your _detectionCallback() function.

7. Start & Stop Keyword Detection

To start listening for wake words:

To stop listening for wake words:

8. Clean Up Resources

Once you no longer need PorcupineManager, release the resources acquired:

Flutter Wake Word Complete Code Example

Below is a fully implemented widget you can add to your project to see Porcupine in action. Replace '{ACCESS_KEY}' with your own AccessKey from Picovoice Console, '{KEYWORD_FILE}' with your keyword file, and '{MODEL_FILE}' with your model file (if applicable).

This is a simplified example but 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:

Next Steps

Now that you have wake word detection set up, combine it with Rhino Speech-to-Intent to handle voice commands immediately after the wake word, enabling a fully hands-free voice experience.

Start Building

Conclusion

With Porcupine and Flutter, you can build offline voice-activated applications that work reliably on both Android and iOS. Whether you're building accessibility tools, hands-free interfaces, or voice-controlled hardware, this guide gives you everything you need to integrate accurate wake-word detection into your app.

Frequently Asked Questions

Can I use multiple wake words at the same time?

Yes, Porcupine supports multiple keywords. You just need to pass an array of keyword paths when initializing PorcupineManager.

Can I use wake word detection offline in Flutter?

Porcupine runs keyword detection entirely on-device. Internet is only required for licensing and usage tracking.

Can I use non-English wake words?

Yes, Porcupine supports multiple languages. You will need the corresponding model file for your chosen language.

What's the best wake word library for Flutter?

The best wake word library for Flutter depends on your app's needs, but porcupine_flutter is a popular choice for its accurate, offline, and privacy-friendly detection, support for custom keywords, and easy Flutter integration.

Does flutter_porcupine work on both iOS and Android?

Yes, Porcupine Flutter supports both platforms, but you need separate keyword files for each.