ESPHome
2024.11.0
|
#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 |
void | set_features_step_size (uint8_t step_size) |
void | set_microphone (microphone::Microphone *microphone) |
Trigger< std::string > * | get_wake_word_detected_trigger () const |
void | add_wake_word_model (const uint8_t *model_start, float probability_cutoff, size_t sliding_window_average_size, const std::string &wake_word, size_t tensor_arena_size) |
void | add_vad_model (const uint8_t *model_start, float probability_cutoff, size_t sliding_window_size, size_t tensor_arena_size) |
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 () const |
bool | is_ready () const |
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) |
bool | has_enough_samples_ () |
Tests if there are enough samples in the ring buffer to generate new features. More... | |
size_t | read_microphone_ () |
Reads audio from microphone into the ring buffer. More... | |
bool | allocate_buffers_ () |
Allocates memory for input_buffer_, preprocessor_audio_buffer_, and ring_buffer_. More... | |
void | deallocate_buffers_ () |
Frees memory allocated for input_buffer_ and preprocessor_audio_buffer_. More... | |
bool | load_models_ () |
Loads streaming models and prepares the feature generation frontend. More... | |
void | unload_models_ () |
Deletes each model's TFLite interpreters and frees tensor arena memory. More... | |
void | update_model_probabilities_ () |
Performs inference with each configured model. More... | |
bool | detect_wake_words_ () |
Checks every model's recent probabilities to determine if the wake word has been predicted. More... | |
bool | generate_features_for_window_ (int8_t features[PREPROCESSOR_FEATURE_SIZE]) |
Generates features for a window of audio samples. More... | |
void | reset_states_ () |
Resets the ring buffer, ignore_windows_, and sliding window probabilities. More... | |
bool | register_streaming_ops_ (tflite::MicroMutableOpResolver< 20 > &op_resolver) |
Returns true if successfully registered the streaming model's TensorFlow operations. More... | |
uint16_t | new_samples_to_get_ () |
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 | |
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_ |
std::vector< WakeWordModel > | wake_word_models_ |
std::unique_ptr< VADModel > | vad_model_ |
tflite::MicroMutableOpResolver< 20 > | streaming_op_resolver_ |
struct FrontendConfig | frontend_config_ |
struct FrontendState | frontend_state_ |
int16_t | ignore_windows_ {-MIN_SLICES_BEFORE_DETECTION} |
uint8_t | features_step_size_ |
int16_t * | input_buffer_ {nullptr} |
int16_t * | preprocessor_audio_buffer_ {nullptr} |
bool | detected_ {false} |
std::string | detected_wake_word_ {""} |
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 35 of file micro_wake_word.h.
void esphome::micro_wake_word::MicroWakeWord::add_vad_model | ( | const uint8_t * | model_start, |
float | probability_cutoff, | ||
size_t | sliding_window_size, | ||
size_t | tensor_arena_size | ||
) |
Definition at line 96 of file micro_wake_word.cpp.
void esphome::micro_wake_word::MicroWakeWord::add_wake_word_model | ( | const uint8_t * | model_start, |
float | probability_cutoff, | ||
size_t | sliding_window_average_size, | ||
const std::string & | wake_word, | ||
size_t | tensor_arena_size | ||
) |
Definition at line 88 of file micro_wake_word.cpp.
|
protected |
Allocates memory for input_buffer_, preprocessor_audio_buffer_, and ring_buffer_.
Definition at line 219 of file micro_wake_word.cpp.
|
protected |
Frees memory allocated for input_buffer_ and preprocessor_audio_buffer_.
Definition at line 249 of file micro_wake_word.cpp.
|
protected |
Checks every model's recent probabilities to determine if the wake word has been predicted.
Verifies the models have processed enough new samples for accurate predictions. Sets detected_wake_word_ to the wake word, if one is detected.
Definition at line 312 of file micro_wake_word.cpp.
|
overridevirtual |
Reimplemented from esphome::Component.
Definition at line 50 of file micro_wake_word.cpp.
|
protected |
Generates features for a window of audio samples.
Reads samples from the ring buffer and feeds them into the preprocessor frontend. Adapted from TFLite microspeech frontend.
features | int8_t array to store the audio features |
Definition at line 345 of file micro_wake_word.cpp.
|
overridevirtual |
Reimplemented from esphome::Component.
Definition at line 29 of file micro_wake_word.cpp.
|
inline |
Definition at line 51 of file micro_wake_word.h.
|
protected |
Tests if there are enough samples in the ring buffer to generate new features.
Definition at line 340 of file micro_wake_word.cpp.
|
inline |
Definition at line 45 of file micro_wake_word.h.
|
protected |
Loads streaming models and prepares the feature generation frontend.
Definition at line 257 of file micro_wake_word.cpp.
|
overridevirtual |
Reimplemented from esphome::Component.
Definition at line 102 of file micro_wake_word.cpp.
|
inlineprotected |
Definition at line 155 of file micro_wake_word.h.
|
protected |
Reads audio from microphone into the ring buffer.
Audio data (16000 kHz with int16 samples) is read into the input_buffer_. Verifies the ring buffer has enough space for all audio data. If not, it logs a warning and resets the ring buffer entirely.
Definition at line 199 of file micro_wake_word.cpp.
|
protected |
Returns true if successfully registered the streaming model's TensorFlow operations.
Definition at line 410 of file micro_wake_word.cpp.
|
protected |
Resets the ring buffer, ignore_windows_, and sliding window probabilities.
Definition at line 398 of file micro_wake_word.cpp.
|
inline |
Definition at line 47 of file micro_wake_word.h.
|
inline |
Definition at line 49 of file micro_wake_word.h.
|
protected |
Definition at line 193 of file micro_wake_word.cpp.
|
overridevirtual |
Reimplemented from esphome::Component.
Definition at line 61 of file micro_wake_word.cpp.
void esphome::micro_wake_word::MicroWakeWord::start | ( | ) |
Definition at line 149 of file micro_wake_word.cpp.
void esphome::micro_wake_word::MicroWakeWord::stop | ( | ) |
Definition at line 181 of file micro_wake_word.cpp.
|
protected |
Deletes each model's TFLite interpreters and frees tensor arena memory.
Frees memory used by the feature generation frontend.
Definition at line 282 of file micro_wake_word.cpp.
|
protected |
Performs inference with each configured model.
If enough audio samples are available, it will generate one slice of new features. It then loops through and performs inference with each of the loaded models.
Definition at line 293 of file micro_wake_word.cpp.
|
protected |
Definition at line 92 of file micro_wake_word.h.
|
protected |
Definition at line 93 of file micro_wake_word.h.
|
protected |
Definition at line 85 of file micro_wake_word.h.
|
protected |
Definition at line 78 of file micro_wake_word.h.
|
protected |
Definition at line 79 of file micro_wake_word.h.
|
protected |
Definition at line 65 of file micro_wake_word.h.
|
protected |
Definition at line 83 of file micro_wake_word.h.
|
protected |
Definition at line 88 of file micro_wake_word.h.
|
protected |
Definition at line 62 of file micro_wake_word.h.
|
protected |
Definition at line 90 of file micro_wake_word.h.
|
protected |
Definition at line 67 of file micro_wake_word.h.
|
protected |
Definition at line 64 of file micro_wake_word.h.
|
protected |
Definition at line 75 of file micro_wake_word.h.
|
protected |
Definition at line 72 of file micro_wake_word.h.
|
protected |
Definition at line 63 of file micro_wake_word.h.
|
protected |
Definition at line 69 of file micro_wake_word.h.