Porcupine Binding for NodeJS
Porcupine
Porcupine is is a highly accurate and lightweight wake word engine. It enables building always-listening voice-enabled applications using cutting edge voice AI.
Porcupine is:
- private and offline
- accurate
- resource efficient (runs even on microcontrollers)
- data efficient (wake words can be easily generated by simply typing them, without needing thousands of hours of bespoke audio training data and manual effort)
- scalable to many simultaneous wake-words / always-on voice commands
- cross-platform
To learn more about Porcupine, see the product, documentation, and GitHub pages.
Custom wake words
Porcupine includes several built-in keywords, which are stored as .ppn
files. To train custom PPN files, see the Picovoice Console.
Unlike the built-in keywords, custom PPN files generated with the Picovoice Console carry restrictions including (but not limited to): training allowance, time limits, available platforms, and commercial usage.
Compatibility
This binding is for running Porcupine on NodeJS 10+ on the following platforms:
- Linux (x86_64)
- macOS (x86_64)
- Raspberry Pi (2,3,4)
Web Browsers
This binding is for NodeJS and does not work in a browser. Looking to run Porcupine in-browser? Use the JavaScript WebAssembly binding instead.
Usage
The binding provides the Porcupine class. Create instances of the Porcupine class to detect specific keywords.
Quick Start: Built-in keywords
The built-in keywords give a quick way to get started. Here we can specify that we want to listen for the 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
- ALEXA
- AMERICANO
- BLUEBERRY
- BUMBLEBEE
- COMPUTER
- GRAPEFRUIT
- GRASSHOPPER
- HEY_GOOGLE
- HEY_SIRI
- JARVIS
- OK_GOOGLE
- 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
);
Using the bindings from source
Unit Tests
Run yarn
(ornpm install
) from the binding/nodejs directory to install project dependencies. This will also run a script to copy all of the necessary shared resources from the Porcupine repository into the package directory.
Run yarn test
(or npm run test
) from the binding/nodejs directory to execute the test suite.