Porcupine Wake Word
Node.js API
API Reference for the Node.js Porcupine SDK (npmjs).
Porcupine
Class for the Porcupine wake word engine.
Porcupine can be initialized using the class constructor().
Resources should be cleaned when you are done using the release() method.
Porcupine.constructor()
constructor method for Porcupine wake word engine.
Parameters
accessKeystring : AccessKey obtained from Picovoice Console.keywordsArray<string> : Absolute paths to keyword model files.sensitivitiesArray<number> : Sensitivities for detecting keywords. Each value should be a number within [0, 1]. A higher sensitivity results in fewer misses at the cost of increasing the false alarm rate.optionsPorcupineOptions : Optional init configuration arguments:modelPathstring : Path to the file containing model parameters (.pv).devicestring : String representation of the device (e.g., CPU or GPU) to use. If set tobest, the most suitable device is selected automatically. If set togpu, the engine uses the first available GPU device. To select a specific GPU device, set this argument togpu:${GPU_INDEX}, where${GPU_INDEX}is the index of the target GPU. If set tocpu, the engine will run on the CPU with the default number of threads. To specify the number of threads, set this argument tocpu:${NUM_THREADS}, where${NUM_THREADS}is the desired number of threads.libraryPathstring : Path to the Orca dynamic library (.node).
Returns
Porcupine: An instance of Porcupine wake word engine.
Porcupine.listAvailableDevices()
Lists all available devices that Porcupine can use for inference. Each entry in the list can be the device argument of the constructor.
Parameters
optionsPorcupineInputOptions : Optional input configuration arguments:libraryPathstring : Path to the Porcupine dynamic library (.node).
Returns
- string[] : List of all available devices that Porcupine can use for inference.
Porcupine.process()
Processes a frame of the incoming audio stream and emits the detection result.
The number of samples per frame can be attained by
calling .frameLength. The incoming audio needs to have a sample rate equal
to .sampleRate and be 16-bit linearly-encoded. Porcupine operates on single-channel audio.
Parameters
frameArray<number> : A frame of audio samples.
Returns
number: Index of observed keyword at the end of the current frame. Indexing is 0-based and matches the ordering of keyword models provided to the constructor. If no keyword is detected then it returns -1.
Porcupine.frameLength
The number of audio samples per frame.
Porcupine.sampleRate
The audio sample rate accepted by the Porcupine engine.
Porcupine.version
The version of the Porcupine engine.
Porcupine.release()
Releases resources acquired by Porcupine
PorcupineOptions
Porcupine init options type.
modelPathstring : The path to the Porcupine model (.pv).devicestring? : String representation of the device (e.g., CPU or GPU) to use for inference. If set tobest, picoLLM picks the most suitable device. If set togpu, the engine uses the first available GPU device. To select a specific GPU device, set this argument togpu:${GPU_INDEX}, where${GPU_INDEX}is the index of the target GPU. If set tocpu, the engine will run on the CPU with the default number of threads. To specify the number of threads, set this argument tocpu:${NUM_THREADS}, where${NUM_THREADS}is the desired number of threads.libraryPathstring : The path to the Porcupine dynamic library.
PorcupineInputOptions
Porcupine input options type.
libraryPathstring : The path to the Porcupine dynamic library.
BuiltInKeyword
Enum of built-in keywords.
Errors
Exceptions thrown if an error occurs within Porcupine Wake Word engine.
Exceptions: