stm32f469/stm32f469i-disco/Src/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 "stm32469i_discovery.h"
17 
18 #include "pv_porcupine_mcu.h"
19 
20 #include "pv_audio_rec.h"
21 #include "pv_params.h"
22 #include "pv_stm32f469.h"
23 
24 #define MEMORY_BUFFER_SIZE (50 * 1024)
25 
26 static const char* ACCESS_KEY = ... //AccessKey string obtained from Picovoice Console (https://picovoice.ai/console/)
27 
28 static int8_t memory_buffer[MEMORY_BUFFER_SIZE] __attribute__((aligned(16)));
29 
30 static const int32_t NUM_KEYWORDS = 4;
31 static const int32_t KEYWORD_MODEL_SIZES[] = {
32  sizeof(DEFAULT_KEYWORD_ARRAY),
33  sizeof(PICOVOICE_KEYWORD_ARRAY),
34  sizeof(BUMBLEBEE_KEYWORD_ARRAY),
35  sizeof(ALEXA_KEYWORD_ARRAY)
36 };
37 static const void *KEYWORD_MODELS[] = {
38  DEFAULT_KEYWORD_ARRAY,
39  PICOVOICE_KEYWORD_ARRAY,
40  BUMBLEBEE_KEYWORD_ARRAY,
41  ALEXA_KEYWORD_ARRAY
42 };
43 static const float SENSITIVITIES[] = {
44  0.75f,
45  0.75f,
46  0.75f,
47  0.75f
48 };
49 
50 static const char *KEYWORDS_NAME[] = {
51  "Porcupine",
52  "Picovoice",
53  "Bumblebee",
54  "Alexa"
55 };
56 
57 static void wake_word_callback(int32_t keyword_index) {
58  printf("[wake word] %s\n", KEYWORDS_NAME[keyword_index]);
59  BSP_LED_On(keyword_index);
60 }
61 
62 static void error_handler(void) {
63  while(true);
64 }
65 
66 int main(void) {
67 
68  pv_status_t status = pv_board_init();
69  if (status != PV_STATUS_SUCCESS) {
70  error_handler();
71  }
72 
73  status = pv_message_init();
74  if (status != PV_STATUS_SUCCESS) {
75  error_handler();
76  }
77 
78  const uint8_t *board_uuid = pv_get_uuid();
79  printf("UUID: ");
80  for (uint32_t i = 0; i < pv_get_uuid_size(); i++) {
81  printf(" %.2x", board_uuid[i]);
82  }
83  printf("\r\n");
84 
85  status = pv_audio_rec_init();
86  if (status != PV_STATUS_SUCCESS) {
87  printf("Audio init failed with '%s'", pv_status_to_string(status));
88  error_handler();
89  }
90 
91  status = pv_audio_rec_start();
92  if (status != PV_STATUS_SUCCESS) {
93  printf("Recording audio failed with '%s'", pv_status_to_string(status));
94  error_handler();
95  }
96 
97  pv_porcupine_t *handle = NULL;
98 
99  status = pv_porcupine_init(
100  ACCESS_KEY,
102  memory_buffer,
103  NUM_KEYWORDS,
107  &handle);
108 
109  if (status != PV_STATUS_SUCCESS) {
110  printf("Porcupine init failed with '%s'", pv_status_to_string(status));
111  error_handler();
112  }
113 
114  uint32_t frame_number = 0;
115  while (true) {
116  const int16_t *buffer = pv_audio_rec_get_new_buffer();
117  if (buffer) {
118  int32_t keyword_index;
119  const pv_status_t status = pv_porcupine_process(handle, buffer, &keyword_index);
120  if (status != PV_STATUS_SUCCESS) {
121  printf("Porcupine process failed with '%s'", pv_status_to_string(status));
122  error_handler();
123  }
124  if (keyword_index != -1) {
125  frame_number = 0;
126  wake_word_callback(keyword_index);
127  }
128  if (frame_number++ > 20) {
129  BSP_LED_Off(LED1);
130  BSP_LED_Off(LED2);
131  BSP_LED_Off(LED3);
132  BSP_LED_Off(LED4);
133  frame_number = 0;
134  }
135  }
136 
137  }
138  pv_board_deinit();
140  pv_porcupine_delete(handle);
141 }
error_handler
static void error_handler(void)
Definition: stm32f469/stm32f469i-disco/Src/main_multi.c:62
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
LED4
@ LED4
Definition: stm32f4_discovery.h:65
pv_board_deinit
void pv_board_deinit(void)
Definition: pv_imxrt1050.c:74
ACCESS_KEY
static const char * ACCESS_KEY
Definition: stm32f469/stm32f469i-disco/Src/main_multi.c:26
pv_get_uuid
const uint8_t * pv_get_uuid(void)
Definition: pv_imxrt1050.c:31
SENSITIVITIES
static const float SENSITIVITIES[]
Definition: stm32f469/stm32f469i-disco/Src/main_multi.c:43
BSP_LED_Off
void BSP_LED_Off(Led_TypeDef Led)
Turns selected LED Off.
Definition: stm32f4_discovery.c:211
pv_porcupine_process
PV_API pv_status_t pv_porcupine_process(pv_porcupine_t *object, const int16_t *pcm, int32_t *keyword_index)
LED2
@ LED2
Definition: stm32469i_discovery.h:72
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
KEYWORD_MODEL_SIZES
static const int32_t KEYWORD_MODEL_SIZES[]
Definition: stm32f469/stm32f469i-disco/Src/main_multi.c:31
PV_STATUS_SUCCESS
@ PV_STATUS_SUCCESS
Definition: porcupine/include/picovoice.h:34
LED1
@ LED1
Definition: stm32469i_discovery.h:70
main
int main(void)
Definition: stm32f469/stm32f469i-disco/Src/main_multi.c:66
BSP_LED_On
void BSP_LED_On(Led_TypeDef Led)
Turns selected LED On.
Definition: stm32f4_discovery.c:197
pv_status_t
pv_status_t
Definition: porcupine/include/picovoice.h:33
pv_board_init
pv_status_t pv_board_init(void)
Definition: pv_imxrt1050.c:39
NUM_KEYWORDS
static const int32_t NUM_KEYWORDS
Definition: stm32f469/stm32f469i-disco/Src/main_multi.c:30
KEYWORD_MODELS
static const void * KEYWORD_MODELS[]
Definition: stm32f469/stm32f469i-disco/Src/main_multi.c:37
pv_porcupine_delete
PV_API void pv_porcupine_delete(pv_porcupine_t *object)
pv_get_uuid_size
const uint32_t pv_get_uuid_size(void)
Definition: pv_imxrt1050.c:35
MEMORY_BUFFER_SIZE
#define MEMORY_BUFFER_SIZE
Definition: stm32f469/stm32f469i-disco/Src/main_multi.c:24
pv_porcupine_mcu.h
LED3
@ LED3
Definition: stm32f4_discovery.h:66
pv_porcupine_t
struct pv_porcupine pv_porcupine_t
Definition: include/pv_porcupine.h:33
pv_stm32f469.h
pv_message_init
pv_status_t pv_message_init(void)
Definition: pv_imxrt1050.c:67
KEYWORDS_NAME
static const char * KEYWORDS_NAME[]
Definition: stm32f469/stm32f469i-disco/Src/main_multi.c:50
wake_word_callback
static void wake_word_callback(int32_t keyword_index)
Definition: stm32f469/stm32f469i-disco/Src/main_multi.c:57
__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
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
stm32469i_discovery.h
This file contains definitions for STM32469I-Discovery LEDs, push-buttons hardware resources.


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