Skip to content

Commit

Permalink
Add announce
Browse files Browse the repository at this point in the history
  • Loading branch information
synesthesiam committed Sep 3, 2024
1 parent f356cc1 commit 8a8d980
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
16 changes: 15 additions & 1 deletion esphome/components/voice_assistant/voice_assistant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ void VoiceAssistant::loop() {
msg.audio_settings = audio_settings;
msg.wake_word_phrase = this->wake_word_;
this->wake_word_ = "";
msg.pipeline_run_id = this->pipeline_run_id_;
this->pipeline_run_id_ = "";

if (this->api_client_ == nullptr || !this->api_client_->send_voice_assistant_request(msg)) {
ESP_LOGW(TAG, "Could not request start");
Expand Down Expand Up @@ -719,7 +721,11 @@ void VoiceAssistant::on_event(const api::VoiceAssistantEventResponse &msg) {
}
case api::enums::VOICE_ASSISTANT_RUN_END: {
ESP_LOGD(TAG, "Assist Pipeline ended");
if (this->state_ == State::STREAMING_MICROPHONE) {
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) {
this->ring_buffer_->reset();
#ifdef USE_ESP_ADF
if (this->use_wake_word_) {
Expand Down Expand Up @@ -865,6 +871,14 @@ void VoiceAssistant::timer_tick_() {
this->timer_tick_trigger_->trigger(res);
}

void VoiceAssistant::on_announce(const api::VoiceAssistantAnnounce &msg) {
#ifdef USE_MEDIA_PLAYER
if (this->media_player_ != nullptr) {
this->media_player_->make_call().set_media_url(msg.media_id).set_announcement(true).perform();
}
#endif
}

VoiceAssistant *global_voice_assistant = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)

} // namespace voice_assistant
Expand Down
8 changes: 8 additions & 0 deletions esphome/components/voice_assistant/voice_assistant.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ enum VoiceAssistantFeature : uint32_t {
FEATURE_SPEAKER = 1 << 1,
FEATURE_API_AUDIO = 1 << 2,
FEATURE_TIMERS = 1 << 3,
FEATURE_ANNOUNCE = 1 << 4,
};

enum class State {
Expand Down Expand Up @@ -124,6 +125,10 @@ class VoiceAssistant : public Component {
flags |= VoiceAssistantFeature::FEATURE_TIMERS;
}

if (this->media_player_ != nullptr) {
flags |= VoiceAssistantFeature::FEATURE_ANNOUNCE;
}

return flags;
}

Expand All @@ -133,6 +138,7 @@ class VoiceAssistant : public Component {
void on_event(const api::VoiceAssistantEventResponse &msg);
void on_audio(const api::VoiceAssistantAudio &msg);
void on_timer_event(const api::VoiceAssistantTimerEventResponse &msg);
void on_announce(const api::VoiceAssistantAnnounce &msg);

bool is_running() const { return this->state_ != State::IDLE; }
void set_continuous(bool continuous) { this->continuous_ = continuous; }
Expand Down Expand Up @@ -250,6 +256,8 @@ class VoiceAssistant : public Component {

std::string wake_word_{""};

std::string pipeline_run_id_{""};

HighFrequencyLoopRequester high_freq_;

#ifdef USE_ESP_ADF
Expand Down

0 comments on commit 8a8d980

Please sign in to comment.