mcuPicovoice Platform - Microcontroller API

This document outlines how to use Picovoice platform on a microcontroller using the Picovoice C API.


pv_picovoice_t

typedef struct pv_picovoice pv_picovoice_t;

Container representing the Picovoice engine.


pv_inference_t

typedef struct {
bool is_understood;
const char *intent;
int32_t num_slots;
const char **slots;
const char **values;
} pv_inference_t;

Container representing inferred user intent. pv_inference_t exposes the following immutable fields:

  1. is_understood is a flag indicating if the spoken command is understood.
  2. intent is the inferred intent from the voice command. If the command is not understood then it's set to NULL.
  3. num_slots is the number of slots.
  4. slots is a list of slot keys.
  5. values is the corresponding slot values.

pv_inference_delete()

void pv_inference_delete(pv_inference_t *inference);

Destructor for pv_inference_t. Should be called after completion of intent inference.

Parameters


pv_picovoice_init()

pv_status_t pv_picovoice_init(
const char *access_key,
int32_t memory_size,
void *memory_buffer,
int32_t keyword_model_size,
const void *keyword_model,
float porcupine_sensitivity,
void (*wake_word_callback)(void),
int32_t context_model_size,
const void *context_model,
float rhino_sensitivity,
bool require_endpoint,
void (*inference_callback)(pv_inference_t *),
pv_picovoice_t **object
);

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.
  • require_endpoint bool : If set to true, Rhino requires an endpoint (chunk of silence) before finishing inference.
  • inference_callback void (*)(pv_inference_t *) : User-defined callback invoked upon completion of intent inference. The callback accepts a single input argument of type pv_inference_t.
  • object pv_picovoice_t * * : Constructed instance of Picovoice.

Returns


pv_picovoice_get_min_memory_buffer_size()

pv_status_t pv_picovoice_get_min_memory_buffer_size(
int32_t preliminary_memory_size,
void *preliminary_memory_buffer,
int32_t keyword_model_size,
const void *keyword_model,
int32_t context_model_size,
const void *context_model,
int32_t *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_picovoice_delete()

void pv_picovoice_delete(pv_picovoice_t *object);

Releases resources acquired by Picovoice.

Parameters


pv_picovoice_process()

pv_status_t pv_picovoice_process(pv_picovoice_t *object, const int16_t *pcm);

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_picovoice_version()

const char *pv_picovoice_version(void);

Getter for version.

Returns

  • char * : Picovoice version.

pv_picovoice_frame_length()

int32_t pv_picovoice_frame_length(void);

Getter for number of audio samples per frame.

Returns

  • int32_t : Frame length.

pv_picovoice_context_info()

pv_status_t pv_picovoice_context_info(const pv_picovoice_t *object, const char **context);

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()

int32_t pv_sample_rate(void);

Audio sample rate accepted by Picovoice.

Returns

  • int32_t : Sample rate.

pv_status_t

typedef enum {
PV_STATUS_SUCCESS = 0,
PV_STATUS_OUT_OF_MEMORY,
PV_STATUS_IO_ERROR,
PV_STATUS_INVALID_ARGUMENT,
PV_STATUS_STOP_ITERATION,
PV_STATUS_KEY_ERROR,
PV_STATUS_INVALID_STATE,
PV_STATUS_RUNTIME_ERROR,
PV_STATUS_ACTIVATION_ERROR,
PV_STATUS_ACTIVATION_LIMIT_REACHED,
PV_STATUS_ACTIVATION_THROTTLED,
PV_STATUS_ACTIVATION_REFUSED
} pv_status_t;

Status code enum.


pv_status_to_string()

const char *pv_status_to_string(pv_status_t status);

Parameters

  • int32_t : Returned status code.

Returns

  • char * : String representation.


Issue with this doc? Please let us know.