nodejsPorcupine - NodeJS Quick Start

  • Wake Word Detection
  • Local Voice Commands
  • Offline Keyword Spotting
  • Hotword Detection
  • Always Listening
  • Voice Activation


  • NodeJS 10+
  • yarn (or npm)


  • Linux (x86_64)
  • macOS (x86_64)
  • Raspberry Pi (2,3,4)

Web Browsers

Looking to run Porcupine in-browser? See the Web, Angular, React, or Vue docs instead.

Microphone Setup


See the documentation for node-record-lpm16 for instructions on installing SoX.

Linux & Raspberry Pi

Connect the microphone and get the list of available input audio devices:

arecord -L

The output will be similar to below

    Discard all samples (playback) or generate zero samples (capture)
    USB PnP Sound Device, USB Audio
    Default Audio Device
    USB PnP Sound Device, USB Audio
    Direct hardware device without any conversions
    USB PnP Sound Device, USB Audio
    Hardware device with all software conversions

In this case, we pick plughw:CARD=Device,DEV=0. Note that this device comes with software conversions which are handy for resampling. In what follows we note this value as ${INPUT_AUDIO_DEVICE}.

create ~/.asoundrc

pcm.!default {
type asym
capture.pcm "mic"
pcm.mic {
type plug
slave {

If you have a speaker add a section for that to ~/.asoundrc as well.

Check if the microphone works properly by recording audio into a file:

arecord --format=S16_LE --duration=5 --rate=16000 --file-type=wav ~/test.wav

If the command above executes without any errors, then the microphone is functioning as expected. We recommend inspecting the recorded file for recording side effects such as clipping.

Demo Applications

The Porcupine NodeJS demo package provides two demonstration command-line applications for Porcupine: a file-based demo, which scans a compatible WAV file for keywords, and a microphone demo, which listens for keywords and outputs detections live.

Install the demo using the global switch so that will be available on the command line:

yarn global add @picovoice/porcupine-node-demo


npm install -g @picovoice/porcupine-node-demo

Microphone Demo

The microphone demo allows you monitor microphone input for keywords using Porcupine. For microphone access, the node-record-lpm16 package is used. Please follow that documentation for troubleshooting. The node-record-lpm16 library spawns a different microphone recording process depending on the OS used. The microphone program (SoX or Arecord) must be setup manually and is not included with yarn/npm.

Use ppn-mic-demo to run the mic demo. Specify either built-in keywords with --keywords or paths to Porcupine .ppn files with --keyword_file_paths.

Here is an example which will listen for "grapefruit" keyword:

ppn-mic-demo --keywords grapefruit

Wake word detections will display in the console:

Platform: 'mac'; attempting to use 'sox' to access microphone ...
Listening for wake word(s): grapefruit
Press ctrl+c to exit.
Detected 'grapefruit'

File Demo

The file-based demo allows you to scan a compatible WAV file for keywords using Porcupine. Run the file-based demo:

ppn-file-demo --input_audio_file_path ${PATH_TO_WAV_FILE} --keywords grasshopper,bumblebee

Replace ${PATH_TO_WAV_FILE} with a path to a compatible WAV file. Detections of each keyword will be output in the terminal, along with their time location in the file:

Detected keyword 'bumblebee' @ 16.096s
Detected keyword 'grasshopper' @ 28.896s

Custom Wake Words

You can create custom Porcupine wake word models using Picovoice Console.

Issue with this doc? Please let us know.