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


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