#include #include #include #include #include #include #include "april_api.h" #ifndef _MSC_VER #include #else #include #include #define STDIN_FILENO 0 typedef SSIZE_T ssize_t; #endif #define BUFFER_SIZE 1024 int ends_with(const char *str, const char *suffix); struct wav_header { // RIFF Header char riff_header[4]; // Contains "RIFF" uint32_t wav_size; // Size of the wav portion of the file, which follows the first 8 bytes. File size - 8 char wave_header[4]; // Contains "WAVE" // Format Header char fmt_header[4]; // Contains "fmt " (includes trailing space) int32_t fmt_chunk_size; // Should be 16 for PCM int16_t audio_format; // Should be 1 for PCM. 3 for IEEE Float int16_t num_channels; int32_t sample_rate; int32_t byte_rate; // Number of bytes per second. sample_rate * num_channels * Bytes Per Sample int16_t sample_alignment; // num_channels * Bytes Per Sample int16_t bit_depth; // Number of bits per sample // Data char data_header[4]; // Contains "data" uint32_t data_bytes; // Number of bytes in data. Number of samples * num_channels * sample byte size }; static_assert(sizeof(wav_header) == 44L, "wav header must be 44 bytes"); // In this example, the internal state is just a global struct just for testing // In your program you can pass any pointer into userdata to access it in the // handler struct { int xyz; } some_internal_state; // This callback function will get called every time a new result is decoded. // It's passed into the AprilConfig along with the userdata pointer. void handler(void *userdata, AprilResultType result, size_t count, const AprilToken *tokens) { assert(userdata == &some_internal_state); switch(result){ case APRIL_RESULT_RECOGNITION_FINAL: printf("@ "); break; case APRIL_RESULT_RECOGNITION_PARTIAL: printf("- "); break; case APRIL_RESULT_SILENCE: break; default: assert(false); return; } for(int t=0; t lenstr) return 0; return strncmp(str + lenstr - lensuffix, suffix, lensuffix) == 0; }