Skip to content

Commit

Permalink
remove unused code directly sending wake word events to the voice ass…
Browse files Browse the repository at this point in the history
…istant (#126)
  • Loading branch information
kahrendt committed Sep 17, 2024
1 parent 6ab7463 commit 3c23656
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 40 deletions.
16 changes: 0 additions & 16 deletions esphome/components/micro_wake_word/micro_wake_word.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"

#include "esphome/components/voice_assistant/voice_assistant.h"

#ifdef USE_OTA
#include "esphome/components/ota/ota_backend.h"
#endif
Expand All @@ -22,12 +20,6 @@

#include <cmath>

// TODO:
// - does VAD need to be a separate class?
// - setup protocol between micro_wake_word and voice_assistant components
// - voice assistant should handle all decisions, mWW should just send info
// - load trained languages from manifest to expose to voice assistant

namespace esphome {
namespace micro_wake_word {

Expand Down Expand Up @@ -116,7 +108,6 @@ void MicroWakeWord::setup() {

ESP_LOGCONFIG(TAG, "Micro Wake Word initialized");


#ifdef USE_OTA
ota::get_global_ota_callback()->add_on_state_callback(
[this](ota::OTAState state, float progress, uint8_t error, ota::OTAComponent *comp) {
Expand Down Expand Up @@ -355,13 +346,6 @@ void MicroWakeWord::loop() {
detection_event.wake_word->c_str(), (detection_event.average_probability / uint8_to_float_divisor),
(detection_event.max_probability / uint8_to_float_divisor));
this->wake_word_detected_trigger_->trigger(*detection_event.wake_word);

#ifdef USE_VOICE_ASSISTANT
// TODO: potentially remove, as it currently only logs in the voice assistant component
if (voice_assistant::global_voice_assistant != nullptr) {
voice_assistant::global_voice_assistant->on_wake_word(detection_event);
}
#endif
}
}
}
Expand Down
32 changes: 12 additions & 20 deletions esphome/components/voice_assistant/voice_assistant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,13 +491,6 @@ void VoiceAssistant::write_speaker_() {
}
#endif

#ifdef USE_MICRO_WAKE_WORD
// TODO: potentially remove, not currently used to initiate a pipeline
void VoiceAssistant::on_wake_word(const micro_wake_word::DetectionEvent &detection_event) {
ESP_LOGD(TAG, "directly communicated wake word: %s", detection_event.wake_word->c_str());
}
#endif

void VoiceAssistant::client_subscription(api::APIConnection *client, bool subscribe) {
if (!subscribe) {
if (this->api_client_ == nullptr || client != this->api_client_) {
Expand Down Expand Up @@ -774,8 +767,7 @@ void VoiceAssistant::on_event(const api::VoiceAssistantEventResponse &msg) {
if (this->state_ == State::STARTING_PIPELINE) {
// Pipeline ended before starting microphone
this->set_state_(State::IDLE, State::IDLE);
}
else if (this->state_ == State::STREAMING_MICROPHONE) {
} else if (this->state_ == State::STREAMING_MICROPHONE) {
this->ring_buffer_->reset();
#ifdef USE_ESP_ADF
if (this->use_wake_word_) {
Expand Down Expand Up @@ -853,17 +845,17 @@ void VoiceAssistant::on_event(const api::VoiceAssistantEventResponse &msg) {
}

void VoiceAssistant::on_audio(const api::VoiceAssistantAudio &msg) {
#ifdef USE_SPEAKER // We should never get to this function if there is no speaker anyway
if (this->speaker_buffer_index_ + msg.data.length() < SPEAKER_BUFFER_SIZE) {
memcpy(this->speaker_buffer_ + this->speaker_buffer_index_, msg.data.data(), msg.data.length());
this->speaker_buffer_index_ += msg.data.length();
this->speaker_buffer_size_ += msg.data.length();
this->speaker_bytes_received_ += msg.data.length();
ESP_LOGV(TAG, "Received audio: %u bytes from API", msg.data.length());
} else {
ESP_LOGE(TAG, "Cannot receive audio, buffer is full");
}
#endif
#ifdef USE_SPEAKER // We should never get to this function if there is no speaker anyway
if (this->speaker_buffer_index_ + msg.data.length() < SPEAKER_BUFFER_SIZE) {
memcpy(this->speaker_buffer_ + this->speaker_buffer_index_, msg.data.data(), msg.data.length());
this->speaker_buffer_index_ += msg.data.length();
this->speaker_buffer_size_ += msg.data.length();
this->speaker_bytes_received_ += msg.data.length();
ESP_LOGV(TAG, "Received audio: %u bytes from API", msg.data.length());
} else {
ESP_LOGE(TAG, "Cannot receive audio, buffer is full");
}
#endif
}

void VoiceAssistant::on_timer_event(const api::VoiceAssistantTimerEventResponse &msg) {
Expand Down
4 changes: 0 additions & 4 deletions esphome/components/voice_assistant/voice_assistant.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,6 @@ class VoiceAssistant : public Component {
void request_start(bool continuous, bool silence_detection);
void request_stop();

#ifdef USE_MICRO_WAKE_WORD
void on_wake_word(const micro_wake_word::DetectionEvent &detection_event);
#endif

void on_event(const api::VoiceAssistantEventResponse &msg);
void on_audio(const api::VoiceAssistantAudio &msg);
void on_timer_event(const api::VoiceAssistantTimerEventResponse &msg);
Expand Down

0 comments on commit 3c23656

Please sign in to comment.