Picovoice Platform
React Native API
API Reference for the React Native Picovoice SDK (npm)
Picovoice
Class for the Picovoice platform.
Picovoice.create()
Picovoice
constructor.
Parameters
accessKey
string : AccessKey obtained from Picovoice Console.keywordPath
string : Path to Porcupine keyword file (.ppn
). Can be relative to the assets/resource folder or an absolute path to the file on device.wakeWordCallback
WakeWordCallback : User-defined callback invoked upon detection of the wake phrase.contextPath
string : Path to Rhino context file (.rhn
). Can be relative to the assets/resource folder or an absolute path to the file on device.inferenceCallback
InferenceCallback : User-defined callback invoked upon completion of intent inference.porcupineSensitivity
number : Optional. Wake word detection sensitivity. It should be a number within [0, 1].rhinoSensitivity
number : Optional. Inference sensitivity. It should be a number within [0, 1].porcupineModelPath
string : Optional. Path to the file containing Porcupine's model parameters (.pv
). Can be relative to the assets/resource folder or an absolute path to the file on device.rhinoModelPath
string : Optional. Path to the file containing Rhino's model parameters (.pv
). Can be relative to the assets/resource folder or an absolute path to the file on device.endpointDurationSec
number : Optional. Endpoint duration in seconds. An endpoint is a chunk of silence at the end of an utterance that marks the end of spoken command. It should be a positive number within [0.5, 5]. A lower endpoint duration reduces delay and improves responsiveness. A higher endpoint duration assures Rhino doesn't return inference pre-emptively in case the user pauses before finishing the request.requireEndpoint
boolean : Optional. If set totrue
, Rhino requires an endpoint (a chunk of silence) after the spoken command. If set tofalse
, Rhino tries to detect silence, but if it cannot, it still will provide inference regardless. Set tofalse
only if operating in an environment with overlapping speech (e.g. people talking in the background).
Returns
Promise<Picovoice>
: An instance of Picovoice platform.
Picovoice.delete()
Releases resources acquired by Picovoice
.
Picovoice.contextInfo()
Getter for Rhino context info.
Returns
string | undefined
: Gets the source of the Rhino context in YAML format.
Picovoice.frameLength
Getter for number of audio samples per frame.
Returns
number
: Number of audio samples per frame.
Picovoice.sampleRate
Getter for audio sample rate accepted by Picovoice.
Returns
number
: Audio sample rate accepted by Picovoice.
Picovoice.version
Getter for version.
Returns
string
: CurrentPicovoice
version.
Picovoice.porcupineVersion
Getter for Porcupine version.
Returns
string | undefined
: Current Porcupine version.
Picovoice.rhinoVersion
Getter for Rhino version.
Returns
string | undefined
: Current Rhino version.
Picovoice.process()
Processes a frame of the incoming audio stream. Upon detection of wake word and completion of follow-on inference invokes user-defined callbacks. The number of samples per frame can be attained by calling .frameLength
. The incoming audio needs to have a sample rate equal to .sampleRate
and be 16-bit linearly-encoded. Picovoice operates on single-channel audio.
Parameters
frame
number[] : A frame of audio samples.
Picovoice.reset()
Resets the internal state of Picovoice. It should be called before processing a new stream of audio or when Picovoice was stopped whilst processing a stream of audio.
PicovoiceError
Exception thrown if an error occurs within Picovoice
platform.
Exceptions:
PicovoiceManager
High-level React Native API for Picovoice
platform. It handles recording audio from the microphone, processes it in real-time using Picovoice, and notifies the client when a keyword has been detected or an inference has been completed.
PicovoiceManager.create()
PicovoiceManager
constructor.
Parameters
accessKey
string : AccessKey obtained from Picovoice Console.keywordPath
string : Path to Porcupine keyword file (.ppn
). Can be relative to the assets/resource folder or an absolute path to the file on device.wakeWordCallback
WakeWordCallback : User-defined callback invoked upon detection of the wake phrase.contextPath
string : Path to file containing Rhino context parameters (.rhn
). Can be relative to the assets/resource folder or an absolute path to the file on device.inferenceCallback
InferenceCallback : User-defined callback invoked upon completion of intent inference.processErrorCallback
ProcessErrorCallback : Optional. Reports errors that are encountered while the engine is processing audio.porcupineSensitivity
number : Optional. Wake word detection sensitivity. It should be a number within [0, 1].rhinoSensitivity
number : Optional. Inference sensitivity. It should be a number within [0, 1].porcupineModelPath
string : Optional. Path to the file containing Porcupine's model parameters (.pv
). Can be relative to the assets/resource folder or an absolute path to the file on device.rhinoModelPath
string : Optional. Path to the file containing Rhino's model parameters (.pv
). Can be relative to the assets/resource folder or an absolute path to the file on device.endpointDurationSec
number : Optional. Endpoint duration in seconds. An endpoint is a chunk of silence at the end of an utterance that marks the end of spoken command. It should be a positive number within [0.5, 5]. A lower endpoint duration reduces delay and improves responsiveness. A higher endpoint duration assures Rhino doesn't return inference pre-emptively in case the user pauses before finishing the request.requireEndpoint
boolean : Optional. If set totrue
, Rhino requires an endpoint (a chunk of silence) after the spoken command. If set tofalse
, Rhino tries to detect silence, but if it cannot, it still will provide inference regardless. Set tofalse
only if operating in an environment with overlapping speech (e.g. people talking in the background).
Returns
Promise<PicovoiceManager>
: An instance of PicovoiceManager.
PicovoiceManager.start()
Starts recording audio from the microphone and passed it to the Picovoice Platform.
PicovoiceManager.stop()
Stops recording audio from the microphone.
PicovoiceManager.reset()
Resets the internal state of PicovoiceManager. It can be called to return to the wake word detection state before an inference has completed.
PicovoiceManager.delete()
Releases native resources that were allocated to PicovoiceManager.
PicovoiceManager.contextInfo
Getter for Rhino context info.
Returns
string | undefined
: Gets the source of the Rhino context in YAML format.
InferenceCallback
Callback interface invoked when an inference is finished. The callback takes a single parameter of type RhinoInference
.
WakeWordCallback
Callback interface invoked when the keyword is detected.
ProcessErrorCallback
Callback interface invoked when an error occurs while processing audio.