mirror of
https://github.com/esphome/esphome.git
synced 2025-09-28 16:12:24 +01:00
Add wake word phrase to voice assistant start command (#6290)
This commit is contained in:
@@ -42,6 +42,8 @@ CONF_AUTO_GAIN = "auto_gain"
|
||||
CONF_NOISE_SUPPRESSION_LEVEL = "noise_suppression_level"
|
||||
CONF_VOLUME_MULTIPLIER = "volume_multiplier"
|
||||
|
||||
CONF_WAKE_WORD = "wake_word"
|
||||
|
||||
|
||||
voice_assistant_ns = cg.esphome_ns.namespace("voice_assistant")
|
||||
VoiceAssistant = voice_assistant_ns.class_("VoiceAssistant", cg.Component)
|
||||
@@ -285,6 +287,7 @@ VOICE_ASSISTANT_ACTION_SCHEMA = cv.Schema({cv.GenerateID(): cv.use_id(VoiceAssis
|
||||
VOICE_ASSISTANT_ACTION_SCHEMA.extend(
|
||||
{
|
||||
cv.Optional(CONF_SILENCE_DETECTION, default=True): cv.boolean,
|
||||
cv.Optional(CONF_WAKE_WORD): cv.templatable(cv.string),
|
||||
}
|
||||
),
|
||||
)
|
||||
@@ -293,6 +296,9 @@ async def voice_assistant_listen_to_code(config, action_id, template_arg, args):
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
if CONF_SILENCE_DETECTION in config:
|
||||
cg.add(var.set_silence_detection(config[CONF_SILENCE_DETECTION]))
|
||||
if wake_word := config.get(CONF_WAKE_WORD):
|
||||
templ = await cg.templatable(wake_word, args, cg.std_string)
|
||||
cg.add(var.set_wake_word(templ))
|
||||
return var
|
||||
|
||||
|
||||
|
@@ -215,6 +215,8 @@ void VoiceAssistant::loop() {
|
||||
msg.conversation_id = this->conversation_id_;
|
||||
msg.flags = flags;
|
||||
msg.audio_settings = audio_settings;
|
||||
msg.wake_word_phrase = this->wake_word_;
|
||||
this->wake_word_ = "";
|
||||
|
||||
if (this->api_client_ == nullptr || !this->api_client_->send_voice_assistant_request(msg)) {
|
||||
ESP_LOGW(TAG, "Could not request start");
|
||||
|
@@ -124,6 +124,8 @@ class VoiceAssistant : public Component {
|
||||
void client_subscription(api::APIConnection *client, bool subscribe);
|
||||
api::APIConnection *get_api_connection() const { return this->api_client_; }
|
||||
|
||||
void set_wake_word(const std::string &wake_word) { this->wake_word_ = wake_word; }
|
||||
|
||||
protected:
|
||||
int read_microphone_();
|
||||
void set_state_(State state);
|
||||
@@ -175,6 +177,8 @@ class VoiceAssistant : public Component {
|
||||
|
||||
std::string conversation_id_{""};
|
||||
|
||||
std::string wake_word_{""};
|
||||
|
||||
HighFrequencyLoopRequester high_freq_;
|
||||
|
||||
#ifdef USE_ESP_ADF
|
||||
@@ -200,8 +204,13 @@ class VoiceAssistant : public Component {
|
||||
};
|
||||
|
||||
template<typename... Ts> class StartAction : public Action<Ts...>, public Parented<VoiceAssistant> {
|
||||
TEMPLATABLE_VALUE(std::string, wake_word);
|
||||
|
||||
public:
|
||||
void play(Ts... x) override { this->parent_->request_start(false, this->silence_detection_); }
|
||||
void play(Ts... x) override {
|
||||
this->parent_->set_wake_word(this->wake_word_.value(x...));
|
||||
this->parent_->request_start(false, this->silence_detection_);
|
||||
}
|
||||
|
||||
void set_silence_detection(bool silence_detection) { this->silence_detection_ = silence_detection; }
|
||||
|
||||
|
Reference in New Issue
Block a user