mcuPorcupine Wake Word Engine - Microcontroller API

This document outlines how to use the Porcupine wake word engine on a microcontroller.

Integration

Porcupine is implemented in ANSI C and therefore can be directly linked to embedded C projects. Its public header file contains relevant information. An instance of the Porcupine object can be constructed as follows.

#define MEMORY_BUFFER_SIZE ...
uint8_t memory_buffer[MEMORY_BUFFER_SIZE] __attribute__((aligned(16)));
const uint8_t keyword_array[] = {...};
const int32_t keyword_model_sizes = sizeof(keyword_array);
const void *keyword_models = keyword_array;
const float sensitivity = 0.5f;
pv_porcupine_t *handle = NULL;
const pv_status_t status = pv_porcupine_init(
MEMORY_BUFFER_SIZE,
memory_buffer,
1,
&keyword_model_sizes,
&keyword_models,
&sensitivity,
&handle);
if (status != PV_STATUS_SUCCESS) {
// error handling logic
}

Sensitivity is the parameter that enables developers to trade miss rate for false alarm. It is a floating-point number within [0, 1]. A higher sensitivity reduces miss rate (false reject rate) at cost of increased false alarm rate.

Now the handle can be used to monitor incoming audio stream. Porcupine accepts single channel, 16-bit PCM audio. The sample rate can be retrieved using pv_sample_rate(). Finally, Picovoice accepts input audio in consecutive chunks (aka frames) the length of each frame can be retrieved using pv_porcupine_frame_length().

extern const int16_t *get_next_audio_frame(void);
while (true) {
const int16_t *pcm = get_next_audio_frame();
int32_t keyword_index;
const pv_status_t status = pv_porcupine_process(handle, pcm, &keyword_index);
if (status != PV_STATUS_SUCCESS) {
// error handling logic
}
if (keyword_index != -1) {
// detection event logic/callback
}
}

Finally, when done be sure to release the acquired resources.

pv_porcupine_delete(handle);

Additionally, there are demo projects on the Picovoice GitHub repository for some development boards.


Issue with this doc? Please let us know.