Claude esdited

This commit is contained in:
radu
2026-12-02 14:25:40 +07:00
parent a078d7b9db
commit 20c975894d
+39 -13
View File
@@ -39,9 +39,7 @@ voice_assistant:
gain_factor: 2 gain_factor: 2
noise_suppression_level: 2 noise_suppression_level: 2
auto_gain: 20dBFS auto_gain: 20dBFS
# wakeword_config:
# threshold: 0.8
# pause_seconds: 2.0
on_start: on_start:
- light.turn_on: - light.turn_on:
@@ -51,7 +49,7 @@ voice_assistant:
blue: 0% blue: 0%
brightness: 15% brightness: 15%
effect: none effect: none
- script.execute: listening_timeout
on_listening: on_listening:
- light.turn_on: - light.turn_on:
@@ -62,12 +60,16 @@ voice_assistant:
effect: none effect: none
- lambda: id(voice_assistant_phase) = 2; - lambda: id(voice_assistant_phase) = 2;
- lambda: id(stt_vad_started) = false; - lambda: id(stt_vad_started) = false;
# Wake word detected, command recording starts -> start the max-length timer
- script.execute: listening_timeout
on_stt_vad_start: on_stt_vad_start:
# Turn off the script if speech is detected # Turn off the script if speech is detected
- lambda: id(stt_vad_started) = true; - lambda: id(stt_vad_started) = true;
on_stt_vad_end: on_stt_vad_end:
- lambda: id(voice_assistant_phase) = 3; # recording finished, HA is processing
- script.stop: listening_timeout
#- logger.log: "===============================VAD is the END ==================================" #- logger.log: "===============================VAD is the END =================================="
- light.turn_on: - light.turn_on:
id: led id: led
@@ -77,6 +79,8 @@ voice_assistant:
effect: none effect: none
on_stt_end: on_stt_end:
- lambda: id(voice_assistant_phase) = 3;
- script.stop: listening_timeout
- logger.log: - logger.log:
format: "STT text: %s" format: "STT text: %s"
args: ["x.c_str()"] args: ["x.c_str()"]
@@ -108,10 +112,21 @@ voice_assistant:
announce: "false" announce: "false"
on_end: on_end:
# No local speaker/media_player, so ESPHome never reports playback as finished
# and HA keeps the satellite in "responding". Report it ourselves.
- lambda: |-
auto *conn = id(va).get_api_connection();
if (conn != nullptr) {
api::VoiceAssistantAnnounceFinished msg;
msg.success = true;
if (!conn->send_message(msg)) {
ESP_LOGW("va", "Could not send announce-finished to HA");
}
}
- lambda: id(voice_assistant_phase) = 1; - lambda: id(voice_assistant_phase) = 1;
- lambda: id(stt_vad_started) = false; - lambda: id(stt_vad_started) = false;
- script.execute: start_wake_word - script.execute: start_wake_word
#- voice_assistant.start:
on_error: on_error:
- if: - if:
@@ -166,7 +181,7 @@ script:
then: then:
- switch.turn_on: - switch.turn_on:
id: rbt id: rbt
- id: listening_timeout - id: listening_timeout
mode: restart mode: restart
then: then:
- delay: ${listenTimeout} - delay: ${listenTimeout}
@@ -176,14 +191,25 @@ script:
- if: - if:
condition: condition:
lambda: |- lambda: |-
return id(voice_assistant_phase) == 2 && !id(stt_vad_started); return id(voice_assistant_phase) == 2;
then: then:
- logger.log: "+++++++++++++++++++++++++ reset ==========================================" - if:
- light.turn_off: condition:
id: led lambda: 'return id(stt_vad_started);'
- voice_assistant.stop: then:
- delay: 1s # Speech is still going after the max time: stop the mic.
- script.execute: start_wake_word # HA processes the audio received so far; on_end restarts the wake word.
- logger.log: "Max listen time reached, stopping audio stream"
- lambda: id(voice_assistant_phase) = 3;
- voice_assistant.stop:
else:
# No speech at all: abort and return to wake word listening
- logger.log: "No speech detected, back to wake word"
- light.turn_off:
id: led
- voice_assistant.stop:
- delay: 1s
- script.execute: start_wake_word
- id: start_wake_word - id: start_wake_word
then: then: