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));
82 void setup()
override;
84 float get_setup_priority()
const override;
85 void start_streaming();
87 void failed_to_start();
92 this->speaker_ = speaker;
93 this->local_output_ =
true;
96 #ifdef USE_MEDIA_PLAYER 98 this->media_player_ = media_player;
99 this->local_output_ =
true;
105 if (this->speaker_ !=
nullptr) {
106 return LEGACY_SPEAKER_SUPPORT;
109 return LEGACY_INITIAL_VERSION;
117 if (this->speaker_ !=
nullptr) {
122 if (this->has_timers_) {
129 void request_start(
bool continuous,
bool silence_detection);
146 this->noise_suppression_level_ = noise_suppression_level;
175 void set_wake_word(
const std::string &wake_word) { this->wake_word_ = wake_word; }
183 const std::unordered_map<std::string, Timer> &
get_timers()
const {
return this->timers_; }
186 bool allocate_buffers_();
187 void clear_buffers_();
188 void deallocate_buffers_();
190 int read_microphone_();
192 void set_state_(
State state,
State desired_state);
195 std::unique_ptr<socket::Socket> socket_ =
nullptr;
221 std::unordered_map<std::string, Timer>
timers_;
228 bool has_timers_{
false};
229 bool timer_tick_running_{
false};
233 void write_speaker_();
236 size_t speaker_buffer_index_{0};
237 size_t speaker_buffer_size_{0};
238 size_t speaker_bytes_received_{0};
239 bool wait_for_stream_end_{
false};
240 bool stream_ended_{
false};
242 #ifdef USE_MEDIA_PLAYER 246 bool local_output_{
false};
248 std::string conversation_id_{
""};
250 std::string wake_word_{
""};
256 uint8_t vad_threshold_{5};
257 uint8_t vad_counter_{0};
269 bool continuous_{
false};
276 bool udp_socket_running_{
false};
277 bool start_udp_socket_();
281 TEMPLATABLE_VALUE(std::string, wake_word);
285 this->parent_->set_wake_word(this->wake_word_.value(
x...));
286 this->parent_->request_start(
false, this->silence_detection_);
297 void play(Ts...
x)
override { this->parent_->request_start(
true,
true); }
302 void play(Ts...
x)
override { this->parent_->request_stop(); }
307 bool check(Ts...
x)
override {
return this->parent_->is_running() || this->parent_->is_continuous(); }
312 bool check(Ts...
x)
override {
return this->parent_->get_api_connection() !=
nullptr; }
320 #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
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
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)
bool check(Ts... x) override
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,...)
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
void set_silence_detection(bool silence_detection)
Implementation of SPI Controller mode.
Trigger * get_stt_vad_end_trigger() const
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.