react-nativePorcupine - React Native API

API Reference for the React Native Porcupine SDK (npm)


Porcupine

class Porcupine { }

Class for the Porcupine Wake Word engine.


Porcupine.fromBuiltInKeywords()

public static async fromBuiltInKeywords(
accessKey: string,
keywords: BuiltInKeywords[],
modelPath: string = '',
sensitivities: number[] = []
)

Porcupine constructor when using built-in keywords.

Parameters

  • accessKey string : AccessKey obtained from Picovoice Console.
  • keywords BuiltInKeyword[] : List of built-in keywords for detection.
  • modelPath string : Optional. Absolute path to the file containing model parameters (.pv).
  • sensitivities number[] : Optional. Sensitivities for detecting keywords. Each value should be a number within [0, 1].

Returns


Porcupine.fromKeywordPaths()

public static async fromKeywordPaths(
accessKey: string,
keywordsPaths: string[],
modelPath: string = '',
sensitivities: number[] = []
)

Porcupine constructor when using keyword paths.

Parameters

  • accessKey string : AccessKey obtained from Picovoice Console.
  • keywordPaths string[] : List of absolute paths to keyword model files (.ppn).
  • modelPath string : Optional. Absolute path to the file containing model parameters (.pv).
  • sensitivities number[] : Optional. Sensitivities for detecting keywords. Each value should be a number within [0, 1].

Returns


Porcupine.delete()

async delete()

Releases resources acquired by Porcupine.


Porcupine.frameLength

get frameLength()

Getter for number of audio samples per frame.

Returns

  • number: Number of audio samples per frame.

Porcupine.sampleRate

get sampleRate()

Getter for audio sample rate accepted by Picovoice.

Returns

  • number: Audio sample rate accepted by Picovoice.

Porcupine.version

get version()

Getter for version.

Returns


Porcupine.process()

async process(frame: number[]): Promise<number>

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 .sampleRateand be 16-bit linearly-encoded. Porcupine operates on single-channel audio.

Parameters

  • frame number[] : A frame of audio samples.

Returns

  • Promise<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.

BuiltInKeywords

enum BuiltInKeyword { }

Enum of available built-in keywords for Porcupine Wake Word engine.

Values:

  • ALEXA = "alexa"
  • AMERICANO = "americano"
  • BLUEBERRY = "blueberry"
  • BUMBLEBEE = "bumblebee"
  • COMPUTER = "computer"
  • GRAPEFRUIT = "grapefruit"
  • GRASSHOPPER = "grasshopper"
  • HEY_GOOGLE = hey google"
  • HEY_SIRI = hey siri"
  • JARVIS = "jarvis"
  • OK_GOOGLE = ok google"
  • PICOVOICE = "picovoice"
  • PORCUPINE = "porcupine"
  • TERMINATOR = "terminator"

PorcupineError

class PorcupineError extends Error { }

Exception thrown if an error occurs within Porcupine Wake Word engine.

Exceptions:

class PorcupineActivationError extends PorcupineError { }
class PorcupineActivationLimitError extends PorcupineError { }
class PorcupineActivationRefusedError extends PorcupineError { }
class PorcupineActivationThrottledError extends PorcupineError { }
class PorcupineIOError extends PorcupineError { }
class PorcupineInvalidArgumentError extends PorcupineError { }
class PorcupineInvalidStateError extends PorcupineError { }
class PorcupineKeyError extends PorcupineError { }
class PorcupineMemoryError extends PorcupineError { }
class PorcupineRuntimeError extends PorcupineError { }
class PorcupineStopIterationError extends PorcupineError { }

PorcupineManager

class PorcupineManager { }

High-level React Native binding for Porcupine Wake Word engine. It handles recording audio from microphone, processes it in real-time using Porcupine, and notifies the client when any of the given keywords are detected.


PorcupineManager.fromBuiltInKeywords()

public static async fromBuiltInKeywords(
accessKey: string,
keywords: BuiltInKeywords[],
detectionCallback: DetectionCallback,
processErrorCallback?: ProcessErrorCallback,
modelPath?: string,
sensitivities?: number[]
)

Porcupine constructor when using built-in keywords.

Parameters

  • accessKey string : AccessKey obtained from Picovoice Console.
  • keywords BuiltInKeyword[] : List of built-in keywords for detection.
  • detectionCallback DetectionCallback : A callback for when Porcupine detects the specified keywords.
  • processErrorCallback ProcessErrorCallback : Optional. A callback for when Porcupine process function triggers an error.
  • modelPath string : Optional. Absolute path to the file containing model parameters (.pv).
  • sensitivities number[] : Optional. Sensitivities for detecting keywords. Each value should be a number within [0, 1].

Returns


PorcupineManager.fromKeywordPaths()

public static async fromKeywordPaths(
accessKey: string,
keywordPaths: string[],
detectionCallback: DetectionCallback,
processErrorCallback?: ProcessErrorCallback,
modelPath?: string,
sensitivities?: number[]
)

Porcupine constructor when using keyword paths.

Parameters

  • accessKey string : AccessKey obtained from Picovoice Console.
  • keywordPaths string[] : List of absolute paths to keyword model files (.ppn).
  • detectionCallback DetectionCallback : A callback for when Porcupine detects the specified keywords.
  • processErrorCallback ProcessErrorCallback : Optional. A callback for when Porcupine process function triggers an error.
  • modelPath string : Optional. Absolute path to the file containing model parameters (.pv).
  • sensitivities number[] : Optional. Sensitivities for detecting keywords. Each value should be a number within [0, 1].

Returns


PorcupineManager.delete()

public delete()

Releases resources acquired by PorcupineManager.


PorcupineManager.start()

public async start()

Starts recording audio from the microphone and monitors it for the utterances of the given set of keywords.


PorcupineManager.stop()

public async stop()

Stops recording audio from the microphone.


DetectionCallback

type DetectionCallback = (keywordIndex: number) => void;

Callback interface invoked when a keyword has been detected.


ProcessErrorCallback

type ProcessErrorCallback = (error: PorcupineErrors.PorcupineError) => void;

Callback interface invoked when an error occurs while processing audio.


Issue with this doc? Please let us know.