19 #include <tensorflow/lite/core/c/common.h> 20 #include <tensorflow/lite/micro/micro_interpreter.h> 21 #include <tensorflow/lite/micro/micro_mutable_op_resolver.h> 24 namespace micro_wake_word {
29 static const uint8_t PREPROCESSOR_FEATURE_SIZE = 40;
31 static const uint8_t FEATURE_STRIDE_MS = 20;
33 static const uint8_t FEATURE_DURATION_MS = 30;
35 static const uint16_t AUDIO_SAMPLE_FREQUENCY = 16000;
37 static const uint16_t HISTORY_SAMPLES_TO_KEEP =
38 ((FEATURE_DURATION_MS - FEATURE_STRIDE_MS) * (AUDIO_SAMPLE_FREQUENCY / 1000));
40 static const uint16_t NEW_SAMPLES_TO_GET = (FEATURE_STRIDE_MS * (AUDIO_SAMPLE_FREQUENCY / 1000));
42 static const uint16_t SAMPLE_DURATION_COUNT = FEATURE_DURATION_MS * AUDIO_SAMPLE_FREQUENCY / 1000;
44 static const uint32_t PREPROCESSOR_ARENA_SIZE = 9528;
49 static const uint8_t MIN_SLICES_BEFORE_DETECTION = 74;
52 static const uint32_t STREAMING_MODEL_ARENA_SIZE = 64000;
53 static const uint32_t STREAMING_MODEL_VARIABLE_ARENA_SIZE = 1024;
66 void setup()
override;
127 tflite::MicroResourceVariables *
mrv_{
nullptr};
162 int8_t feature_output[PREPROCESSOR_FEATURE_SIZE]);
188 void play(Ts...
x)
override { this->parent_->start(); }
193 void play(Ts...
x)
override { this->parent_->stop(); }
198 bool check(Ts...
x)
override {
return this->parent_->is_running(); }
204 #endif // USE_ESP_IDF tflite::MicroInterpreter * streaming_interpreter_
bool detect_wake_word_()
Detects if wake word has been said.
void set_model_start(const uint8_t *model_start)
int16_t * preprocessor_audio_buffer_
bool register_preprocessor_ops_(tflite::MicroMutableOpResolver< 18 > &op_resolver)
Returns true if successfully registered the preprocessor's TensorFlow operations. ...
const tflite::Model * preprocessor_model_
void set_state_(State state)
Trigger< std::string > * wake_word_detected_trigger_
std::string get_wake_word()
std::unique_ptr< RingBuffer > ring_buffer_
const uint8_t * model_start_
std::vector< float > recent_streaming_probabilities_
Helper class to request loop() to be called as fast as possible.
uint8_t * streaming_var_arena_
float get_setup_priority() const override
uint8_t * streaming_tensor_arena_
HighFrequencyLoopRequester high_freq_
size_t sliding_window_average_size_
void set_probability_cutoff(float probability_cutoff)
bool stride_audio_samples_(int16_t **audio_samples)
Strides the audio samples by keeping the last 10 ms of the previous slice.
tflite::MicroInterpreter * preprocessor_interperter_
bool update_features_()
Shifts previous feature slices over by one and generates a new slice of features. ...
float perform_streaming_inference_()
Performs inference over the most recent feature slice with the streaming model.
void dump_config() override
bool check(Ts... x) override
microphone::Microphone * microphone_
Base class for all automation conditions.
bool register_streaming_ops_(tflite::MicroMutableOpResolver< 17 > &op_resolver)
Returns true if successfully registered the streaming model's TensorFlow operations.
void play(Ts... x) override
void set_wake_word(const std::string &wake_word)
int8_t * new_features_data_
Trigger< std::string > * get_wake_word_detected_trigger() const
bool generate_single_feature_(const int16_t *audio_data, int audio_data_size, int8_t feature_output[PREPROCESSOR_FEATURE_SIZE])
Generates features from audio samples.
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
void play(Ts... x) override
void set_microphone(microphone::Microphone *microphone)
bool slice_available_()
Returns true if there are enough audio samples in the buffer to generate another slice of features...
uint8_t * preprocessor_tensor_arena_
void set_sliding_window_average_size(size_t size)
const tflite::Model * streaming_model_
float probability_cutoff_
Helper class to easily give an object a parent of type T.
tflite::MicroResourceVariables * mrv_