reactPicovoice - React API

API Reference for the Picovoice React SDK.


usePicovoice()

function usePicovoice(
picovoiceWorkerFactory: PicovoiceWorkerFactory | null,
picovoiceHookArgs: PicovoiceHookArgs | null,
keywordCallback: (keywordLabel: string) => void,
inferenceCallback: (inference: RhinoInference) => void
)

React Hook for Picovoice.

Parameters

  • picovoiceWorkerFactory PicovoiceWorkerFactory : The language-specific worker factory, imported as { PicovoiceWorkerFactory } from the @picovoice/picovoice-web-xx-worker series of packages, where xx is the two-letter language code.
  • picovoiceHookArgs PicovoiceHookArgs : usePicovoice Hook Parameters.
  • keywordEventHandler (label: string) => void : User-defined callback function invoked upon detection of the keywords.
  • inferenceCallback (inference: RhinoInferenceFinalized) => void : User-defined callback invoked upon completion of intent inference.

Returns

  • contextInfostring : Context information.
  • 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.
  • engine EngineControlType : A state indicating the current active engine.
  • 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.

PicovoiceHookArgs

type PicovoiceHookArgs = {
accessKey: string;
porcupineKeyword: PorcupineKeyword;
rhinoContext: RhinoContext;
requireEndpoint?: boolean;
start?: boolean;
};

Type alias for the Hook Parameters

Parameters

  • accessKey string : AccessKey obtained from Picovoice Console.
  • porcupineKeyword PorcupineKeyword : An array of keywords to listen for. Keywords can be either PorcupineKeywordBuiltin or PorcupineKeywordCustom.
  • rhinoContext RhinoContext : The context to instantiate
  • requireEndpoint boolean : If set to true, Rhino requires an endpoint (chunk of silence) before finishing inference.
  • start boolean : If set to true, the Porcupine Hook immediately starts the microphone upon initialization.

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 string : Name of a builtin keyword for the specific language.
  • sensitivity number : 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 string : Base64 representation of a trained Porcupine keyword.
  • custom string : An arbitrary label that Picovoice reports when the detection occurs.
  • sensitivity number : Value in range [0,1] that trades off miss rate for false alarm. If not set 0.5 will be used.

RhinoContext

type RhinoContext = {
base64: string;
sensitivity?: number;
};

Type alias for the Rhino context

Parameters

  • base64 string : Base64 representation of a trained Rhino context (.rhn file)
  • sensitivity number : Value in range [0,1] that trades off miss rate for false alarm. If not set 0.5 will be used.

RhinoInference

type RhinoInferenceFinalized = {
isFinalized: boolean;
isUnderstood?: boolean;
intent?: string;
slots?: Record<string, string>;
};

Type alias for the Rhino inference Parameters

  • isFinalized: Indicates whether Rhino has concluded an inference.
  • isUnderstood boolean : Indicates whether the intent was understood.
  • intent string : The name of the intent.
  • slots Record : Map of the slot variables and values extracted from the utterance.

EngineControlType

type EngineControlType = 'ppn' | 'rhn';

Type alias for the active engine


Issue with this doc? Please let us know.