5 #ifdef USE_VOICE_ASSISTANT 18 #ifdef USE_MEDIA_PLAYER 28 namespace voice_assistant {
32 static const uint32_t LEGACY_INITIAL_VERSION = 1;
33 static const uint32_t LEGACY_SPEAKER_SUPPORT = 2;
64 void setup()
override;
66 float get_setup_priority()
const override;
67 void start_streaming();
69 void failed_to_start();
74 this->speaker_ = speaker;
75 this->local_output_ =
true;
78 #ifdef USE_MEDIA_PLAYER 80 this->media_player_ = media_player;
81 this->local_output_ =
true;
87 if (this->speaker_ !=
nullptr) {
88 return LEGACY_SPEAKER_SUPPORT;
91 return LEGACY_INITIAL_VERSION;
98 if (this->speaker_ !=
nullptr) {
106 void request_start(
bool continuous,
bool silence_detection);
122 this->noise_suppression_level_ = noise_suppression_level;
151 void set_wake_word(
const std::string &wake_word) { this->wake_word_ = wake_word; }
154 int read_microphone_();
156 void set_state_(
State state,
State desired_state);
159 std::unique_ptr<socket::Socket> socket_ =
nullptr;
187 void write_speaker_();
190 size_t speaker_buffer_index_{0};
191 size_t speaker_buffer_size_{0};
192 size_t speaker_bytes_received_{0};
193 bool wait_for_stream_end_{
false};
194 bool stream_ended_{
false};
196 #ifdef USE_MEDIA_PLAYER 200 bool local_output_{
false};
202 std::string conversation_id_{
""};
204 std::string wake_word_{
""};
210 uint8_t vad_threshold_{5};
211 uint8_t vad_counter_{0};
223 bool continuous_{
false};
230 bool udp_socket_running_{
false};
231 bool start_udp_socket_();
235 TEMPLATABLE_VALUE(std::string, wake_word);
239 this->parent_->set_wake_word(this->wake_word_.value(
x...));
240 this->parent_->request_start(
false, this->silence_detection_);
251 void play(Ts...
x)
override { this->parent_->request_start(
true,
true); }
256 void play(Ts...
x)
override { this->parent_->request_stop(); }
261 bool check(Ts...
x)
override {
return this->parent_->is_running() || this->parent_->is_continuous(); }
266 bool check(Ts...
x)
override {
return this->parent_->get_api_connection() !=
nullptr; }
274 #endif // USE_VOICE_ASSISTANT
void set_microphone(microphone::Microphone *mic)
void play(Ts... x) override
Trigger * get_tts_stream_start_trigger() const
Trigger * get_tts_stream_end_trigger() const
HighFrequencyLoopRequester high_freq_
VoiceAssistant * global_voice_assistant
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
void play(Ts... x) override
uint8_t * speaker_buffer_
Trigger * get_listening_trigger() const
uint8_t noise_suppression_level_
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
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)
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Trigger * get_stt_vad_end_trigger() const
Trigger< std::string > * get_stt_end_trigger() const
Trigger * get_start_trigger() const
Helper class to easily give an object a parent of type T.