Picovoice Platform
Web API
API Reference for the Picovoice Web SDK (npmjs).
Picovoice
Class for using Picovoice Platform on the main thread.
Picovoice.create()
Creates an instance of Picovoice
.
Parameters
accessKey
string : AccessKey obtained from Picovoice Console.keyword
PorcupineKeyword : A Porcupine keyword. Can be provided as a built-in, base64 or a hosted.ppn
file.wakeWordCallback
DetectionCallback : User-defined callback to run after a keyword is detected.porcupineModel
PorcupineModel : Contains the model parameters that are used to initialize the Porcupine engine. Model can be encoded in base64 or can be stored in a.pv
file in a public directory.context
RhinoContext : A Rhino context. Can be provided as a base64 or a hosted.rhn
file.inferenceCallback
InferenceCallback : User-defined callback invoked when Rhino has made an inference.rhinoModel
RhinoModel : Contains the model parameters that are used to initialize the Rhino engine. Model can be encoded in base64 or can be stored in a.pv
file in a public directory.options
PicovoiceOptions : Optional configuration arguments.
Returns
Picovoice
: An instance of the Picovoice platform.
Picovoice.process()
Processes a frame of audio and invokes user-provided callbacks if the keyword is detected or an intent is inferred. The required sample rate can be retrieved from 'sampleRate' and the length of frame (number of audio samples per frame) can be retrieved from 'frameLength'. The audio must be single-channel and 16-bit linearly-encoded.
Results are returned via the user-defined wakeWordCallback
and inferenceCallback
provided when creating Picovoice
.
Parameters
pcm
Int16Array : A frame of audio.
Picovoice.reset()
Resets the internal Picovoice state.
Picovoice.release()
Releases resources acquired by the Picovoice Web SDK.
Picovoice.contextInfo
Get the Rhino context info. Shows the list of intents, which expressions map to those intents, as well as slots and their possible values.
Picovoice.frameLength
Get number of samples per frame required by Picovoice.
Picovoice.sampleRate
Get audio sample rate required by Picovoice.
Picovoice.version
Get Picovoice SDK version.
PicovoiceOptions
Optional parameters for Picovoice.
processErrorCallback
(error: string) => void : User-defined callback invoked if any error happens while processing the audio stream. Its only input argument is the error message. NOTE: This is only used by thepicovoice-web
package.endpointDurationSec
number : 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
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).
PicovoiceWorker
A class for using Picovoice Platform on a worker thread.
PicovoiceWorker.create()
Creates an instance of PicovoiceWorker
.
Parameters
accessKey
string : AccessKey obtained from Picovoice Console.keyword
PorcupineKeyword : A Porcupine keyword. Can be provided as a built-in, base64 or a hosted.ppn
file.wakeWordCallback
DetectionCallback : User-defined callback to run after a keyword is detected.porcupineModel
PorcupineModel : Contains the model parameters that are used to initialize the Porcupine engine. Model can be encoded in base64 or can be stored in a.pv
file in a public directory.context
RhinoContext : A Rhino context. Can be provided as a base64 or a hosted.rhn
file.inferenceCallback
InferenceCallback : User-defined callback invoked when Rhino has made an inference.rhinoModel
RhinoModel : Contains the model parameters that are used to initialize the Rhino engine. Model can be encoded in base64 or can be stored in a.pv
file in a public directory.options
PicovoiceOptions : Optional configuration arguments.
Returns
PicovoiceWorker
: An instance of the Picovoice platform on a worker thread.
PicovoiceWorker.process()
Processes a frame of audio. The required sample rate can be retrieved from .sampleRate
and the length of frame (number of audio samples per frame) can be retrieved from .frameLength
The audio needs to be 16-bit linearly-encoded. Picovoice operates on single-channel audio.
Results are returned via the user-defined wakeWordCallback
and inferenceCallback
that are provided when creating a PicovoiceWorker
.
Parameters
pcm
Int16Array : A frame of audio.
PicovoiceWorker.reset()
Resets the internal Picovoice state.
PicovoiceWorker.release()
Releases resources acquired by the Picovoice Web SDK.
PicovoiceWorker.terminate()
Force terminates the instance of PicovoiceWorker
.
PicovoiceWorker.contextInfo
Get the Rhino context info. Shows the list of intents, which expressions map to those intents, as well as slots and their possible values.
PicovoiceWorker.frameLength
Get number of samples per frame required by Picovoice.
PicovoiceWorker.sampleRate
Get audio sample rate required by Picovoice.
PicovoiceWorker.version
Get Picovoice SDK version.
PicovoiceError
Error thrown if an error occurs within Picovoice
SDK.
Errors: