ESPHome  2024.2.0
Public Member Functions | Protected Member Functions | Protected Attributes
esphome::voice_assistant::VoiceAssistant Class Reference

#include <voice_assistant.h>

Inheritance diagram for esphome::voice_assistant::VoiceAssistant:
esphome::Component

Public Member Functions

void setup () override
 
void loop () override
 
float get_setup_priority () const override
 
void start_streaming (struct sockaddr_storage *addr, uint16_t port)
 
void failed_to_start ()
 
void set_microphone (microphone::Microphone *mic)
 
void set_speaker (speaker::Speaker *speaker)
 
void set_media_player (media_player::MediaPlayer *media_player)
 
uint32_t get_version () const
 
void request_start (bool continuous, bool silence_detection)
 
void request_stop ()
 
void on_event (const api::VoiceAssistantEventResponse &msg)
 
bool is_running () const
 
void set_continuous (bool continuous)
 
bool is_continuous () const
 
void set_use_wake_word (bool use_wake_word)
 
void set_vad_threshold (uint8_t vad_threshold)
 
void set_noise_suppression_level (uint8_t noise_suppression_level)
 
void set_auto_gain (uint8_t auto_gain)
 
void set_volume_multiplier (float volume_multiplier)
 
Triggerget_intent_end_trigger () const
 
Triggerget_intent_start_trigger () const
 
Triggerget_listening_trigger () const
 
Triggerget_end_trigger () const
 
Triggerget_start_trigger () const
 
Triggerget_stt_vad_end_trigger () const
 
Triggerget_stt_vad_start_trigger () const
 
Triggerget_tts_stream_start_trigger () const
 
Triggerget_tts_stream_end_trigger () const
 
Triggerget_wake_word_detected_trigger () const
 
Trigger< std::string > * get_stt_end_trigger () const
 
Trigger< std::string > * get_tts_end_trigger () const
 
Trigger< std::string > * get_tts_start_trigger () const
 
Trigger< std::string, std::string > * get_error_trigger () const
 
Triggerget_idle_trigger () const
 
Triggerget_client_connected_trigger () const
 
Triggerget_client_disconnected_trigger () const
 
void client_subscription (api::APIConnection *client, bool subscribe)
 
api::APIConnectionget_api_connection () const
 
- Public Member Functions inherited from esphome::Component
virtual void dump_config ()
 
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 ()
 
bool status_has_error ()
 
void status_set_warning ()
 
void status_set_error ()
 
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

int read_microphone_ ()
 
void set_state_ (State state)
 
void set_state_ (State state, State desired_state)
 
void signal_stop_ ()
 
void write_speaker_ ()
 
- 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

std::unique_ptr< socket::Socketsocket_ = nullptr
 
struct sockaddr_storage dest_addr_
 
Triggerintent_end_trigger_ = new Trigger<>()
 
Triggerintent_start_trigger_ = new Trigger<>()
 
Triggerlistening_trigger_ = new Trigger<>()
 
Triggerend_trigger_ = new Trigger<>()
 
Triggerstart_trigger_ = new Trigger<>()
 
Triggerstt_vad_start_trigger_ = new Trigger<>()
 
Triggerstt_vad_end_trigger_ = new Trigger<>()
 
Triggertts_stream_start_trigger_ = new Trigger<>()
 
Triggertts_stream_end_trigger_ = new Trigger<>()
 
Triggerwake_word_detected_trigger_ = new Trigger<>()
 
Trigger< std::string > * stt_end_trigger_ = new Trigger<std::string>()
 
Trigger< std::string > * tts_end_trigger_ = new Trigger<std::string>()
 
Trigger< std::string > * tts_start_trigger_ = new Trigger<std::string>()
 
Trigger< std::string, std::string > * error_trigger_ = new Trigger<std::string, std::string>()
 
Triggeridle_trigger_ = new Trigger<>()
 
Triggerclient_connected_trigger_ = new Trigger<>()
 
Triggerclient_disconnected_trigger_ = new Trigger<>()
 
api::APIConnectionapi_client_ {nullptr}
 
microphone::Microphonemic_ {nullptr}
 
speaker::Speakerspeaker_ {nullptr}
 
uint8_t * speaker_buffer_
 
size_t speaker_buffer_index_ {0}
 
size_t speaker_buffer_size_ {0}
 
size_t speaker_bytes_received_ {0}
 
bool wait_for_stream_end_ {false}
 
bool stream_ended_ {false}
 
media_player::MediaPlayermedia_player_ {nullptr}
 
bool local_output_ {false}
 
std::string conversation_id_ {""}
 
HighFrequencyLoopRequester high_freq_
 
vad_handle_t vad_instance_
 
uint8_t vad_threshold_ {5}
 
uint8_t vad_counter_ {0}
 
std::unique_ptr< RingBufferring_buffer_
 
bool use_wake_word_
 
uint8_t noise_suppression_level_
 
uint8_t auto_gain_
 
float volume_multiplier_
 
uint8_t * send_buffer_
 
int16_t * input_buffer_
 
bool continuous_ {false}
 
bool silence_detection_
 
State state_ {State::IDLE}
 
State desired_state_ {State::IDLE}
 
- 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}
 

Detailed Description

Definition at line 52 of file voice_assistant.h.

Member Function Documentation

◆ client_subscription()

void esphome::voice_assistant::VoiceAssistant::client_subscription ( api::APIConnection client,
bool  subscribe 
)

Definition at line 355 of file voice_assistant.cpp.

◆ failed_to_start()

void esphome::voice_assistant::VoiceAssistant::failed_to_start ( )

Definition at line 423 of file voice_assistant.cpp.

◆ get_api_connection()

api::APIConnection* esphome::voice_assistant::VoiceAssistant::get_api_connection ( ) const
inline

Definition at line 125 of file voice_assistant.h.

◆ get_client_connected_trigger()

Trigger* esphome::voice_assistant::VoiceAssistant::get_client_connected_trigger ( ) const
inline

Definition at line 121 of file voice_assistant.h.

◆ get_client_disconnected_trigger()

Trigger* esphome::voice_assistant::VoiceAssistant::get_client_disconnected_trigger ( ) const
inline

Definition at line 122 of file voice_assistant.h.

◆ get_end_trigger()

Trigger* esphome::voice_assistant::VoiceAssistant::get_end_trigger ( ) const
inline

Definition at line 106 of file voice_assistant.h.

◆ get_error_trigger()

Trigger<std::string, std::string>* esphome::voice_assistant::VoiceAssistant::get_error_trigger ( ) const
inline

Definition at line 118 of file voice_assistant.h.

◆ get_idle_trigger()

Trigger* esphome::voice_assistant::VoiceAssistant::get_idle_trigger ( ) const
inline

Definition at line 119 of file voice_assistant.h.

◆ get_intent_end_trigger()

Trigger* esphome::voice_assistant::VoiceAssistant::get_intent_end_trigger ( ) const
inline

Definition at line 103 of file voice_assistant.h.

◆ get_intent_start_trigger()

Trigger* esphome::voice_assistant::VoiceAssistant::get_intent_start_trigger ( ) const
inline

Definition at line 104 of file voice_assistant.h.

◆ get_listening_trigger()

Trigger* esphome::voice_assistant::VoiceAssistant::get_listening_trigger ( ) const
inline

Definition at line 105 of file voice_assistant.h.

◆ get_setup_priority()

float esphome::voice_assistant::VoiceAssistant::get_setup_priority ( ) const
overridevirtual

Reimplemented from esphome::Component.

Definition at line 25 of file voice_assistant.cpp.

◆ get_start_trigger()

Trigger* esphome::voice_assistant::VoiceAssistant::get_start_trigger ( ) const
inline

Definition at line 107 of file voice_assistant.h.

◆ get_stt_end_trigger()

Trigger<std::string>* esphome::voice_assistant::VoiceAssistant::get_stt_end_trigger ( ) const
inline

Definition at line 115 of file voice_assistant.h.

◆ get_stt_vad_end_trigger()

Trigger* esphome::voice_assistant::VoiceAssistant::get_stt_vad_end_trigger ( ) const
inline

Definition at line 108 of file voice_assistant.h.

◆ get_stt_vad_start_trigger()

Trigger* esphome::voice_assistant::VoiceAssistant::get_stt_vad_start_trigger ( ) const
inline

Definition at line 109 of file voice_assistant.h.

◆ get_tts_end_trigger()

Trigger<std::string>* esphome::voice_assistant::VoiceAssistant::get_tts_end_trigger ( ) const
inline

Definition at line 116 of file voice_assistant.h.

◆ get_tts_start_trigger()

Trigger<std::string>* esphome::voice_assistant::VoiceAssistant::get_tts_start_trigger ( ) const
inline

Definition at line 117 of file voice_assistant.h.

◆ get_tts_stream_end_trigger()

Trigger* esphome::voice_assistant::VoiceAssistant::get_tts_stream_end_trigger ( ) const
inline

Definition at line 112 of file voice_assistant.h.

◆ get_tts_stream_start_trigger()

Trigger* esphome::voice_assistant::VoiceAssistant::get_tts_stream_start_trigger ( ) const
inline

Definition at line 111 of file voice_assistant.h.

◆ get_version()

uint32_t esphome::voice_assistant::VoiceAssistant::get_version ( ) const
inline

Definition at line 74 of file voice_assistant.h.

◆ get_wake_word_detected_trigger()

Trigger* esphome::voice_assistant::VoiceAssistant::get_wake_word_detected_trigger ( ) const
inline

Definition at line 114 of file voice_assistant.h.

◆ is_continuous()

bool esphome::voice_assistant::VoiceAssistant::is_continuous ( ) const
inline

Definition at line 90 of file voice_assistant.h.

◆ is_running()

bool esphome::voice_assistant::VoiceAssistant::is_running ( ) const
inline

Definition at line 88 of file voice_assistant.h.

◆ loop()

void esphome::voice_assistant::VoiceAssistant::loop ( )
overridevirtual

Reimplemented from esphome::Component.

Definition at line 123 of file voice_assistant.cpp.

◆ on_event()

void esphome::voice_assistant::VoiceAssistant::on_event ( const api::VoiceAssistantEventResponse msg)

Definition at line 520 of file voice_assistant.cpp.

◆ read_microphone_()

int esphome::voice_assistant::VoiceAssistant::read_microphone_ ( )
protected

Definition at line 107 of file voice_assistant.cpp.

◆ request_start()

void esphome::voice_assistant::VoiceAssistant::request_start ( bool  continuous,
bool  silence_detection 
)

Definition at line 458 of file voice_assistant.cpp.

◆ request_stop()

void esphome::voice_assistant::VoiceAssistant::request_stop ( )

Definition at line 480 of file voice_assistant.cpp.

◆ set_auto_gain()

void esphome::voice_assistant::VoiceAssistant::set_auto_gain ( uint8_t  auto_gain)
inline

Definition at line 100 of file voice_assistant.h.

◆ set_continuous()

void esphome::voice_assistant::VoiceAssistant::set_continuous ( bool  continuous)
inline

Definition at line 89 of file voice_assistant.h.

◆ set_media_player()

void esphome::voice_assistant::VoiceAssistant::set_media_player ( media_player::MediaPlayer media_player)
inline

Definition at line 68 of file voice_assistant.h.

◆ set_microphone()

void esphome::voice_assistant::VoiceAssistant::set_microphone ( microphone::Microphone mic)
inline

Definition at line 60 of file voice_assistant.h.

◆ set_noise_suppression_level()

void esphome::voice_assistant::VoiceAssistant::set_noise_suppression_level ( uint8_t  noise_suppression_level)
inline

Definition at line 97 of file voice_assistant.h.

◆ set_speaker()

void esphome::voice_assistant::VoiceAssistant::set_speaker ( speaker::Speaker speaker)
inline

Definition at line 62 of file voice_assistant.h.

◆ set_state_() [1/2]

void esphome::voice_assistant::VoiceAssistant::set_state_ ( State  state)
protected

Definition at line 410 of file voice_assistant.cpp.

◆ set_state_() [2/2]

void esphome::voice_assistant::VoiceAssistant::set_state_ ( State  state,
State  desired_state 
)
protected

Definition at line 417 of file voice_assistant.cpp.

◆ set_use_wake_word()

void esphome::voice_assistant::VoiceAssistant::set_use_wake_word ( bool  use_wake_word)
inline

Definition at line 92 of file voice_assistant.h.

◆ set_vad_threshold()

void esphome::voice_assistant::VoiceAssistant::set_vad_threshold ( uint8_t  vad_threshold)
inline

Definition at line 94 of file voice_assistant.h.

◆ set_volume_multiplier()

void esphome::voice_assistant::VoiceAssistant::set_volume_multiplier ( float  volume_multiplier)
inline

Definition at line 101 of file voice_assistant.h.

◆ setup()

void esphome::voice_assistant::VoiceAssistant::setup ( )
overridevirtual

Reimplemented from esphome::Component.

Definition at line 27 of file voice_assistant.cpp.

◆ signal_stop_()

void esphome::voice_assistant::VoiceAssistant::signal_stop_ ( )
protected

Definition at line 509 of file voice_assistant.cpp.

◆ start_streaming()

void esphome::voice_assistant::VoiceAssistant::start_streaming ( struct sockaddr_storage addr,
uint16_t  port 
)

Definition at line 429 of file voice_assistant.cpp.

◆ write_speaker_()

void esphome::voice_assistant::VoiceAssistant::write_speaker_ ( )
protected

Definition at line 340 of file voice_assistant.cpp.

Field Documentation

◆ api_client_

api::APIConnection* esphome::voice_assistant::VoiceAssistant::api_client_ {nullptr}
protected

Definition at line 157 of file voice_assistant.h.

◆ auto_gain_

uint8_t esphome::voice_assistant::VoiceAssistant::auto_gain_
protected

Definition at line 189 of file voice_assistant.h.

◆ client_connected_trigger_

Trigger* esphome::voice_assistant::VoiceAssistant::client_connected_trigger_ = new Trigger<>()
protected

Definition at line 154 of file voice_assistant.h.

◆ client_disconnected_trigger_

Trigger* esphome::voice_assistant::VoiceAssistant::client_disconnected_trigger_ = new Trigger<>()
protected

Definition at line 155 of file voice_assistant.h.

◆ continuous_

bool esphome::voice_assistant::VoiceAssistant::continuous_ {false}
protected

Definition at line 195 of file voice_assistant.h.

◆ conversation_id_

std::string esphome::voice_assistant::VoiceAssistant::conversation_id_ {""}
protected

Definition at line 176 of file voice_assistant.h.

◆ desired_state_

State esphome::voice_assistant::VoiceAssistant::desired_state_ {State::IDLE}
protected

Definition at line 199 of file voice_assistant.h.

◆ dest_addr_

struct sockaddr_storage esphome::voice_assistant::VoiceAssistant::dest_addr_
protected

Definition at line 134 of file voice_assistant.h.

◆ end_trigger_

Trigger* esphome::voice_assistant::VoiceAssistant::end_trigger_ = new Trigger<>()
protected

Definition at line 139 of file voice_assistant.h.

◆ error_trigger_

Trigger<std::string, std::string>* esphome::voice_assistant::VoiceAssistant::error_trigger_ = new Trigger<std::string, std::string>()
protected

Definition at line 151 of file voice_assistant.h.

◆ high_freq_

HighFrequencyLoopRequester esphome::voice_assistant::VoiceAssistant::high_freq_
protected

Definition at line 178 of file voice_assistant.h.

◆ idle_trigger_

Trigger* esphome::voice_assistant::VoiceAssistant::idle_trigger_ = new Trigger<>()
protected

Definition at line 152 of file voice_assistant.h.

◆ input_buffer_

int16_t* esphome::voice_assistant::VoiceAssistant::input_buffer_
protected

Definition at line 193 of file voice_assistant.h.

◆ intent_end_trigger_

Trigger* esphome::voice_assistant::VoiceAssistant::intent_end_trigger_ = new Trigger<>()
protected

Definition at line 136 of file voice_assistant.h.

◆ intent_start_trigger_

Trigger* esphome::voice_assistant::VoiceAssistant::intent_start_trigger_ = new Trigger<>()
protected

Definition at line 137 of file voice_assistant.h.

◆ listening_trigger_

Trigger* esphome::voice_assistant::VoiceAssistant::listening_trigger_ = new Trigger<>()
protected

Definition at line 138 of file voice_assistant.h.

◆ local_output_

bool esphome::voice_assistant::VoiceAssistant::local_output_ {false}
protected

Definition at line 174 of file voice_assistant.h.

◆ media_player_

media_player::MediaPlayer* esphome::voice_assistant::VoiceAssistant::media_player_ {nullptr}
protected

Definition at line 171 of file voice_assistant.h.

◆ mic_

microphone::Microphone* esphome::voice_assistant::VoiceAssistant::mic_ {nullptr}
protected

Definition at line 159 of file voice_assistant.h.

◆ noise_suppression_level_

uint8_t esphome::voice_assistant::VoiceAssistant::noise_suppression_level_
protected

Definition at line 188 of file voice_assistant.h.

◆ ring_buffer_

std::unique_ptr<RingBuffer> esphome::voice_assistant::VoiceAssistant::ring_buffer_
protected

Definition at line 185 of file voice_assistant.h.

◆ send_buffer_

uint8_t* esphome::voice_assistant::VoiceAssistant::send_buffer_
protected

Definition at line 192 of file voice_assistant.h.

◆ silence_detection_

bool esphome::voice_assistant::VoiceAssistant::silence_detection_
protected

Definition at line 196 of file voice_assistant.h.

◆ socket_

std::unique_ptr<socket::Socket> esphome::voice_assistant::VoiceAssistant::socket_ = nullptr
protected

Definition at line 133 of file voice_assistant.h.

◆ speaker_

speaker::Speaker* esphome::voice_assistant::VoiceAssistant::speaker_ {nullptr}
protected

Definition at line 162 of file voice_assistant.h.

◆ speaker_buffer_

uint8_t* esphome::voice_assistant::VoiceAssistant::speaker_buffer_
protected

Definition at line 163 of file voice_assistant.h.

◆ speaker_buffer_index_

size_t esphome::voice_assistant::VoiceAssistant::speaker_buffer_index_ {0}
protected

Definition at line 164 of file voice_assistant.h.

◆ speaker_buffer_size_

size_t esphome::voice_assistant::VoiceAssistant::speaker_buffer_size_ {0}
protected

Definition at line 165 of file voice_assistant.h.

◆ speaker_bytes_received_

size_t esphome::voice_assistant::VoiceAssistant::speaker_bytes_received_ {0}
protected

Definition at line 166 of file voice_assistant.h.

◆ start_trigger_

Trigger* esphome::voice_assistant::VoiceAssistant::start_trigger_ = new Trigger<>()
protected

Definition at line 140 of file voice_assistant.h.

◆ state_

State esphome::voice_assistant::VoiceAssistant::state_ {State::IDLE}
protected

Definition at line 198 of file voice_assistant.h.

◆ stream_ended_

bool esphome::voice_assistant::VoiceAssistant::stream_ended_ {false}
protected

Definition at line 168 of file voice_assistant.h.

◆ stt_end_trigger_

Trigger<std::string>* esphome::voice_assistant::VoiceAssistant::stt_end_trigger_ = new Trigger<std::string>()
protected

Definition at line 148 of file voice_assistant.h.

◆ stt_vad_end_trigger_

Trigger* esphome::voice_assistant::VoiceAssistant::stt_vad_end_trigger_ = new Trigger<>()
protected

Definition at line 142 of file voice_assistant.h.

◆ stt_vad_start_trigger_

Trigger* esphome::voice_assistant::VoiceAssistant::stt_vad_start_trigger_ = new Trigger<>()
protected

Definition at line 141 of file voice_assistant.h.

◆ tts_end_trigger_

Trigger<std::string>* esphome::voice_assistant::VoiceAssistant::tts_end_trigger_ = new Trigger<std::string>()
protected

Definition at line 149 of file voice_assistant.h.

◆ tts_start_trigger_

Trigger<std::string>* esphome::voice_assistant::VoiceAssistant::tts_start_trigger_ = new Trigger<std::string>()
protected

Definition at line 150 of file voice_assistant.h.

◆ tts_stream_end_trigger_

Trigger* esphome::voice_assistant::VoiceAssistant::tts_stream_end_trigger_ = new Trigger<>()
protected

Definition at line 145 of file voice_assistant.h.

◆ tts_stream_start_trigger_

Trigger* esphome::voice_assistant::VoiceAssistant::tts_stream_start_trigger_ = new Trigger<>()
protected

Definition at line 144 of file voice_assistant.h.

◆ use_wake_word_

bool esphome::voice_assistant::VoiceAssistant::use_wake_word_
protected

Definition at line 187 of file voice_assistant.h.

◆ vad_counter_

uint8_t esphome::voice_assistant::VoiceAssistant::vad_counter_ {0}
protected

Definition at line 183 of file voice_assistant.h.

◆ vad_instance_

vad_handle_t esphome::voice_assistant::VoiceAssistant::vad_instance_
protected

Definition at line 181 of file voice_assistant.h.

◆ vad_threshold_

uint8_t esphome::voice_assistant::VoiceAssistant::vad_threshold_ {5}
protected

Definition at line 182 of file voice_assistant.h.

◆ volume_multiplier_

float esphome::voice_assistant::VoiceAssistant::volume_multiplier_
protected

Definition at line 190 of file voice_assistant.h.

◆ wait_for_stream_end_

bool esphome::voice_assistant::VoiceAssistant::wait_for_stream_end_ {false}
protected

Definition at line 167 of file voice_assistant.h.

◆ wake_word_detected_trigger_

Trigger* esphome::voice_assistant::VoiceAssistant::wake_word_detected_trigger_ = new Trigger<>()
protected

Definition at line 147 of file voice_assistant.h.


The documentation for this class was generated from the following files: