Voice assist improvement - configurable conversation_id timeout (#7385)

This commit is contained in:
Jeff Cooper 2024-09-03 23:48:13 -04:00 committed by GitHub
parent a7fd3b34aa
commit e882cea47e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 17 additions and 1 deletions

View File

@ -43,6 +43,8 @@ CONF_VOLUME_MULTIPLIER = "volume_multiplier"
CONF_WAKE_WORD = "wake_word" CONF_WAKE_WORD = "wake_word"
CONF_CONVERSATION_TIMEOUT = "conversation_timeout"
CONF_ON_TIMER_STARTED = "on_timer_started" CONF_ON_TIMER_STARTED = "on_timer_started"
CONF_ON_TIMER_UPDATED = "on_timer_updated" CONF_ON_TIMER_UPDATED = "on_timer_updated"
CONF_ON_TIMER_CANCELLED = "on_timer_cancelled" CONF_ON_TIMER_CANCELLED = "on_timer_cancelled"
@ -100,6 +102,9 @@ CONFIG_SCHEMA = cv.All(
cv.float_with_unit("decibel full scale", "(dBFS|dbfs|DBFS)"), cv.float_with_unit("decibel full scale", "(dBFS|dbfs|DBFS)"),
cv.int_range(0, 31), cv.int_range(0, 31),
), ),
cv.Optional(
CONF_CONVERSATION_TIMEOUT, default="300s"
): cv.positive_time_period_milliseconds,
cv.Optional(CONF_VOLUME_MULTIPLIER, default=1.0): cv.float_range( cv.Optional(CONF_VOLUME_MULTIPLIER, default=1.0): cv.float_range(
min=0.0, min_included=False min=0.0, min_included=False
), ),
@ -182,6 +187,7 @@ async def to_code(config):
cg.add(var.set_noise_suppression_level(config[CONF_NOISE_SUPPRESSION_LEVEL])) cg.add(var.set_noise_suppression_level(config[CONF_NOISE_SUPPRESSION_LEVEL]))
cg.add(var.set_auto_gain(config[CONF_AUTO_GAIN])) cg.add(var.set_auto_gain(config[CONF_AUTO_GAIN]))
cg.add(var.set_volume_multiplier(config[CONF_VOLUME_MULTIPLIER])) cg.add(var.set_volume_multiplier(config[CONF_VOLUME_MULTIPLIER]))
cg.add(var.set_conversation_timeout(config[CONF_CONVERSATION_TIMEOUT]))
if CONF_ON_LISTENING in config: if CONF_ON_LISTENING in config:
await automation.build_automation( await automation.build_automation(

View File

@ -171,6 +171,11 @@ void VoiceAssistant::deallocate_buffers_() {
#endif #endif
} }
void VoiceAssistant::reset_conversation_id() {
this->conversation_id_ = "";
ESP_LOGD(TAG, "reset conversation ID");
}
int VoiceAssistant::read_microphone_() { int VoiceAssistant::read_microphone_() {
size_t bytes_read = 0; size_t bytes_read = 0;
if (this->mic_->is_running()) { // Read audio into input buffer if (this->mic_->is_running()) { // Read audio into input buffer
@ -299,7 +304,8 @@ void VoiceAssistant::loop() {
break; break;
} }
this->set_state_(State::STARTING_PIPELINE); this->set_state_(State::STARTING_PIPELINE);
this->set_timeout("reset-conversation_id", 5 * 60 * 1000, [this]() { this->conversation_id_ = ""; }); this->set_timeout("reset-conversation_id", this->conversation_timeout_,
[this]() { this->reset_conversation_id(); });
break; break;
} }
case State::STARTING_PIPELINE: { case State::STARTING_PIPELINE: {

View File

@ -147,6 +147,8 @@ class VoiceAssistant : public Component {
} }
void set_auto_gain(uint8_t auto_gain) { this->auto_gain_ = auto_gain; } void set_auto_gain(uint8_t auto_gain) { this->auto_gain_ = auto_gain; }
void set_volume_multiplier(float volume_multiplier) { this->volume_multiplier_ = volume_multiplier; } void set_volume_multiplier(float volume_multiplier) { this->volume_multiplier_ = volume_multiplier; }
void set_conversation_timeout(uint32_t conversation_timeout) { this->conversation_timeout_ = conversation_timeout; }
void reset_conversation_id();
Trigger<> *get_intent_end_trigger() const { return this->intent_end_trigger_; } Trigger<> *get_intent_end_trigger() const { return this->intent_end_trigger_; }
Trigger<> *get_intent_start_trigger() const { return this->intent_start_trigger_; } Trigger<> *get_intent_start_trigger() const { return this->intent_start_trigger_; }
@ -262,6 +264,7 @@ class VoiceAssistant : public Component {
uint8_t noise_suppression_level_; uint8_t noise_suppression_level_;
uint8_t auto_gain_; uint8_t auto_gain_;
float volume_multiplier_; float volume_multiplier_;
uint32_t conversation_timeout_;
uint8_t *send_buffer_; uint8_t *send_buffer_;
int16_t *input_buffer_; int16_t *input_buffer_;

View File

@ -33,6 +33,7 @@ speaker:
voice_assistant: voice_assistant:
microphone: mic_id_external microphone: mic_id_external
speaker: speaker_id speaker: speaker_id
conversation_timeout: 60s
on_listening: on_listening:
- logger.log: "Voice assistant microphone listening" - logger.log: "Voice assistant microphone listening"
on_start: on_start: