reactPorcupine - React API

API Reference for the Porcupine React SDK.


usePorcupine()

function usePorcupine(
porcupineWorkerFactory: PorcupineWorkerFactory,
porcupineHookArgs: PorcupineHookArgs,
keywordEventHandler: (label: string) => void
)

React Hook for Porcupine wake word engine.

Parameters

  • porcupineWorkerFactory PorcupineWorkerFactory : The language-specific worker factory, imported as { PorcupineWorkerFactory } from the @picovoice/porcupine-web-xx-worker series of packages, where xx is the two-letter language code.
  • porcupineHookArgs PorcupineHookArgs : usePorcupine Hook Parameters.
  • keywordEventHandler (label: string) => void : User-defined callback function invoked upon detection of the keywords.

Returns

  • isLoaded boolean : A state indicating whether the engine is initialized successfully.
  • isListening boolean : A state indicating whether the webVoiceProcessor is passing audio to the engine.
  • isError boolean : A state indicating whether the Hook returned an error.
  • errorMessage string : A string expression of the error.
  • webVoiceProcessor WebVoiceProcessor : A pointer to the internal webVoiceProcessor object.
  • start () => void : A method to start processing the audio.
  • pause () => void : A method to stop processing the audio.
  • setKeywordEventHandler (label: string) => void : Setter for keywordEventHandler

PorcupineHookArgs

type PorcupineHookArgs = {
start: boolean
accessKey: string
keywords: Array<PorcupineKeyword | string> | PorcupineKeyword | string
}

Type alias for the Hook Parameters

Parameters


PorcupineKeyword

type PorcupineKeyword = PorcupineKeywordCustom | PorcupineKeywordBuiltin;

Type alias for the Porcupine keywords which can be either PorcupineKeywordBuiltin or PorcupineKeywordCustom.


PorcupineKeywordBuiltin

type PorcupineKeywordBuiltin = {
builtin: string
sensitivity?: number
}

Type alias for the builtin keywords

Parameters

  • builtin: Name of a builtin keyword for the specific language.
  • sensitivity: Value in range [0,1] that trades off miss rate for false alarm. If not set 0.5 will be used.

PorcupineKeywordCustom

type PorcupineKeywordCustom = {
base64: string
custom: string
sensitivity?: number
}

Type alias for the custom keywords

Parameters

  • base64: Base64 representation of a trained Porcupine keyword.
  • custom: An arbitrary label that Picovoice reports when the detection occurs.
  • sensitivity: Value in range [0,1] that trades off miss rate for false alarm. If not set 0.5 will be used.


Issue with this doc? Please let us know.