Learn how to add wake words, like Alexa or Hey Siri, to any React app. This tutorial takes 15 minutes or less from the start to a working demo. We learn how to train custom wake word models, like Hey Jarvis, that fit your product, not Big Tech's brand. In this article, we use Picovoice Porcupine Wake Word Engine React SDK.

Wake Word Detection is also known as Keyword Spotting, Hotword Detection, Always-Listening Voice Commands, Trigger Word Detection, and Voice Activation.

Setup the Project

  1. Create a new React app:
  1. Install the dependencies:
  1. Download the Porcupine model (i.e. Deep Neural Network). From the project folder, run the following to turn the binary model into a base64 string. Remember that you need to replace ${DOWNLOADED_MODEL_PATH} with the path to the model you downloaded (e.g. ~/Downloads/porcupine_params.pv on my Ubuntu machine).
  1. Run the local server to load the page:

Train Wake Word Models

  1. Sign up for Picovoice Console.
  2. Go to the Porcupine Page.
  3. Select English as the language for your model.
  4. Type in Hey Jarvis as the phrase you want to build the model for.
Console A
  1. Optionally, you can try it within the browser
  2. Once you are happy, click on the train button.
  3. Select Web (WASM) as the platform.
Console B
  1. Click on Download. You should have a .zip file in your download folder now.
  2. Unzip it. Inside the folder, you see a file with the suffix .ppn. That's our model. Transform it into a base64 string. Remember that you need to replace ${DOWNLOADED_PPN_PATH} with the path to downloaded file (e.g. ~/Downloads/Hey-Jarvis_en_wasm_v2_1_0/Hey-Jarvis_en_wasm_v2_1_0.ppn on my Ubuntu machine)

Wire it up

  1. Go to Picovoice Console's dashboard. Copy your AccessKey.
AccessKey
  1. Create a file within src called VoiceWidget.js and paste the below into it. The code uses Porcupine's hook to create and start the wake word detection. Remember to replace ${ACCESS_KEY} with your AccessKey obtained from Picovoice Console.
  1. Modify the App.js to display the VoiceWidget and click start:

Additional Languages

Porcupine supports many more languages aside from English. To use models in other languages, refer to the quick start.

Source Code

The source code for a fully-working demo with Porcupine is available on its GitHub repository.

Have you seen our other React.js tutorials? Don’t forget to check out Real-time Transcription with React.js and Batch Transcription with React.js.