mirror of
https://github.com/esphome/esphome.git
synced 2025-11-19 16:25:50 +00:00
[micro_wake_word] Add wake_loop_threadsafe() for low-latency wake word detection (#11698)
This commit is contained in:
@@ -7,7 +7,7 @@ from urllib.parse import urljoin
|
|||||||
from esphome import automation, external_files, git
|
from esphome import automation, external_files, git
|
||||||
from esphome.automation import register_action, register_condition
|
from esphome.automation import register_action, register_condition
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
from esphome.components import esp32, microphone
|
from esphome.components import esp32, microphone, socket
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.const import (
|
from esphome.const import (
|
||||||
CONF_FILE,
|
CONF_FILE,
|
||||||
@@ -32,6 +32,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
CODEOWNERS = ["@kahrendt", "@jesserockz"]
|
CODEOWNERS = ["@kahrendt", "@jesserockz"]
|
||||||
DEPENDENCIES = ["microphone"]
|
DEPENDENCIES = ["microphone"]
|
||||||
|
AUTO_LOAD = ["socket"]
|
||||||
DOMAIN = "micro_wake_word"
|
DOMAIN = "micro_wake_word"
|
||||||
|
|
||||||
|
|
||||||
@@ -443,6 +444,10 @@ async def to_code(config):
|
|||||||
var = cg.new_Pvariable(config[CONF_ID])
|
var = cg.new_Pvariable(config[CONF_ID])
|
||||||
await cg.register_component(var, config)
|
await cg.register_component(var, config)
|
||||||
|
|
||||||
|
# Enable wake_loop_threadsafe() for low-latency wake word detection
|
||||||
|
# The inference task queues detection events that need immediate processing
|
||||||
|
socket.require_wake_loop_threadsafe()
|
||||||
|
|
||||||
mic_source = await microphone.microphone_source_to_code(config[CONF_MICROPHONE])
|
mic_source = await microphone.microphone_source_to_code(config[CONF_MICROPHONE])
|
||||||
cg.add(var.set_microphone_source(mic_source))
|
cg.add(var.set_microphone_source(mic_source))
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#ifdef USE_ESP_IDF
|
#ifdef USE_ESP_IDF
|
||||||
|
|
||||||
|
#include "esphome/core/application.h"
|
||||||
#include "esphome/core/hal.h"
|
#include "esphome/core/hal.h"
|
||||||
#include "esphome/core/helpers.h"
|
#include "esphome/core/helpers.h"
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
@@ -426,6 +427,12 @@ void MicroWakeWord::process_probabilities_() {
|
|||||||
if (vad_state.detected) {
|
if (vad_state.detected) {
|
||||||
#endif
|
#endif
|
||||||
xQueueSend(this->detection_queue_, &wake_word_state, portMAX_DELAY);
|
xQueueSend(this->detection_queue_, &wake_word_state, portMAX_DELAY);
|
||||||
|
|
||||||
|
// Wake main loop immediately to process wake word detection
|
||||||
|
#if defined(USE_SOCKET_SELECT_SUPPORT) && defined(USE_WAKE_LOOP_THREADSAFE)
|
||||||
|
App.wake_loop_threadsafe();
|
||||||
|
#endif
|
||||||
|
|
||||||
model->reset_probabilities();
|
model->reset_probabilities();
|
||||||
#ifdef USE_MICRO_WAKE_WORD_VAD
|
#ifdef USE_MICRO_WAKE_WORD_VAD
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user