stm32f769/stm32f769i-disco/Src/main.c
Go to the documentation of this file.
1 
2 /*
3  Copyright 2021 Picovoice Inc.
4 
5  You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
6  file accompanying this source.
7 
8  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9  an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10  specific language governing permissions and limitations under the License.
11 */
12 
13 #include <stdbool.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 
17 #include "stm32f769i_discovery.h"
18 
19 #include "pv_porcupine_mcu.h"
20 
21 #include "pv_audio_rec.h"
22 #include "pv_params.h"
23 #include "pv_st_f769.h"
24 
25 #define MEMORY_BUFFER_SIZE (20 * 1024)
26 
27 static const char* ACCESS_KEY = ... //AccessKey string obtained from Picovoice Console (https://picovoice.ai/console/)
28 
29 static int8_t memory_buffer[MEMORY_BUFFER_SIZE] __attribute__((aligned(16)));
30 
31 static const int32_t KEYWORD_MODEL_SIZES = sizeof(DEFAULT_KEYWORD_ARRAY);
32 static const void *KEYWORD_MODELS = DEFAULT_KEYWORD_ARRAY;
33 static const float SENSITIVITY = 0.75f;
34 
35 static void wake_word_callback(void) {
36  printf("[wake word]\n");
38 }
39 
40 static void error_handler(void) {
41  while(true);
42 }
43 
44 int main(void) {
45 
46  pv_status_t status = pv_board_init();
47  if (status != PV_STATUS_SUCCESS) {
48  error_handler();
49  }
50 
51  status = pv_message_init();
52  if (status != PV_STATUS_SUCCESS) {
53  error_handler();
54  }
55 
56  const uint8_t *board_uuid = pv_get_uuid();
57  printf("UUID: ");
58  for (uint32_t i = 0; i < pv_get_uuid_size(); i++) {
59  printf(" %.2x", board_uuid[i]);
60  }
61  printf("\r\n");
62 
63  status = pv_audio_rec_init();
64  if (status != PV_STATUS_SUCCESS) {
65  printf("Audio init failed with '%s'", pv_status_to_string(status));
66  error_handler();
67  }
68 
69  status = pv_audio_rec_start();
70  if (status != PV_STATUS_SUCCESS) {
71  printf("Recording audio failed with '%s'", pv_status_to_string(status));
72  error_handler();
73  }
74 
75  pv_porcupine_t *handle = NULL;
76 
77  status = pv_porcupine_init(
78  ACCESS_KEY,
80  memory_buffer,
81  1,
84  &SENSITIVITY,
85  &handle);
86 
87  if (status != PV_STATUS_SUCCESS) {
88  printf("Porcupine init failed with '%s'", pv_status_to_string(status));
89  error_handler();
90  }
91 
92  uint32_t frame_number = 0;
93  while (true) {
94  const int16_t *buffer = pv_audio_rec_get_new_buffer();
95  if (buffer) {
96  int32_t keyword_index;
97  const pv_status_t status = pv_porcupine_process(handle, buffer, &keyword_index);
98  if (status != PV_STATUS_SUCCESS) {
99  printf("Porcupine process failed with '%s'", pv_status_to_string(status));
100  error_handler();
101  }
102  if (keyword_index != -1) {
103  frame_number = 0;
105  }
106  if (frame_number++ > 20) {
107  BSP_LED_Off(LED1);
108  frame_number = 0;
109  }
110  }
111 
112  }
113  pv_board_deinit();
115  pv_porcupine_delete(handle);
116 }
117 
118 
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)
main
int main(void)
Definition: stm32f769/stm32f769i-disco/Src/main.c:44
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
ACCESS_KEY
static const char * ACCESS_KEY
Definition: stm32f769/stm32f769i-disco/Src/main.c:27
stm32f769i_discovery.h
This file contains definitions for STM32F769I-Discovery LEDs, push-buttons hardware resources.
pv_get_uuid
const uint8_t * pv_get_uuid(void)
Definition: pv_imxrt1050.c:31
BSP_LED_Off
void BSP_LED_Off(Led_TypeDef Led)
Turns selected LED Off.
Definition: stm32f4_discovery.c:211
KEYWORD_MODELS
static const void * KEYWORD_MODELS
Definition: stm32f769/stm32f769i-disco/Src/main.c:32
pv_porcupine_process
PV_API pv_status_t pv_porcupine_process(pv_porcupine_t *object, const int16_t *pcm, int32_t *keyword_index)
wake_word_callback
static void wake_word_callback(void)
Definition: stm32f769/stm32f769i-disco/Src/main.c:35
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
LED1
@ LED1
Definition: stm32469i_discovery.h:70
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
error_handler
static void error_handler(void)
Definition: stm32f769/stm32f769i-disco/Src/main.c:40
pv_board_init
pv_status_t pv_board_init(void)
Definition: pv_imxrt1050.c:39
SENSITIVITY
static const float SENSITIVITY
Definition: stm32f769/stm32f769i-disco/Src/main.c:33
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
pv_porcupine_mcu.h
pv_st_f769.h
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
__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
MEMORY_BUFFER_SIZE
#define MEMORY_BUFFER_SIZE
Definition: stm32f769/stm32f769i-disco/Src/main.c:25
KEYWORD_MODEL_SIZES
static const int32_t KEYWORD_MODEL_SIZES
Definition: stm32f769/stm32f769i-disco/Src/main.c:31


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