imxrt1050/imxrt1050-evkb/source/main_multi.c
Go to the documentation of this file.
1 /*
2  Copyright 2020-2021 Picovoice Inc.
3 
4  You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
5  file accompanying this source.
6 
7  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8  an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9  specific language governing permissions and limitations under the License.
10 */
11 
12 #include <stdbool.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 
16 #include "pv_porcupine_mcu.h"
17 
18 #include "pv_audio_rec.h"
19 #include "pv_params.h"
20 #include "pv_imxrt1050.h"
21 
22 #define MEMORY_BUFFER_SIZE (50 * 1024)
23 
24 static const char* ACCESS_KEY = ... //AccessKey string obtained from Picovoice Console (https://picovoice.ai/console/)
25 
26 static int8_t memory_buffer[MEMORY_BUFFER_SIZE] __attribute__((aligned(16)));
27 
28 static const int32_t NUM_KEYWORDS = 4;
29 static const int32_t KEYWORD_MODEL_SIZES[] = {
30  sizeof(DEFAULT_KEYWORD_ARRAY),
31  sizeof(PICOVOICE_KEYWORD_ARRAY),
32  sizeof(BUMBLEBEE_KEYWORD_ARRAY),
33  sizeof(ALEXA_KEYWORD_ARRAY)
34 };
35 static const void *KEYWORD_MODELS[] = {
36  DEFAULT_KEYWORD_ARRAY,
37  PICOVOICE_KEYWORD_ARRAY,
38  BUMBLEBEE_KEYWORD_ARRAY,
39  ALEXA_KEYWORD_ARRAY
40 };
41 static const float SENSITIVITIES[] = {
42  0.75f,
43  0.75f,
44  0.75f,
45  0.75f
46 };
47 
48 static const char *KEYWORDS_NAME[] = {
49  "Porcupine",
50  "Picovoice",
51  "Bumblebee",
52  "Alexa"
53 };
54 
55 static void wake_word_callback(int32_t keyword_index) {
56  printf("[wake word] %s\n", KEYWORDS_NAME[keyword_index]);
57 }
58 
59 static void error_handler(void) {
60  while(true);
61 }
62 
63 
64 int main(void) {
65 
66  pv_status_t status = pv_board_init();
67  if (status != PV_STATUS_SUCCESS) {
68  error_handler();
69  }
70 
71  status = pv_message_init();
72  if (status != PV_STATUS_SUCCESS) {
73  error_handler();
74  }
75 
76  const uint8_t *board_uuid = pv_get_uuid();
77  printf("UUID: ");
78  for (uint32_t i = 0; i < pv_get_uuid_size(); i++) {
79  printf(" %.2x", board_uuid[i]);
80  }
81  printf("\r\n");
82 
83  status = pv_audio_rec_init();
84  if (status != PV_STATUS_SUCCESS) {
85  printf("Audio init failed with '%s'", pv_status_to_string(status));
86  error_handler();
87  }
88 
89  status = pv_audio_rec_start();
90  if (status != PV_STATUS_SUCCESS) {
91  printf("Recording audio failed with '%s'", pv_status_to_string(status));
92  error_handler();
93  }
94 
95  pv_porcupine_t *handle = NULL;
96 
97  status = pv_porcupine_init(
98  ACCESS_KEY,
100  memory_buffer,
101  NUM_KEYWORDS,
105  &handle);
106 
107  if (status != PV_STATUS_SUCCESS) {
108  printf("Picovoice init failed with '%s'", pv_status_to_string(status));
109  error_handler();
110  }
111 
112  while (true) {
113  const int16_t *buffer = pv_audio_rec_get_new_buffer();
114  if (buffer) {
115  int32_t keyword_index;
116  const pv_status_t status = pv_porcupine_process(handle, buffer, &keyword_index);
117  if (status != PV_STATUS_SUCCESS) {
118  printf("Porcupine process failed with '%s'", pv_status_to_string(status));
119  error_handler();
120  }
121  if (keyword_index != -1) {
122  wake_word_callback(keyword_index);
123  }
124  }
125 
126  }
127  pv_board_deinit();
129  pv_porcupine_delete(handle);
130 }
KEYWORD_MODEL_SIZES
static const int32_t KEYWORD_MODEL_SIZES[]
Definition: imxrt1050/imxrt1050-evkb/source/main_multi.c:29
pv_audio_rec_start
pv_status_t pv_audio_rec_start(void)
Definition: imxrt1050/imxrt1050-evkb/source/pv_audio_rec.c:186
pv_porcupine_init
PV_API pv_status_t pv_porcupine_init(const char *access_key, const char *model_path, int32_t num_keywords, const char *const *keyword_paths, const float *sensitivities, pv_porcupine_t **object)
NULL
#define NULL
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/thirdparty/resample.c:92
pv_board_deinit
void pv_board_deinit(void)
Definition: pv_imxrt1050.c:74
pv_get_uuid
const uint8_t * pv_get_uuid(void)
Definition: pv_imxrt1050.c:31
pv_porcupine_process
PV_API pv_status_t pv_porcupine_process(pv_porcupine_t *object, const int16_t *pcm, int32_t *keyword_index)
MEMORY_BUFFER_SIZE
#define MEMORY_BUFFER_SIZE
Definition: imxrt1050/imxrt1050-evkb/source/main_multi.c:22
SENSITIVITIES
static const float SENSITIVITIES[]
Definition: imxrt1050/imxrt1050-evkb/source/main_multi.c:41
pv_audio_rec_get_new_buffer
const int16_t * pv_audio_rec_get_new_buffer(void)
Definition: imxrt1050/imxrt1050-evkb/source/pv_audio_rec.c:202
PV_STATUS_SUCCESS
@ PV_STATUS_SUCCESS
Definition: porcupine/include/picovoice.h:34
main
int main(void)
Definition: imxrt1050/imxrt1050-evkb/source/main_multi.c:64
pv_status_t
pv_status_t
Definition: porcupine/include/picovoice.h:33
error_handler
static void error_handler(void)
Definition: imxrt1050/imxrt1050-evkb/source/main_multi.c:59
pv_board_init
pv_status_t pv_board_init(void)
Definition: pv_imxrt1050.c:39
KEYWORDS_NAME
static const char * KEYWORDS_NAME[]
Definition: imxrt1050/imxrt1050-evkb/source/main_multi.c:48
pv_porcupine_delete
PV_API void pv_porcupine_delete(pv_porcupine_t *object)
NUM_KEYWORDS
static const int32_t NUM_KEYWORDS
Definition: imxrt1050/imxrt1050-evkb/source/main_multi.c:28
pv_get_uuid_size
const uint32_t pv_get_uuid_size(void)
Definition: pv_imxrt1050.c:35
pv_porcupine_mcu.h
ACCESS_KEY
static const char * ACCESS_KEY
Definition: imxrt1050/imxrt1050-evkb/source/main_multi.c:24
pv_porcupine_t
struct pv_porcupine pv_porcupine_t
Definition: include/pv_porcupine.h:33
pv_message_init
pv_status_t pv_message_init(void)
Definition: pv_imxrt1050.c:67
wake_word_callback
static void wake_word_callback(int32_t keyword_index)
Definition: imxrt1050/imxrt1050-evkb/source/main_multi.c:55
__attribute__
__attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value)
Reverse byte order (16 bit)
Definition: imxrt1050/imxrt1050-evkb/CMSIS/cmsis_armcc.h:492
KEYWORD_MODELS
static const void * KEYWORD_MODELS[]
Definition: imxrt1050/imxrt1050-evkb/source/main_multi.c:35
pv_audio_rec_deinit
void pv_audio_rec_deinit(void)
Definition: imxrt1050/imxrt1050-evkb/source/pv_audio_rec.c:216
pv_status_to_string
const PV_API char * pv_status_to_string(pv_status_t status)
pv_audio_rec_init
pv_status_t pv_audio_rec_init(void)
Definition: imxrt1050/imxrt1050-evkb/source/pv_audio_rec.c:125
pv_imxrt1050.h


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:13:56