ESPHome
2024.4.2
|
#include <micro_wake_word.h>
Public Member Functions | |
void | setup () override |
void | loop () override |
float | get_setup_priority () const override |
void | dump_config () override |
void | start () |
void | stop () |
bool | is_running () const |
bool | initialize_models () |
std::string | get_wake_word () |
void | set_probability_cutoff (float probability_cutoff) |
void | set_sliding_window_average_size (size_t size) |
void | set_microphone (microphone::Microphone *microphone) |
Trigger< std::string > * | get_wake_word_detected_trigger () const |
void | set_model_start (const uint8_t *model_start) |
void | set_wake_word (const std::string &wake_word) |
Public Member Functions inherited from esphome::Component | |
float | get_actual_setup_priority () const |
void | set_setup_priority (float priority) |
virtual float | get_loop_priority () const |
priority of loop(). More... | |
void | call () |
virtual void | on_shutdown () |
virtual void | on_safe_shutdown () |
uint32_t | get_component_state () const |
virtual void | mark_failed () |
Mark this component as failed. More... | |
bool | is_failed () |
bool | is_ready () |
virtual bool | can_proceed () |
bool | status_has_warning () const |
bool | status_has_error () const |
void | status_set_warning (const char *message="unspecified") |
void | status_set_error (const char *message="unspecified") |
void | status_clear_warning () |
void | status_clear_error () |
void | status_momentary_warning (const std::string &name, uint32_t length=5000) |
void | status_momentary_error (const std::string &name, uint32_t length=5000) |
bool | has_overridden_loop () const |
void | set_component_source (const char *source) |
Set where this component was loaded from for some debug messages. More... | |
const char * | get_component_source () const |
Get the integration where this component was declared as a string. More... | |
Protected Member Functions | |
void | set_state_ (State state) |
int | read_microphone_ () |
bool | detect_wake_word_ () |
Detects if wake word has been said. More... | |
bool | slice_available_ () |
Returns true if there are enough audio samples in the buffer to generate another slice of features. More... | |
bool | update_features_ () |
Shifts previous feature slices over by one and generates a new slice of features. More... | |
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. More... | |
float | perform_streaming_inference_ () |
Performs inference over the most recent feature slice with the streaming model. More... | |
bool | stride_audio_samples_ (int16_t **audio_samples) |
Strides the audio samples by keeping the last 10 ms of the previous slice. More... | |
bool | register_preprocessor_ops_ (tflite::MicroMutableOpResolver< 18 > &op_resolver) |
Returns true if successfully registered the preprocessor's TensorFlow operations. More... | |
bool | register_streaming_ops_ (tflite::MicroMutableOpResolver< 17 > &op_resolver) |
Returns true if successfully registered the streaming model's TensorFlow operations. More... | |
Protected Member Functions inherited from esphome::Component | |
virtual void | call_loop () |
virtual void | call_setup () |
virtual void | call_dump_config () |
void | set_interval (const std::string &name, uint32_t interval, std::function< void()> &&f) |
Set an interval function with a unique name. More... | |
void | set_interval (uint32_t interval, std::function< void()> &&f) |
bool | cancel_interval (const std::string &name) |
Cancel an interval function. More... | |
void | set_retry (const std::string &name, uint32_t initial_wait_time, uint8_t max_attempts, std::function< RetryResult(uint8_t)> &&f, float backoff_increase_factor=1.0f) |
Set an retry function with a unique name. More... | |
void | set_retry (uint32_t initial_wait_time, uint8_t max_attempts, std::function< RetryResult(uint8_t)> &&f, float backoff_increase_factor=1.0f) |
bool | cancel_retry (const std::string &name) |
Cancel a retry function. More... | |
void | set_timeout (const std::string &name, uint32_t timeout, std::function< void()> &&f) |
Set a timeout function with a unique name. More... | |
void | set_timeout (uint32_t timeout, std::function< void()> &&f) |
bool | cancel_timeout (const std::string &name) |
Cancel a timeout function. More... | |
void | defer (const std::string &name, std::function< void()> &&f) |
Defer a callback to the next loop() call. More... | |
void | defer (std::function< void()> &&f) |
Defer a callback to the next loop() call. More... | |
bool | cancel_defer (const std::string &name) |
Cancel a defer callback using the specified name, name must not be empty. More... | |
Protected Attributes | |
const uint8_t * | model_start_ |
std::string | wake_word_ |
microphone::Microphone * | microphone_ {nullptr} |
Trigger< std::string > * | wake_word_detected_trigger_ = new Trigger<std::string>() |
State | state_ {State::IDLE} |
HighFrequencyLoopRequester | high_freq_ |
std::unique_ptr< RingBuffer > | ring_buffer_ |
int16_t * | input_buffer_ |
const tflite::Model * | preprocessor_model_ {nullptr} |
const tflite::Model * | streaming_model_ {nullptr} |
tflite::MicroInterpreter * | streaming_interpreter_ {nullptr} |
tflite::MicroInterpreter * | preprocessor_interperter_ {nullptr} |
std::vector< float > | recent_streaming_probabilities_ |
size_t | last_n_index_ {0} |
float | probability_cutoff_ {0.5} |
size_t | sliding_window_average_size_ {10} |
int16_t | ignore_windows_ {-MIN_SLICES_BEFORE_DETECTION} |
uint8_t * | streaming_var_arena_ {nullptr} |
uint8_t * | streaming_tensor_arena_ {nullptr} |
uint8_t * | preprocessor_tensor_arena_ {nullptr} |
int8_t * | new_features_data_ {nullptr} |
tflite::MicroResourceVariables * | mrv_ {nullptr} |
int16_t * | preprocessor_audio_buffer_ |
bool | detected_ {false} |
Protected Attributes inherited from esphome::Component | |
uint32_t | component_state_ {0x0000} |
State of this component. More... | |
float | setup_priority_override_ {NAN} |
const char * | component_source_ {nullptr} |
Definition at line 64 of file micro_wake_word.h.
|
protected |
Detects if wake word has been said.
If enough audio samples are available, it will generate one slice of new features. If the streaming model predicts the wake word, then the nonstreaming model confirms it.
ring_Buffer | Ring buffer containing raw audio samples |
Definition at line 326 of file micro_wake_word.cpp.
|
overridevirtual |
Reimplemented from esphome::Component.
Definition at line 56 of file micro_wake_word.cpp.
|
protected |
Generates features from audio samples.
Adapted from TFLite micro speech example
audio_data | Pointer to array with the audio samples |
audio_data_size | The number of samples to use as input to the preprocessor model |
feature_output | Array that will store the features |
Definition at line 407 of file micro_wake_word.cpp.
|
overridevirtual |
Reimplemented from esphome::Component.
Definition at line 35 of file micro_wake_word.cpp.
|
inline |
Definition at line 78 of file micro_wake_word.h.
|
inline |
Definition at line 86 of file micro_wake_word.h.
bool esphome::micro_wake_word::MicroWakeWord::initialize_models | ( | ) |
Definition at line 181 of file micro_wake_word.cpp.
|
inline |
Definition at line 74 of file micro_wake_word.h.
|
overridevirtual |
Reimplemented from esphome::Component.
Definition at line 110 of file micro_wake_word.cpp.
|
protected |
Performs inference over the most recent feature slice with the streaming model.
Definition at line 304 of file micro_wake_word.cpp.
|
protected |
Definition at line 90 of file micro_wake_word.cpp.
|
protected |
Returns true if successfully registered the preprocessor's TensorFlow operations.
Definition at line 422 of file micro_wake_word.cpp.
|
protected |
Returns true if successfully registered the streaming model's TensorFlow operations.
Definition at line 463 of file micro_wake_word.cpp.
|
inline |
Definition at line 84 of file micro_wake_word.h.
|
inline |
Definition at line 88 of file micro_wake_word.h.
|
inline |
Definition at line 81 of file micro_wake_word.h.
void esphome::micro_wake_word::MicroWakeWord::set_sliding_window_average_size | ( | size_t | size | ) |
Definition at line 369 of file micro_wake_word.cpp.
|
protected |
Definition at line 175 of file micro_wake_word.cpp.
|
inline |
Definition at line 89 of file micro_wake_word.h.
|
overridevirtual |
Reimplemented from esphome::Component.
Definition at line 63 of file micro_wake_word.cpp.
|
protected |
Returns true if there are enough audio samples in the buffer to generate another slice of features.
Definition at line 374 of file micro_wake_word.cpp.
void esphome::micro_wake_word::MicroWakeWord::start | ( | ) |
Definition at line 151 of file micro_wake_word.cpp.
void esphome::micro_wake_word::MicroWakeWord::stop | ( | ) |
Definition at line 163 of file micro_wake_word.cpp.
|
protected |
Strides the audio samples by keeping the last 10 ms of the previous slice.
Adapted from the TFLite micro speech example
ring_buffer | Ring buffer containing raw audio samples |
audio_samples | Pointer to an array that will store the strided audio samples |
Definition at line 380 of file micro_wake_word.cpp.
|
protected |
Shifts previous feature slices over by one and generates a new slice of features.
ring_buffer | ring buffer containing raw audio samples |
Definition at line 289 of file micro_wake_word.cpp.
|
protected |
Definition at line 132 of file micro_wake_word.h.
|
protected |
Definition at line 101 of file micro_wake_word.h.
|
protected |
Definition at line 120 of file micro_wake_word.h.
|
protected |
Definition at line 105 of file micro_wake_word.h.
|
protected |
Definition at line 113 of file micro_wake_word.h.
|
protected |
Definition at line 98 of file micro_wake_word.h.
|
protected |
Definition at line 95 of file micro_wake_word.h.
|
protected |
Definition at line 127 of file micro_wake_word.h.
|
protected |
Definition at line 125 of file micro_wake_word.h.
|
protected |
Definition at line 130 of file micro_wake_word.h.
|
protected |
Definition at line 110 of file micro_wake_word.h.
|
protected |
Definition at line 107 of file micro_wake_word.h.
|
protected |
Definition at line 124 of file micro_wake_word.h.
|
protected |
Definition at line 115 of file micro_wake_word.h.
|
protected |
Definition at line 112 of file micro_wake_word.h.
|
protected |
Definition at line 103 of file micro_wake_word.h.
|
protected |
Definition at line 116 of file micro_wake_word.h.
|
protected |
Definition at line 100 of file micro_wake_word.h.
|
protected |
Definition at line 109 of file micro_wake_word.h.
|
protected |
Definition at line 108 of file micro_wake_word.h.
|
protected |
Definition at line 123 of file micro_wake_word.h.
|
protected |
Definition at line 122 of file micro_wake_word.h.
|
protected |
Definition at line 96 of file micro_wake_word.h.
|
protected |
Definition at line 99 of file micro_wake_word.h.