1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-01 15:41:52 +00:00

Compare commits

...

9 Commits

Author SHA1 Message Date
Jesse Hills
d72ab25d46 Merge pull request #6804 from esphome/bump-2024.5.3
2024.5.3
2024-05-25 08:24:38 +12:00
Jesse Hills
af755380b7 Bump version to 2024.5.3 2024-05-25 08:14:39 +12:00
Jesse Hills
04db724295 [voice_assistant] Don't allocate buffers until starting the microphone for the first time (#6800) 2024-05-25 08:14:39 +12:00
Jesse Hills
0ee4348777 Merge pull request #6786 from esphome/bump-2024.5.2
2024.5.2
2024-05-21 12:29:09 +12:00
Jesse Hills
fcdf36e991 Bump version to 2024.5.2 2024-05-21 11:07:20 +12:00
esphomebot
5eb8efd8b3 Update webserver local assets to 20240519-215627 (#6779) 2024-05-21 11:07:20 +12:00
Jesse Hills
cd0f557940 [remote_receiver] Add better error message for tolerance breaking change (#6784) 2024-05-21 11:07:20 +12:00
J. Nick Koston
efde677ca9 Fix DashboardEntries.all() call (#6783) 2024-05-21 11:07:20 +12:00
J. Nick Koston
2eebee1de7 Revert "Fix MQTT dashboard discovery (Exception in MqttStatusThread)." (#6782) 2024-05-21 11:07:20 +12:00
8 changed files with 4074 additions and 4017 deletions

View File

@@ -63,7 +63,13 @@ def validate_tolerance(value):
if "%" in str(value):
type_ = TYPE_PERCENTAGE
else:
type_ = TYPE_TIME
try:
cv.positive_time_period_microseconds(value)
type_ = TYPE_TIME
except cv.Invalid as exc:
raise cv.Invalid(
"Tolerance must be a percentage or time. Configurations made before 2024.5.0 treated the value as a percentage."
) from exc
return TOLERANCE_SCHEMA(
{

View File

@@ -71,6 +71,12 @@ void VoiceAssistant::setup() {
ESP_LOGCONFIG(TAG, "Setting up Voice Assistant...");
global_voice_assistant = this;
}
bool VoiceAssistant::allocate_buffers_() {
if (this->send_buffer_ != nullptr) {
return true; // Already allocated
}
#ifdef USE_SPEAKER
if (this->speaker_ != nullptr) {
@@ -78,8 +84,7 @@ void VoiceAssistant::setup() {
this->speaker_buffer_ = speaker_allocator.allocate(SPEAKER_BUFFER_SIZE);
if (this->speaker_buffer_ == nullptr) {
ESP_LOGW(TAG, "Could not allocate speaker buffer");
this->mark_failed();
return;
return false;
}
}
#endif
@@ -88,8 +93,7 @@ void VoiceAssistant::setup() {
this->input_buffer_ = allocator.allocate(INPUT_BUFFER_SIZE);
if (this->input_buffer_ == nullptr) {
ESP_LOGW(TAG, "Could not allocate input buffer");
this->mark_failed();
return;
return false;
}
#ifdef USE_ESP_ADF
@@ -99,17 +103,71 @@ void VoiceAssistant::setup() {
this->ring_buffer_ = RingBuffer::create(BUFFER_SIZE * sizeof(int16_t));
if (this->ring_buffer_ == nullptr) {
ESP_LOGW(TAG, "Could not allocate ring buffer");
this->mark_failed();
return;
return false;
}
ExternalRAMAllocator<uint8_t> send_allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE);
this->send_buffer_ = send_allocator.allocate(SEND_BUFFER_SIZE);
if (send_buffer_ == nullptr) {
ESP_LOGW(TAG, "Could not allocate send buffer");
this->mark_failed();
return;
return false;
}
return true;
}
void VoiceAssistant::clear_buffers_() {
if (this->send_buffer_ != nullptr) {
memset(this->send_buffer_, 0, SEND_BUFFER_SIZE);
}
if (this->input_buffer_ != nullptr) {
memset(this->input_buffer_, 0, INPUT_BUFFER_SIZE * sizeof(int16_t));
}
if (this->ring_buffer_ != nullptr) {
this->ring_buffer_->reset();
}
#ifdef USE_SPEAKER
if (this->speaker_buffer_ != nullptr) {
memset(this->speaker_buffer_, 0, SPEAKER_BUFFER_SIZE);
this->speaker_buffer_size_ = 0;
this->speaker_buffer_index_ = 0;
this->speaker_bytes_received_ = 0;
}
#endif
}
void VoiceAssistant::deallocate_buffers_() {
ExternalRAMAllocator<uint8_t> send_deallocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE);
send_deallocator.deallocate(this->send_buffer_, SEND_BUFFER_SIZE);
this->send_buffer_ = nullptr;
if (this->ring_buffer_ != nullptr) {
this->ring_buffer_.reset();
this->ring_buffer_ = nullptr;
}
#ifdef USE_ESP_ADF
if (this->vad_instance_ != nullptr) {
vad_destroy(this->vad_instance_);
this->vad_instance_ = nullptr;
}
#endif
ExternalRAMAllocator<int16_t> input_deallocator(ExternalRAMAllocator<int16_t>::ALLOW_FAILURE);
input_deallocator.deallocate(this->input_buffer_, INPUT_BUFFER_SIZE);
this->input_buffer_ = nullptr;
#ifdef USE_SPEAKER
if (this->speaker_buffer_ != nullptr) {
ExternalRAMAllocator<uint8_t> speaker_deallocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE);
speaker_deallocator.deallocate(this->speaker_buffer_, SPEAKER_BUFFER_SIZE);
this->speaker_buffer_ = nullptr;
}
#endif
}
int VoiceAssistant::read_microphone_() {
@@ -138,14 +196,13 @@ void VoiceAssistant::loop() {
}
this->continuous_ = false;
this->signal_stop_();
this->clear_buffers_();
return;
}
switch (this->state_) {
case State::IDLE: {
if (this->continuous_ && this->desired_state_ == State::IDLE) {
this->idle_trigger_->trigger();
this->ring_buffer_->reset();
#ifdef USE_ESP_ADF
if (this->use_wake_word_) {
this->set_state_(State::START_MICROPHONE, State::WAIT_FOR_VAD);
@@ -161,8 +218,15 @@ void VoiceAssistant::loop() {
}
case State::START_MICROPHONE: {
ESP_LOGD(TAG, "Starting Microphone");
memset(this->send_buffer_, 0, SEND_BUFFER_SIZE);
memset(this->input_buffer_, 0, INPUT_BUFFER_SIZE * sizeof(int16_t));
if (!this->allocate_buffers_()) {
this->status_set_error("Failed to allocate buffers");
return;
}
if (this->status_has_error()) {
this->status_clear_error();
}
this->clear_buffers_();
this->mic_->start();
this->high_freq_.start();
this->set_state_(State::STARTING_MICROPHONE);
@@ -343,10 +407,9 @@ void VoiceAssistant::loop() {
this->speaker_->stop();
this->cancel_timeout("speaker-timeout");
this->cancel_timeout("playing");
this->speaker_buffer_size_ = 0;
this->speaker_buffer_index_ = 0;
this->speaker_bytes_received_ = 0;
memset(this->speaker_buffer_, 0, SPEAKER_BUFFER_SIZE);
this->clear_buffers_();
this->wait_for_stream_end_ = false;
this->stream_ended_ = false;
@@ -507,7 +570,6 @@ void VoiceAssistant::request_start(bool continuous, bool silence_detection) {
if (this->state_ == State::IDLE) {
this->continuous_ = continuous;
this->silence_detection_ = silence_detection;
this->ring_buffer_->reset();
#ifdef USE_ESP_ADF
if (this->use_wake_word_) {
this->set_state_(State::START_MICROPHONE, State::WAIT_FOR_VAD);

View File

@@ -151,6 +151,10 @@ class VoiceAssistant : public Component {
void set_wake_word(const std::string &wake_word) { this->wake_word_ = wake_word; }
protected:
bool allocate_buffers_();
void clear_buffers_();
void deallocate_buffers_();
int read_microphone_();
void set_state_(State state);
void set_state_(State state, State desired_state);

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
"""Constants used by esphome."""
__version__ = "2024.5.1"
__version__ = "2024.5.3"
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
VALID_SUBSTITUTIONS_CHARACTERS = (

View File

@@ -103,7 +103,7 @@ class DashboardEntries:
def all(self) -> list[DashboardEntry]:
"""Return all entries."""
return asyncio.run_coroutine_threadsafe(self._async_all, self._loop).result()
return asyncio.run_coroutine_threadsafe(self._async_all(), self._loop).result()
def async_all(self) -> list[DashboardEntry]:
"""Return all entries."""

View File

@@ -18,7 +18,7 @@ class MqttStatusThread(threading.Thread):
"""Run the status thread."""
dashboard = DASHBOARD
entries = dashboard.entries
current_entries = entries.async_all()
current_entries = entries.all()
config = mqtt.config_from_env()
topic = "esphome/discover/#"
@@ -33,7 +33,7 @@ class MqttStatusThread(threading.Thread):
return
for entry in current_entries:
if entry.name == data["name"]:
entries.async_set_state(entry, EntryState.ONLINE)
entries.set_state(entry, EntryState.ONLINE)
return
def on_connect(client, userdata, flags, return_code):
@@ -53,11 +53,11 @@ class MqttStatusThread(threading.Thread):
client.loop_start()
while not dashboard.stop_event.wait(2):
current_entries = entries.async_all()
current_entries = entries.all()
# will be set to true on on_message
for entry in current_entries:
if entry.no_mdns:
entries.async_set_state(entry, EntryState.OFFLINE)
entries.set_state(entry, EntryState.OFFLINE)
client.publish("esphome/discover", None, retain=False)
dashboard.mqtt_ping_request.wait()

View File

@@ -3,6 +3,7 @@ remote_receiver:
pin: ${pin}
rmt_channel: ${rmt_channel}
dump: all
tolerance: 25%
on_abbwelcome:
then:
- logger.log: