5 #ifdef USE_VOICE_ASSISTANT 18 #ifdef USE_MEDIA_PLAYER 27 #include <unordered_map> 31 namespace voice_assistant {
35 static const uint32_t LEGACY_INITIAL_VERSION = 1;
36 static const uint32_t LEGACY_SPEAKER_SUPPORT = 2;
74 return str_sprintf(
"Timer(id=%s, name=%s, total_seconds=%" PRIu32
", seconds_left=%" PRIu32
", is_active=%s)",
75 this->
id.c_str(), this->name.c_str(), this->total_seconds, this->seconds_left,
76 YESNO(this->is_active));
94 void setup()
override;
96 float get_setup_priority()
const override;
97 void start_streaming();
99 void failed_to_start();
104 this->speaker_ = speaker;
105 this->local_output_ =
true;
108 #ifdef USE_MEDIA_PLAYER 110 this->media_player_ = media_player;
111 this->local_output_ =
true;
117 if (this->speaker_ !=
nullptr) {
118 return LEGACY_SPEAKER_SUPPORT;
121 return LEGACY_INITIAL_VERSION;
129 if (this->speaker_ !=
nullptr) {
134 if (this->has_timers_) {
141 void request_start(
bool continuous,
bool silence_detection);
161 this->noise_suppression_level_ = noise_suppression_level;
166 void reset_conversation_id();
192 void set_wake_word(
const std::string &wake_word) { this->wake_word_ = wake_word; }
200 const std::unordered_map<std::string, Timer> &
get_timers()
const {
return this->timers_; }
203 bool allocate_buffers_();
204 void clear_buffers_();
205 void deallocate_buffers_();
207 int read_microphone_();
209 void set_state_(
State state,
State desired_state);
212 std::unique_ptr<socket::Socket> socket_ =
nullptr;
238 std::unordered_map<std::string, Timer>
timers_;
245 bool has_timers_{
false};
246 bool timer_tick_running_{
false};
250 void write_speaker_();
253 size_t speaker_buffer_index_{0};
254 size_t speaker_buffer_size_{0};
255 size_t speaker_bytes_received_{0};
256 bool wait_for_stream_end_{
false};
257 bool stream_ended_{
false};
259 #ifdef USE_MEDIA_PLAYER 263 bool local_output_{
false};
265 std::string conversation_id_{
""};
267 std::string wake_word_{
""};
273 uint8_t vad_threshold_{5};
274 uint8_t vad_counter_{0};
287 bool continuous_{
false};
294 bool udp_socket_running_{
false};
295 bool start_udp_socket_();
301 TEMPLATABLE_VALUE(std::string, wake_word);
305 this->parent_->set_wake_word(this->wake_word_.value(
x...));
306 this->parent_->request_start(
false, this->silence_detection_);
317 void play(Ts...
x)
override { this->parent_->request_start(
true,
true); }
322 void play(Ts...
x)
override { this->parent_->request_stop(); }
327 bool check(Ts...
x)
override {
return this->parent_->is_running() || this->parent_->is_continuous(); }
332 bool check(Ts...
x)
override {
return this->parent_->get_api_connection() !=
nullptr; }
340 #endif // USE_VOICE_ASSISTANT
Trigger< Timer > * get_timer_finished_trigger() const
void set_microphone(microphone::Microphone *mic)
void play(Ts... x) override
Trigger< Timer > * get_timer_started_trigger() const
void on_set_configuration(const std::vector< std::string > &active_wake_words)
Trigger * get_tts_stream_start_trigger() const
std::unordered_map< std::string, Timer > timers_
Trigger * get_tts_stream_end_trigger() const
HighFrequencyLoopRequester high_freq_
VoiceAssistant * global_voice_assistant
Trigger< Timer > * get_timer_cancelled_trigger() const
vad_handle_t vad_instance_
void set_continuous(bool continuous)
Helper class to request loop() to be called as fast as possible.
void play(Ts... x) override
uint32_t get_legacy_version() const
Trigger * get_client_connected_trigger() const
api::APIConnection * get_api_connection() const
uint32_t conversation_timeout_
const std::unordered_map< std::string, Timer > & get_timers() const
void play(Ts... x) override
uint8_t * speaker_buffer_
Trigger * get_listening_trigger() const
void set_has_timers(bool has_timers)
uint8_t noise_suppression_level_
Trigger< std::vector< Timer > > * get_timer_tick_trigger() const
void set_auto_gain(uint8_t auto_gain)
void set_wake_word(const std::string &wake_word)
void set_noise_suppression_level(uint8_t noise_suppression_level)
std::vector< std::string > trained_languages
bool check(Ts... x) override
uint32_t max_active_wake_words
void set_volume_multiplier(float volume_multiplier)
Base class for all automation conditions.
Trigger * get_idle_trigger() const
Trigger< std::string > * get_tts_start_trigger() const
std::string str_sprintf(const char *fmt,...)
void set_conversation_timeout(uint32_t conversation_timeout)
std::vector< std::string > active_wake_words
Trigger * get_stt_vad_start_trigger() const
Trigger * get_end_trigger() const
Trigger * get_intent_start_trigger() const
Trigger * get_client_disconnected_trigger() const
Trigger * get_wake_word_detected_trigger() const
Trigger< std::string, std::string > * get_error_trigger() const
std::unique_ptr< RingBuffer > ring_buffer_
bool is_continuous() const
void set_speaker(speaker::Speaker *speaker)
Trigger * get_intent_end_trigger() const
void set_vad_threshold(uint8_t vad_threshold)
Trigger< std::string > * get_tts_end_trigger() const
void set_use_wake_word(bool use_wake_word)
void set_media_player(media_player::MediaPlayer *media_player)
bool check(Ts... x) override
uint32_t get_feature_flags() const
std::vector< WakeWord > available_wake_words
void set_silence_detection(bool silence_detection)
Implementation of SPI Controller mode.
Trigger * get_stt_vad_end_trigger() const
const Configuration & get_configuration()
std::string to_string() const
Trigger< std::string > * get_stt_end_trigger() const
Trigger * get_start_trigger() const
Trigger< Timer > * get_timer_updated_trigger() const
Helper class to easily give an object a parent of type T.