Skip to content

Commit e78b64e

Browse files
author
Kevin Ahrendt
authored
[voice_assistant] remove unused mWW VAD for end of speech detection (#137)
* remove unused microWakeWord VAD for end of speech detection * remove some missed code
1 parent b74e4ed commit e78b64e

File tree

2 files changed

+2
-65
lines changed

2 files changed

+2
-65
lines changed

esphome/components/voice_assistant/voice_assistant.cpp

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,6 @@ void VoiceAssistant::loop() {
281281
flags |= api::enums::VOICE_ASSISTANT_REQUEST_USE_WAKE_WORD;
282282
if (this->silence_detection_)
283283
flags |= api::enums::VOICE_ASSISTANT_REQUEST_USE_VAD;
284-
else {
285-
this->speech_ms_left_ = this->speech_ms_;
286-
this->silence_ms_left_ = this->silence_ms_;
287-
this->timeout_ms_left_ = this->timeout_ms_;
288-
this->last_loop_ms_ = {};
289-
}
290284

291285
api::VoiceAssistantAudioSettings audio_settings;
292286
audio_settings.noise_suppression_level = this->noise_suppression_level_;
@@ -337,41 +331,6 @@ void VoiceAssistant::loop() {
337331
}
338332
available = this->ring_buffer_->available();
339333
}
340-
341-
#ifdef USE_MICRO_WAKE_WORD_VAD
342-
if (!this->silence_detection_) {
343-
bool new_vad_state = false;
344-
if (this->micro_wake_word_ != nullptr) {
345-
new_vad_state = this->micro_wake_word_->get_vad_state();
346-
}
347-
348-
uint32_t new_loop_ms = millis();
349-
if (this->last_loop_ms_.has_value()) {
350-
uint32_t since_last_loop_ms = new_loop_ms - this->last_loop_ms_.value();
351-
352-
if (new_vad_state && this->last_vad_state_) {
353-
// Speech
354-
this->speech_ms_left_ -= since_last_loop_ms;
355-
this->silence_ms_left_ = this->silence_ms_;
356-
} else if (!new_vad_state && !this->last_vad_state_) {
357-
// No speech
358-
this->silence_ms_left_ -= since_last_loop_ms;
359-
}
360-
361-
this->timeout_ms_left_ -= since_last_loop_ms;
362-
}
363-
this->last_loop_ms_ = new_loop_ms;
364-
this->last_vad_state_ = new_vad_state;
365-
366-
if ((this->timeout_ms_left_ < 0) || ((this->speech_ms_left_ < 0) && (this->silence_ms_left_ < 0))) {
367-
this->signal_stop_();
368-
// TODO: Both of these are hacky... protocol needs to be updated to handle this properly?
369-
this->set_state_(State::STOP_MICROPHONE, State::IDLE);
370-
// this->set_state_(State::STOP_MICROPHONE, State::AWAITING_RESPONSE);
371-
}
372-
#endif
373-
}
374-
375334
break;
376335
}
377336
case State::STOP_MICROPHONE: {
@@ -922,7 +881,7 @@ void VoiceAssistant::on_announce(const api::VoiceAssistantAnnounceRequest &msg)
922881
#endif
923882
}
924883

925-
void VoiceAssistant::on_set_configuration(const std::vector<std::string>& active_wake_words) {
884+
void VoiceAssistant::on_set_configuration(const std::vector<std::string> &active_wake_words) {
926885
if (this->micro_wake_word_) {
927886
// Disable all wake words first
928887
for (auto &model : this->micro_wake_word_->get_wake_words()) {
@@ -934,9 +893,7 @@ void VoiceAssistant::on_set_configuration(const std::vector<std::string>& active
934893
for (auto &model : this->micro_wake_word_->get_wake_words()) {
935894
if (model->get_id() == ww_id) {
936895
model->enable();
937-
ESP_LOGD(TAG, "Enabled wake word: %s (id=%s)",
938-
model->get_wake_word().c_str(),
939-
model->get_id().c_str());
896+
ESP_LOGD(TAG, "Enabled wake word: %s (id=%s)", model->get_wake_word().c_str(), model->get_id().c_str());
940897
}
941898
}
942899
}
@@ -968,7 +925,6 @@ const Configuration &VoiceAssistant::get_configuration() {
968925
this->config_.max_active_wake_words = 0;
969926
}
970927

971-
972928
return this->config_;
973929
};
974930

esphome/components/voice_assistant/voice_assistant.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,6 @@ class VoiceAssistant : public Component {
105105
void set_microphone(microphone::Microphone *mic) { this->mic_ = mic; }
106106
#ifdef USE_MICRO_WAKE_WORD
107107
void set_micro_wake_word(micro_wake_word::MicroWakeWord *mww) { this->micro_wake_word_ = mww; }
108-
#ifdef USE_MICRO_WAKE_WORD_VAD
109-
void set_speech_ms(uint32_t speech_ms) { this->speech_ms_ = speech_ms; }
110-
void set_timeout_ms(uint32_t timeout_ms) { this->timeout_ms_ = timeout_ms; }
111-
void set_silence_ms(uint32_t silence_ms) { this->silence_ms_ = silence_ms; }
112-
#endif
113108
#endif
114109
#ifdef USE_SPEAKER
115110
void set_speaker(speaker::Speaker *speaker) {
@@ -313,20 +308,6 @@ class VoiceAssistant : public Component {
313308

314309
#ifdef USE_MICRO_WAKE_WORD
315310
micro_wake_word::MicroWakeWord *micro_wake_word_{nullptr};
316-
317-
#ifdef USE_MICRO_WAKE_WORD_VAD
318-
uint32_t speech_ms_{500}; // This is hard to configure (HA uses 300) with the current VAD, as it may initially be
319-
// detected from the wake word
320-
uint32_t timeout_ms_{15000};
321-
uint32_t silence_ms_{1000};
322-
323-
int32_t speech_ms_left_{0};
324-
int32_t silence_ms_left_{0};
325-
int32_t timeout_ms_left_{0};
326-
327-
optional<uint32_t> last_loop_ms_;
328-
bool last_vad_state_;
329-
#endif
330311
#endif
331312
}; // namespace voice_assistant
332313

0 commit comments

Comments
 (0)