Picovoice Platform
Microcontroller API
This document outlines how to use Picovoice platform on a microcontroller using the Picovoice C API.
pv_picovoice_t
Container representing the Picovoice engine.
pv_inference_t
Container representing inferred user intent. pv_inference_t
exposes the following immutable fields:
is_understood
is a flag indicating if the spoken command is understood.intent
is the inferred intent from the voice command. If the command is not understood then it's set toNULL
.num_slots
is the number of slots.slots
is a list of slot keys.values
is the corresponding slot values.
pv_inference_delete()
Destructor for pv_inference_t
. Should be called after completion of intent inference.
Parameters
inference
pv_inference_t * : Inference container.
pv_picovoice_init()
Create a Picovoice instance. Resources should be cleaned when you are done using
the pv_picovoice_delete()
function.
Parameters
access_key
char * : AccessKey obtained from Picovoice Console (https://console.picovoice.ai/).memory_size
int32_t : Memory size in bytes. The optimal size for given keyword and context models can be computed using pv_picovoice_get_min_memory_buffer_size()memory_buffer
void * : Memory; needs to be 8-byte aligned.keyword_model_size
int32_t : Size of keyword model in bytes.keyword_model
void * : Keyword model.porcupine_sensitivity
float : Wake word detection sensitivity. It should be a number within [0, 1]. A higher sensitivity results in fewer misses at the cost of increasing the false alarm rate.wake_word_callback
void (*)(void) : User-defined callback invoked upon detection of the wake phrase. The callback accepts no input arguments.context_model_size
int32_t : Size of the context in bytes.context_model
void * : Context model.rhino_sensitivity
float : Inference sensitivity. It should be a number within [0, 1]. A higher sensitivity value results in fewer misses at the cost of (potentially) increasing the erroneous inference rate.endpoint_duration_sec
float : 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.require_endpoint
bool : 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).inference_callback
void (*)(pv_inference_t
*) : User-defined callback invoked upon completion of intent inference. The callback accepts a single input argument of typepv_inference_t
.object
pv_picovoice_t * * : Constructed instance of Picovoice.
Returns
- pv_status_t : Returned status code.
pv_picovoice_get_min_memory_buffer_size()
Computes the minimum required memory buffer size, in bytes, for the given keyword and context model. A relatively large value for 'preliminary_memory_buffer' is suggested (e.g., 70 kilobytes). Then, 'pv_picovoice_init' can be called optimally passing a memory buffer with the size of 'min_memory_buffer_size'.
Parameters
preliminary_memory_size
int32_t : Memory size in bytes.preliminary_memory_buffer
void * : Memory; needs to be 8-byte aligned.keyword_model_size
int32_t : Size of keyword model in bytes.keyword_model
void * : Keyword model.context_model_size
int32_t : Size of the context in bytes.context_model
void * : Context model.min_memory_buffer_size
int32_t * : minimum required memory buffer size in bytes.
Returns
- pv_status_t : Returned status code.
pv_picovoice_delete()
Releases resources acquired by Picovoice.
Parameters
object
pv_picovoice_t * : Picovoice object.
pv_picovoice_process()
Processes a frame of the incoming audio stream. Upon detection of wake word and completion of follow-on command
inference invokes user-defined callbacks. The number of samples per frame can be attained by
calling pv_picovoice_frame_length()
. The incoming audio needs to have a sample rate
equal to pv_sample_rate()
and be 16-bit linearly-encoded. Picovoice operates on single-channel
audio.
Parameters
object
pv_picovoice_t * : Picovoice object.pcm
int16_t : A frame of audio samples.
Returns
- pv_status_t : Returned status code.
pv_picovoice_version()
Getter for version.
Returns
- char * : Picovoice version.
pv_picovoice_frame_length()
Getter for number of audio samples per frame.
Returns
- int32_t : Frame length.
pv_picovoice_context_info()
Getter for context information.
Parameters
object
pv_picovoice_t * : Picovoice object.context
char * * : A frame of audio samples.
Returns
- int32_t : Returned status code.
pv_sample_rate()
Audio sample rate accepted by Picovoice.
Returns
- int32_t : Sample rate.
pv_status_t
Status code enum.
pv_status_to_string()
Parameters
- int32_t : Returned status code.
Returns
- char * : String representation.
pv_get_error_stack()
If a function returns a failure (any pv_status_t other than PV_STATUS_SUCCESS
), this function can be
called
to get a series of error messages related to the failure. This function can only be called only once per
failure status on another function. The memory for message_stack
must be freed using pv_free_error_stack
.
Regardless of the return status of this function, if message_stack
is not NULL
, then message_stack
contains valid memory. However, a failure status on this function indicates that future error messages
may not be reported.
Parameters
message_stack
const char * * * : Array of messages relating to the failure. Messages are NULL terminated strings. The array and messages must be freed usingpv_free_error_stack()
.message_stack_depth
int32_t * : The number of messages in themessage_stack
array.
pv_free_error_stack()
This function frees the memory used by error messages allocated by pv_get_error_stack()
.
Parameters
message_stack
const char * * * : Array of messages relating to the failure.