Porcupine - Web API
API Reference for the Porcupine Web SDK.
Porcupine
class Porcupine implements PorcupineEngine
Class for the Porcupine Wake Word engine.
Porcupine.create()
static async function create(accessKey: string,keywords: Array<PorcupineKeyword | string> | PorcupineKeyword | string): Promise<Porcupine>
Creates an instance of the Porcupine Wake Word engine.
Parameters
accessKey
string : AccessKey obtained from Picovoice Console.keywords
Array<PorcupineKeyword | string> | PorcupineKeyword | string : Built-in or Base64 representations of keywords and their sensitivities. Can be provided as an array or a single keyword.
Returns
Porcupine
: An instance of the Porcupine engine.
Porcupine.process()
async function process(pcm: Int16Array): Promise<number>
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 must be single-channel and 16-bit linearly-encoded.
Parameters
pcm
Int16Array : A frame of audio.
Returns
number
: Index of detected keyword (phrase). When no keyword is detected, it returns -1.
Porcupine.release()
async function release(): Promise<void>
Releases resources acquired by the Porcupine Web SDK.
Porcupine.frameLength
get framelength(): number
Number of audio samples per frame.
Porcupine.keywordLabels
get keywordLabels(): Map<number, string>
A map of keyword indices to user-defined labels.
Porcupine.sampleRate
get sampleRate(): number
Audio sample rate accepted by Porcupine.
Porcupine.version
get version(): string
Porcupine version string.
PorcupineKeywordCustom
type PorcupineKeywordCustom = {base64: string;custom: string;sensitivity?: number;};
Type representing a keyword created using the Picovoice Console.
Parameters
base64
string : Base64 representation of a trained Porcupine keyword.custom
string : An arbitrary label that you want Picovoice to report when the detection occurs.sensitivity
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.
PorcupineKeywordBuiltin
type PorcupineKeywordBuiltin = {builtin: string;sensitivity?: number;};
Type representing a pre-trained keyword that is included with the Porcupine Web SDK.
Parameters
builtin
string : Name of a built-in keyword for the current language.sensitivity
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.
PorcupineKeyword
type PorcupineKeyword = PorcupineKeywordCustom | PorcupineKeywordBuiltin;
Type that encapsulates PorcupineKeywordCustom
and PorcupineKeywordBuiltin
.
PorcupineWorkerFactory
class PorcupineWorkerFactory
A factory class for creating new instances of the PorcupineWorker
web worker.
PorcupineWorkerFactory.create()
static async function create(accessKey: string,keywords: Array<PorcupineKeyword | string> | PorcupineKeyword | string,keywordDetectionCallback?: CallableFunction,processErrorCallback?: CallableFunction,start?: boolean): Promise<Worker>
Creates Porcupine web worker instances. The promise resolves when the worker is ready to process voice data.
Parameters
accessKey
string : AccessKey obtained from Picovoice Console.keywords
Array<PorcupineKeyword | string> | PorcupineKeyword | string : Built-in or Base64 representations of keywords and their sensitivities. Can be provided as an array or a single keyword.keywordDetectionCallback
CallableFunction : User-defined callback invoked upon detection of the wake phrase. The only input argument is the keyword label defined at initialization.processErrorCallback
CallableFunction : User-defined callback invoked if any error happens while processing the audio stream. Its only input argument is the error message.start
boolean : Indicates if worker should begin accepting audio as soon as it's initialized.
Returns
Worker
: A Porcupine web worker.