Porcupine Wake Word
C API
API Reference for the Porcupine C SDK.
pv_porcupine_t
Container representing the Porcupine wake word engine.
pv_porcupine_init()
Creates a Porcupine instance. Resources should be cleaned when you are done using the pv_porcupine_delete() function.
Parameters
access_keyconst char * : AccessKey obtained from Picovoice Console.model_pathconst char * : Absolute path to the file containing model parameters (.pv).devicechar * : String representation of the device (e.g., CPU or GPU) to use. If set tobest, the most suitable device is selected automatically. If set togpu, the engine uses the first available GPU device. To select a specific GPU device, set this argument togpu:${GPU_INDEX}, where${GPU_INDEX}is the index of the target GPU. If set tocpu, the engine will run on the CPU with the default number of threads. To specify the number of threads, set this argument tocpu:${NUM_THREADS}, where${NUM_THREADS}is the desired number of threads.num_keywordsint32_t : Number of keywords to monitor.keyword_pathsconst char *const * : Absolute paths to keyword model files (.ppn).sensitivitiesfloat * : Sensitivities for detecting keywords. Each value should be a number within [0, 1]. A higher sensitivity results in fewer misses at the cost of increasing the false alarm rate.objectpv_porcupine_t * * : Constructed instance of Porcupine.
Returns
- pv_status_t : Returned status code.
pv_porcupine_delete()
Releases resources acquired by Porcupine.
Parameters
objectpv_porcupine_t * : Picovoice object.
pv_porcupine_process()
Processes a frame of the incoming audio stream and emits the detection result. The number of samples per frame can be
attained by calling pv_porcupine_frame_length(). The incoming audio needs to have a
sample rate equal to pv_sample_rate() and be 16-bit linearly-encoded. Porcupine operates on
single-channel audio.
Parameters
objectpv_porcupine_t * : Porcupine object.pcmint16_t : A frame of audio samples.keyword_indexint32_t * : Index of observed keyword at the end of the current frame. Indexing is 0-based and matches the ordering of keyword models provided to pv_porcupine_init(). If no keyword is detected then it is set to -1.
Returns
- pv_status_t : Returned status code.
pv_porcupine_version()
Getter for version.
Returns
- char * : Porcupine version.
pv_porcupine_frame_length()
Getter for number of audio samples per frame.
Returns
- int32_t : Frame length.
pv_porcupine_list_hardware_devices()
Gets a list of hardware devices that can be specified when calling pv_porcupine_init().
Parameters
hardware_devicesconst char * * * : Array of available hardware devices. Devices are NULL terminated strings. The array must be freed usingpv_porcupine_free_hardware_devices().num_hardware_devicesint32_t * : The number of devices in thehardware_devicesarray.
Returns
- pv_status_t : Returned status code.
pv_porcupine_free_hardware_devices()
This function frees the memory allocated by pv_porcupine_list_hardware_devices().
Parameters
hardware_devicesconst char * * * : Array of available hardware devices allocated bypv_porcupine_list_hardware_devices().num_hardware_devicesint32_t * : The number of devices in thehardware_devicesarray.
pv_sample_rate()
Audio sample rate accepted by Porcupine.
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_stackconst 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_depthint32_t * : The number of messages in themessage_stackarray.
Returns
- pv_status_t : Returned status code.
pv_free_error_stack()
This function frees the memory used by error messages allocated by pv_get_error_stack().
Parameters
message_stackconst char * * * : Array of messages relating to the failure.