From bd7fe1227c442dfdeaf745682ddb39c3b071dc97 Mon Sep 17 00:00:00 2001 From: guillempages Date: Sat, 13 Jan 2024 22:01:32 +0100 Subject: [PATCH 1/3] Let show_*_page actions depend on "Display" (#6092) Instead of forcing a DisplayBuffer, let the display page actions use Displays without buffer. --- esphome/components/display/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/esphome/components/display/__init__.py b/esphome/components/display/__init__.py index 91f10c5458..992799008a 100644 --- a/esphome/components/display/__init__.py +++ b/esphome/components/display/__init__.py @@ -145,7 +145,7 @@ async def display_page_show_to_code(config, action_id, template_arg, args): DisplayPageShowNextAction, maybe_simple_id( { - cv.Required(CONF_ID): cv.templatable(cv.use_id(DisplayBuffer)), + cv.Required(CONF_ID): cv.templatable(cv.use_id(Display)), } ), ) @@ -159,7 +159,7 @@ async def display_page_show_next_to_code(config, action_id, template_arg, args): DisplayPageShowPrevAction, maybe_simple_id( { - cv.Required(CONF_ID): cv.templatable(cv.use_id(DisplayBuffer)), + cv.Required(CONF_ID): cv.templatable(cv.use_id(Display)), } ), ) @@ -173,7 +173,7 @@ async def display_page_show_previous_to_code(config, action_id, template_arg, ar DisplayIsDisplayingPageCondition, cv.maybe_simple_value( { - cv.GenerateID(CONF_ID): cv.use_id(DisplayBuffer), + cv.GenerateID(CONF_ID): cv.use_id(Display), cv.Required(CONF_PAGE_ID): cv.use_id(DisplayPage), }, key=CONF_PAGE_ID, From d5fe5b089974f22419939bdb418faee2d3fa890b Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Sat, 20 Jan 2024 03:38:37 +1300 Subject: [PATCH 2/3] Fix some Voice Assistant bugs (#6121) --- esphome/components/voice_assistant/voice_assistant.cpp | 10 ++++++---- esphome/core/ring_buffer.cpp | 9 +++++---- esphome/core/ring_buffer.h | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/esphome/components/voice_assistant/voice_assistant.cpp b/esphome/components/voice_assistant/voice_assistant.cpp index 299e624f5f..9094b93c02 100644 --- a/esphome/components/voice_assistant/voice_assistant.cpp +++ b/esphome/components/voice_assistant/voice_assistant.cpp @@ -17,7 +17,7 @@ static const char *const TAG = "voice_assistant"; static const size_t SAMPLE_RATE_HZ = 16000; static const size_t INPUT_BUFFER_SIZE = 32 * SAMPLE_RATE_HZ / 1000; // 32ms * 16kHz / 1000ms -static const size_t BUFFER_SIZE = 1000 * SAMPLE_RATE_HZ / 1000; // 1s +static const size_t BUFFER_SIZE = 1024 * SAMPLE_RATE_HZ / 1000; static const size_t SEND_BUFFER_SIZE = INPUT_BUFFER_SIZE * sizeof(int16_t); static const size_t RECEIVE_SIZE = 1024; static const size_t SPEAKER_BUFFER_SIZE = 16 * RECEIVE_SIZE; @@ -231,10 +231,12 @@ void VoiceAssistant::loop() { } case State::STREAMING_MICROPHONE: { this->read_microphone_(); - if (this->ring_buffer_->available() >= SEND_BUFFER_SIZE) { - this->ring_buffer_->read((void *) this->send_buffer_, SEND_BUFFER_SIZE, 0); - this->socket_->sendto(this->send_buffer_, SEND_BUFFER_SIZE, 0, (struct sockaddr *) &this->dest_addr_, + size_t available = this->ring_buffer_->available(); + while (available >= SEND_BUFFER_SIZE) { + size_t read_bytes = this->ring_buffer_->read((void *) this->send_buffer_, SEND_BUFFER_SIZE, 0); + this->socket_->sendto(this->send_buffer_, read_bytes, 0, (struct sockaddr *) &this->dest_addr_, sizeof(this->dest_addr_)); + available = this->ring_buffer_->available(); } break; diff --git a/esphome/core/ring_buffer.cpp b/esphome/core/ring_buffer.cpp index d9c56d84c5..9bd3d9d853 100644 --- a/esphome/core/ring_buffer.cpp +++ b/esphome/core/ring_buffer.cpp @@ -15,17 +15,18 @@ std::unique_ptr RingBuffer::create(size_t len) { std::unique_ptr rb = make_unique(); ExternalRAMAllocator allocator(ExternalRAMAllocator::ALLOW_FAILURE); - rb->storage_ = allocator.allocate(len); + rb->storage_ = allocator.allocate(len + 1); if (rb->storage_ == nullptr) { return nullptr; } - rb->handle_ = xStreamBufferCreateStatic(len, 0, rb->storage_, &rb->structure_); + rb->handle_ = xStreamBufferCreateStatic(len + 1, 0, rb->storage_, &rb->structure_); + ESP_LOGD(TAG, "Created ring buffer with size %u", len); return rb; } -size_t RingBuffer::read(void *data, size_t size, TickType_t ticks_to_wait) { - return xStreamBufferReceive(this->handle_, data, size, ticks_to_wait); +size_t RingBuffer::read(void *data, size_t len, TickType_t ticks_to_wait) { + return xStreamBufferReceive(this->handle_, data, len, ticks_to_wait); } size_t RingBuffer::write(void *data, size_t len) { diff --git a/esphome/core/ring_buffer.h b/esphome/core/ring_buffer.h index 6c6d04117a..e602068844 100644 --- a/esphome/core/ring_buffer.h +++ b/esphome/core/ring_buffer.h @@ -12,7 +12,7 @@ namespace esphome { class RingBuffer { public: - size_t read(void *data, size_t size, TickType_t ticks_to_wait = 0); + size_t read(void *data, size_t len, TickType_t ticks_to_wait = 0); size_t write(void *data, size_t len); From aee702f84fbee28a9dcb1d9b75aed8238c630799 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Fri, 19 Jan 2024 23:40:26 +0900 Subject: [PATCH 3/3] Bump version to 2023.12.8 --- esphome/const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/const.py b/esphome/const.py index 34a28fb400..3b31a17c3e 100644 --- a/esphome/const.py +++ b/esphome/const.py @@ -1,6 +1,6 @@ """Constants used by esphome.""" -__version__ = "2023.12.7" +__version__ = "2023.12.8" ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_" VALID_SUBSTITUTIONS_CHARACTERS = (