nodejsPorcupine - NodeJS API

  • Wake Word Engine
  • Offline Voice Commands
  • Local Speech Recognition
  • Always Listening
  • Raspberry Pi
  • Linux
  • Mac
  • NodeJS
  • NPM

This document outlines how to integrate the Porcupine wake word engine within an application using its NodeJS API.

Requirements

  • NodeJS 10+
  • yarn (or npm)

Compatibility

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

Web Browsers

Looking to run Picovoice in-browser? See the JavaScript WebAssembly demo instead.

Installation

yarn add @picovoice/porcupine-node

or

npm install @picovoice/porcupine-node

Usage

The Porcupine SDK for NodeJS provides the Porcupine class. Below are code snippets showcasing how Porcupine can be integrated into different applications.

The built-in keywords give a quick way to get started. Here we can specify that we want to listen for the built-in wake words "grasshopper" and "bumblebee" with sensitivities of 0.5 and 0.65, respectively. Since Porcupine can listen to many keywords, they are provided as an array argument.

const Porcupine = require("@picovoice/porcupine-node");
const {
GRASSHOPPER,
BUMBLEBEE,
} = require("@picovoice/porcupine-node/builtin_keywords");
let handle = new Porcupine([GRASSHOPPER, BUMBLEBEE], [0.5, 0.65]);
// process a single frame of audio
// the keywordIndex provies the index of the keyword detected, or -1 if no keyword was detected
let keywordIndex = handle.process(frame);

List of built-in keywords

  • AMERICANO
  • BLUEBERRY
  • BUMBLEBEE
  • GRAPEFRUIT
  • GRASSHOPPER
  • PICOVOICE
  • PORCUPINE
  • TERMINATOR

Custom keywords

Providing an array of strings instead of the built-in enums allows you to specify an aboslute path to a keyword PPN file:

let handle = new Porcupine(
["/absolute/path/to/your/keyword.ppn"],
[0.5]
);

Override model and library paths

The Porcupine constructor accepts two optional positional parameters for the absolute paths to the model and dynamic library, should you need to override them (typically, you will not).

let handle = new Porcupine(
keywordPaths,
sensitivities,
modelFilePath,
libraryFilePath
);

Custom Wake Word

You can create custom wake word models using Picovoice Console.