Porcupine - 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, wherexx
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 thewebVoiceProcessor
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 internalwebVoiceProcessor
object.start
() => void : A method to start processing the audio.pause
() => void : A method to stop processing the audio.setKeywordEventHandler
(label: string) => void : Setter forkeywordEventHandler
PorcupineHookArgs
type PorcupineHookArgs = {start: booleanaccessKey: stringkeywords: Array<PorcupineKeyword | string> | PorcupineKeyword | string}
Type alias for the Hook Parameters
Parameters
start
boolean : If set totrue
, the Porcupine Hook immediately starts the microphone upon initialization.accessKey
string : AccessKey obtained from Picovoice Console.keywords
Array<PorcupineKeyword | string> : An array of keywords to listen for. Keywords can be either PorcupineKeywordBuiltin or PorcupineKeywordCustom.
PorcupineKeyword
type PorcupineKeyword = PorcupineKeywordCustom | PorcupineKeywordBuiltin;
Type alias for the Porcupine keywords which can be either PorcupineKeywordBuiltin or PorcupineKeywordCustom.
PorcupineKeywordBuiltin
type PorcupineKeywordBuiltin = {builtin: stringsensitivity?: 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: stringcustom: stringsensitivity?: 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.