mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 21:44:55 +01:00
Voice Assistant: add on_idle trigger and fix nevermind (#6141)
This commit is contained in:
parent
4eb04afa62
commit
fb16e6b027
3 changed files with 16 additions and 0 deletions
|
@ -32,6 +32,7 @@ CONF_ON_TTS_START = "on_tts_start"
|
||||||
CONF_ON_TTS_STREAM_START = "on_tts_stream_start"
|
CONF_ON_TTS_STREAM_START = "on_tts_stream_start"
|
||||||
CONF_ON_TTS_STREAM_END = "on_tts_stream_end"
|
CONF_ON_TTS_STREAM_END = "on_tts_stream_end"
|
||||||
CONF_ON_WAKE_WORD_DETECTED = "on_wake_word_detected"
|
CONF_ON_WAKE_WORD_DETECTED = "on_wake_word_detected"
|
||||||
|
CONF_ON_IDLE = "on_idle"
|
||||||
|
|
||||||
CONF_SILENCE_DETECTION = "silence_detection"
|
CONF_SILENCE_DETECTION = "silence_detection"
|
||||||
CONF_USE_WAKE_WORD = "use_wake_word"
|
CONF_USE_WAKE_WORD = "use_wake_word"
|
||||||
|
@ -127,6 +128,7 @@ CONFIG_SCHEMA = cv.All(
|
||||||
cv.Optional(CONF_ON_TTS_STREAM_END): automation.validate_automation(
|
cv.Optional(CONF_ON_TTS_STREAM_END): automation.validate_automation(
|
||||||
single=True
|
single=True
|
||||||
),
|
),
|
||||||
|
cv.Optional(CONF_ON_IDLE): automation.validate_automation(single=True),
|
||||||
}
|
}
|
||||||
).extend(cv.COMPONENT_SCHEMA),
|
).extend(cv.COMPONENT_SCHEMA),
|
||||||
tts_stream_validate,
|
tts_stream_validate,
|
||||||
|
@ -259,6 +261,13 @@ async def to_code(config):
|
||||||
config[CONF_ON_TTS_STREAM_END],
|
config[CONF_ON_TTS_STREAM_END],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if CONF_ON_IDLE in config:
|
||||||
|
await automation.build_automation(
|
||||||
|
var.get_idle_trigger(),
|
||||||
|
[],
|
||||||
|
config[CONF_ON_IDLE],
|
||||||
|
)
|
||||||
|
|
||||||
cg.add_define("USE_VOICE_ASSISTANT")
|
cg.add_define("USE_VOICE_ASSISTANT")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -135,6 +135,8 @@ void VoiceAssistant::loop() {
|
||||||
switch (this->state_) {
|
switch (this->state_) {
|
||||||
case State::IDLE: {
|
case State::IDLE: {
|
||||||
if (this->continuous_ && this->desired_state_ == State::IDLE) {
|
if (this->continuous_ && this->desired_state_ == State::IDLE) {
|
||||||
|
this->idle_trigger_->trigger();
|
||||||
|
|
||||||
this->ring_buffer_->reset();
|
this->ring_buffer_->reset();
|
||||||
#ifdef USE_ESP_ADF
|
#ifdef USE_ESP_ADF
|
||||||
if (this->use_wake_word_) {
|
if (this->use_wake_word_) {
|
||||||
|
@ -618,6 +620,9 @@ void VoiceAssistant::on_event(const api::VoiceAssistantEventResponse &msg) {
|
||||||
{
|
{
|
||||||
this->set_state_(State::IDLE, State::IDLE);
|
this->set_state_(State::IDLE, State::IDLE);
|
||||||
}
|
}
|
||||||
|
} else if (this->state_ == State::AWAITING_RESPONSE) {
|
||||||
|
// No TTS start event ("nevermind")
|
||||||
|
this->set_state_(State::IDLE, State::IDLE);
|
||||||
}
|
}
|
||||||
this->defer([this]() { this->end_trigger_->trigger(); });
|
this->defer([this]() { this->end_trigger_->trigger(); });
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -116,6 +116,7 @@ class VoiceAssistant : public Component {
|
||||||
Trigger<std::string> *get_tts_end_trigger() const { return this->tts_end_trigger_; }
|
Trigger<std::string> *get_tts_end_trigger() const { return this->tts_end_trigger_; }
|
||||||
Trigger<std::string> *get_tts_start_trigger() const { return this->tts_start_trigger_; }
|
Trigger<std::string> *get_tts_start_trigger() const { return this->tts_start_trigger_; }
|
||||||
Trigger<std::string, std::string> *get_error_trigger() const { return this->error_trigger_; }
|
Trigger<std::string, std::string> *get_error_trigger() const { return this->error_trigger_; }
|
||||||
|
Trigger<> *get_idle_trigger() const { return this->idle_trigger_; }
|
||||||
|
|
||||||
Trigger<> *get_client_connected_trigger() const { return this->client_connected_trigger_; }
|
Trigger<> *get_client_connected_trigger() const { return this->client_connected_trigger_; }
|
||||||
Trigger<> *get_client_disconnected_trigger() const { return this->client_disconnected_trigger_; }
|
Trigger<> *get_client_disconnected_trigger() const { return this->client_disconnected_trigger_; }
|
||||||
|
@ -148,6 +149,7 @@ class VoiceAssistant : public Component {
|
||||||
Trigger<std::string> *tts_end_trigger_ = new Trigger<std::string>();
|
Trigger<std::string> *tts_end_trigger_ = new Trigger<std::string>();
|
||||||
Trigger<std::string> *tts_start_trigger_ = new Trigger<std::string>();
|
Trigger<std::string> *tts_start_trigger_ = new Trigger<std::string>();
|
||||||
Trigger<std::string, std::string> *error_trigger_ = new Trigger<std::string, std::string>();
|
Trigger<std::string, std::string> *error_trigger_ = new Trigger<std::string, std::string>();
|
||||||
|
Trigger<> *idle_trigger_ = new Trigger<>();
|
||||||
|
|
||||||
Trigger<> *client_connected_trigger_ = new Trigger<>();
|
Trigger<> *client_connected_trigger_ = new Trigger<>();
|
||||||
Trigger<> *client_disconnected_trigger_ = new Trigger<>();
|
Trigger<> *client_disconnected_trigger_ = new Trigger<>();
|
||||||
|
|
Loading…
Reference in a new issue