Porcupine Wake Word
Web API
API Reference for the Porcupine Web SDK (npmjs).
Porcupine
Class for the Porcupine Wake Word engine.
Porcupine.create()
Creates an instance of the Porcupine wake word engine using either a '.pv' file in public directory or a base64'd string. The model size is large, hence it will try to use the existing one if it exists, otherwise saves the model in storage.
Parameters
accessKey
string : AccessKey obtained from Picovoice Console.keywords
Array<PorcupineKeyword | BuiltInKeyword> | PorcupineKeyword | BuiltInKeyword : Built-in or Base64 representations of keywords and their sensitivities. Can be provided as an array or a single keyword.keywordDetectionCallback
DetectionCallback : User-defined callback to run after a keyword is detected.model
PorcupineModel : object containing a base64 string representation of or path to public binary of a Porcupine parameter model used to initialize Porcupine.options
PorcupineOptions : Optional configuration arguments.
Returns
Porcupine
: An instance of the Porcupine engine.
Porcupine.process()
Processes a frame of audio. The required sample rate can be retrieved from .sampleRate
and the
length of frame (number of audio samples per frame) can be retrieved from .frameLength
. The
audio needs to be 16-bit linearly-encoded. Furthermore, the engine operates on single-channel audio.
The result will be supplied with the callback provided when initializing the engine.
Parameters
pcm
Int16Array : A frame of audio.
Porcupine.release()
Releases resources acquired by the Porcupine Web SDK.
Porcupine.frameLength
Number of audio samples per frame.
Porcupine.sampleRate
Audio sample rate accepted by Porcupine.
Porcupine.version
Porcupine version string.
DetectionCallback
Type defining the interface for the user-defined DetectionCallback
used to run after a keyword is detected.
Parameters
detection
PorcupineDetection : Detection data.
PorcupineModel
Porcupine options type.
base64
string : Base64 representation of the file.publicPath
string : The file path relative to the public directory.customWritePath
string : Custom path to save the model in storage.forceWrite
boolean : Flag to overwrite the model in storage even if it exists.version
number : Porcupine model version. Set to a higher number to update the model file.
PorcupineOptions
processErrorCallback
(error: string) => void : User-defined callback invoked if any error happens while processing the audio stream. Its only input argument is the error message. NOTE: This is only used by theporcupine-web
package.
PorcupineKeyword
Type that encapsulates PorcupineKeywordCustom
and PorcupineKeywordBuiltin
.
PorcupineKeywordCustom
Type representing a keyword created using the Picovoice Console.
Parameters
label
string : An arbitrary label used for caching purposessensitivity
number : Sensitivity value for detecting the keyword. Value should be a number within [0, 1]. A higher sensitivity results in fewer misses at the cost of increasing the false alarm rate. The default value is 0.5.base64
string : Base64 representation of the file.publicPath
string : The file path relative to the public directory.customWritePath
string : Custom path to save the model in storage.forceWrite
boolean : Flag to overwrite the model in storage even if it exists.version
number : Porcupine model version. Set to a higher number to update the model file.
PorcupineKeywordBuiltin
Type representing a pre-trained keyword that is included with the Porcupine Web SDK.
Parameters
builtin
BuiltInKeyword : Name of a built-in keywordsensitivity
number : Sensitivity value for detecting the keyword. Value should be a number within [0, 1]. A higher sensitivity results in fewer misses at the cost of increasing the false alarm rate. The default value is 0.5.
PorcupineDetection
Type containing detection result data returned from the Porcupine engine.
Parameters
index
number : The index of the detected keyword.label
string : The corresponding label of the detected keyword.
PorcupineWorker
A class for using Porcupine on a worker thread.
PorcupineWorker.create()
Creates an instance of the PorcupineWorker
using either a '.pv' file in public directory or a base64'd string.
The model size is large, hence it will try to use the existing one if it exists, otherwise saves the model in storage.
Parameters
accessKey
string : AccessKey obtained from Picovoice Console.keywords
Array<PorcupineKeyword | BuiltInKeyword> | PorcupineKeyword | BuiltInKeyword : Built-in or Base64 representations of keywords and their sensitivities. Can be provided as an array or a single keyword.keywordDetectionCallback
DetectionCallback : User-defined callback to run after a keyword is detected.model
PorcupineModel : object containing a base64 string representation of or path to public binary of a Porcupine parameter model used to initialize Porcupine.options
PorcupineOptions : Optional configuration arguments.
Returns
PorcupineWorker
: An instance ofPorcupineWorker
.
PorcupineWorker.process()
Processes a frame of audio. The required sample rate can be retrieved from .sampleRate
and
the length of frame (number of audio samples per frame) can be retrieved
from .frameLength
. The audio needs to be 16-bit linearly-encoded. Furthermore, the engine
operates on single-channel audio.
The result will be supplied with the callback provided when creating the worker.
Parameters
pcm
Int16Array : A frame of audio.
PorcupineWorker.release()
Releases resources acquired by the Porcupine Web SDK.
PorcupineWorker.terminate()
Force terminates the instance of PorcupineWorker
.
PorcupineWorker.frameLength
Number of audio samples per frame.
PorcupineWorker.sampleRate
Audio sample rate accepted by Porcupine.
PorcupineWorker.version
Porcupine version string.
BuiltInKeyword
Enum of built-in keywords.
PorcupineError
Error thrown if an error occurs within Porcupine
wake word engine.
Errors: