Skip to content

Commit

Permalink
update demo
Browse files Browse the repository at this point in the history
  • Loading branch information
ksyeo1010 committed Oct 6, 2023
1 parent 48cbaaf commit 95470d6
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions demo/c/porcupine_demo_mic.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ int picovoice_main(int argc, char *argv[]) {
exit(1);
}

void (*pv_get_error_stack_func)(char ***, int32_t *) = load_symbol(porcupine_library, "pv_get_error_stack");
pv_status_t (*pv_get_error_stack_func)(char ***, int32_t *) = load_symbol(porcupine_library, "pv_get_error_stack");
if (!pv_get_error_stack_func) {
print_dl_error("failed to load 'pv_get_error_stack_func'");
exit(1);
Expand All @@ -237,12 +237,17 @@ int picovoice_main(int argc, char *argv[]) {

char **message_stack = NULL;
int32_t message_stack_depth = 0;
pv_status_t error_status;

pv_porcupine_t *porcupine = NULL;
pv_status_t porcupine_status = pv_porcupine_init_func(access_key, model_path, 1, &keyword_path, &sensitivity, &porcupine);
if (porcupine_status != PV_STATUS_SUCCESS) {
fprintf(stderr, "'pv_porcupine_init' failed with '%s'", pv_status_to_string_func(porcupine_status));
pv_get_error_stack_func(&message_stack, &message_stack_depth);
error_status = pv_get_error_stack_func(&message_stack, &message_stack_depth);
if (error_status != PV_STATUS_SUCCESS) {
fprintf(stderr, ".\nUnable to get Porcupine error stack.\n");
exit(1);
}

if (message_stack_depth > 0) {
fprintf(stderr, ":\n");
Expand Down Expand Up @@ -292,15 +297,19 @@ int picovoice_main(int argc, char *argv[]) {
porcupine_status = pv_porcupine_process_func(porcupine, pcm, &keyword_index);
if (porcupine_status != PV_STATUS_SUCCESS) {
fprintf(stderr, "'pv_porcupine_process' failed with '%s'", pv_status_to_string_func(porcupine_status));
pv_get_error_stack_func(&message_stack, &message_stack_depth);

if (message_stack_depth > 0) {
fprintf(stderr, ":\n");
print_error_message(message_stack, message_stack_depth);
pv_free_error_stack_func(message_stack);
} else {
fprintf(stderr, ".\n");
}
error_status = pv_get_error_stack_func(&message_stack, &message_stack_depth);
if (error_status != PV_STATUS_SUCCESS) {
fprintf(stderr, ".\nUnable to get Porcupine error stack.\n");
exit(1);
}

if (message_stack_depth > 0) {
fprintf(stderr, ":\n");
print_error_message(message_stack, message_stack_depth);
pv_free_error_stack_func(message_stack);
} else {
fprintf(stderr, ".\n");
}
exit(1);
}

Expand Down

0 comments on commit 95470d6

Please sign in to comment.