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));
97 float get_setup_priority()
const override;
98 void start_streaming();
100 void failed_to_start();
105 this->speaker_ = speaker;
106 this->local_output_ =
true;
109 #ifdef USE_MEDIA_PLAYER 111 this->media_player_ = media_player;
112 this->local_output_ =
true;
118 if (this->speaker_ !=
nullptr) {
119 return LEGACY_SPEAKER_SUPPORT;
122 return LEGACY_INITIAL_VERSION;
130 if (this->speaker_ !=
nullptr) {
135 if (this->has_timers_) {
142 void request_start(
bool continuous,
bool silence_detection);
162 this->noise_suppression_level_ = noise_suppression_level;
167 void reset_conversation_id();
193 void set_wake_word(
const std::string &wake_word) { this->wake_word_ = wake_word; }
201 const std::unordered_map<std::string, Timer> &
get_timers()
const {
return this->timers_; }
204 bool allocate_buffers_();
205 void clear_buffers_();
206 void deallocate_buffers_();
208 int read_microphone_();
210 void set_state_(
State state,
State desired_state);
213 std::unique_ptr<socket::Socket> socket_ =
nullptr;
239 std::unordered_map<std::string, Timer>
timers_;
246 bool has_timers_{
false};
247 bool timer_tick_running_{
false};
251 void write_speaker_();
253 uint8_t *speaker_buffer_{
nullptr};
254 size_t speaker_buffer_index_{0};
255 size_t speaker_buffer_size_{0};
256 size_t speaker_bytes_received_{0};
257 bool wait_for_stream_end_{
false};
258 bool stream_ended_{
false};
260 #ifdef USE_MEDIA_PLAYER 264 bool local_output_{
false};
266 std::string conversation_id_{
""};
268 std::string wake_word_{
""};
274 uint8_t vad_threshold_{5};
275 uint8_t vad_counter_{0};
285 uint8_t *send_buffer_{
nullptr};
286 int16_t *input_buffer_{
nullptr};
288 bool continuous_{
false};
295 bool udp_socket_running_{
false};
296 bool start_udp_socket_();
302 TEMPLATABLE_VALUE(std::string, wake_word);
306 this->parent_->set_wake_word(this->wake_word_.value(
x...));
307 this->parent_->request_start(
false, this->silence_detection_);
318 void play(Ts...
x)
override { this->parent_->request_start(
true,
true); }
323 void play(Ts...
x)
override { this->parent_->request_stop(); }
328 bool check(Ts...
x)
override {
return this->parent_->is_running() || this->parent_->is_continuous(); }
333 bool check(Ts...
x)
override {
return this->parent_->get_api_connection() !=
nullptr; }
341 #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
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.