cPicovoice Platform - C API

API Reference for the Picovoice C SDK.


pv_picovoice_t

typedef struct pv_picovoice pv_picovoice_t;

Container representing the Picovoice platform.


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,
const char *porcupine_model_path,
const char *keyword_path,
float porcupine_sensitivity,
void (*wake_word_callback)(void),
const char *rhino_model_path,
const char *context_path,
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.
  • porcupine_model_path char * : Absolute path to the file containing Porcupine model parameters (.pv).
  • keyword_path char * : Absolute path to Porcupine's keyword model file (.ppn).
  • 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.
  • rhino_model_path char * : Absolute path to the file containing Rhino model parameters (.pv).
  • context_path char * : Absolute path to file containing context parameters (.rhn). A context represents the set of expressions (spoken commands), intents, and intent arguments (slots) within a domain of interest.
  • 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_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


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.