mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 13:34:54 +01:00
commit
5b062a222c
5 changed files with 28 additions and 3 deletions
|
@ -19,10 +19,27 @@ void I2SAudioSpeaker::setup() {
|
||||||
ESP_LOGCONFIG(TAG, "Setting up I2S Audio Speaker...");
|
ESP_LOGCONFIG(TAG, "Setting up I2S Audio Speaker...");
|
||||||
|
|
||||||
this->buffer_queue_ = xQueueCreate(BUFFER_COUNT, sizeof(DataEvent));
|
this->buffer_queue_ = xQueueCreate(BUFFER_COUNT, sizeof(DataEvent));
|
||||||
|
if (this->buffer_queue_ == nullptr) {
|
||||||
|
ESP_LOGE(TAG, "Failed to create buffer queue");
|
||||||
|
this->mark_failed();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this->event_queue_ = xQueueCreate(BUFFER_COUNT, sizeof(TaskEvent));
|
this->event_queue_ = xQueueCreate(BUFFER_COUNT, sizeof(TaskEvent));
|
||||||
|
if (this->event_queue_ == nullptr) {
|
||||||
|
ESP_LOGE(TAG, "Failed to create event queue");
|
||||||
|
this->mark_failed();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void I2SAudioSpeaker::start() { this->state_ = speaker::STATE_STARTING; }
|
void I2SAudioSpeaker::start() {
|
||||||
|
if (this->is_failed()) {
|
||||||
|
ESP_LOGE(TAG, "Cannot start audio, speaker failed to setup");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this->state_ = speaker::STATE_STARTING;
|
||||||
|
}
|
||||||
void I2SAudioSpeaker::start_() {
|
void I2SAudioSpeaker::start_() {
|
||||||
if (!this->parent_->try_lock()) {
|
if (!this->parent_->try_lock()) {
|
||||||
return; // Waiting for another i2s component to return lock
|
return; // Waiting for another i2s component to return lock
|
||||||
|
@ -141,6 +158,8 @@ void I2SAudioSpeaker::player_task(void *params) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void I2SAudioSpeaker::stop() {
|
void I2SAudioSpeaker::stop() {
|
||||||
|
if (this->is_failed())
|
||||||
|
return;
|
||||||
if (this->state_ == speaker::STATE_STOPPED)
|
if (this->state_ == speaker::STATE_STOPPED)
|
||||||
return;
|
return;
|
||||||
if (this->state_ == speaker::STATE_STARTING) {
|
if (this->state_ == speaker::STATE_STARTING) {
|
||||||
|
@ -200,6 +219,10 @@ void I2SAudioSpeaker::loop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t I2SAudioSpeaker::play(const uint8_t *data, size_t length) {
|
size_t I2SAudioSpeaker::play(const uint8_t *data, size_t length) {
|
||||||
|
if (this->is_failed()) {
|
||||||
|
ESP_LOGE(TAG, "Cannot play audio, speaker failed to setup");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (this->state_ != speaker::STATE_RUNNING && this->state_ != speaker::STATE_STARTING) {
|
if (this->state_ != speaker::STATE_RUNNING && this->state_ != speaker::STATE_STARTING) {
|
||||||
this->start();
|
this->start();
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,6 +109,7 @@ void ImprovSerialComponent::write_data_(std::vector<uint8_t> &data) {
|
||||||
#if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32S3)
|
#if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32S3)
|
||||||
case logger::UART_SELECTION_USB_SERIAL_JTAG:
|
case logger::UART_SELECTION_USB_SERIAL_JTAG:
|
||||||
usb_serial_jtag_write_bytes((char *) data.data(), data.size(), 20 / portTICK_PERIOD_MS);
|
usb_serial_jtag_write_bytes((char *) data.data(), data.size(), 20 / portTICK_PERIOD_MS);
|
||||||
|
usb_serial_jtag_ll_txfifo_flush(); // fixes for issue in IDF 4.4.7
|
||||||
break;
|
break;
|
||||||
#endif // USE_ESP32_VARIANT_ESP32C3 || USE_ESP32_VARIANT_ESP32S3
|
#endif // USE_ESP32_VARIANT_ESP32C3 || USE_ESP32_VARIANT_ESP32S3
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32S3) || \
|
#if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32S3) || \
|
||||||
defined(USE_ESP32_VARIANT_ESP32H2)
|
defined(USE_ESP32_VARIANT_ESP32H2)
|
||||||
#include <driver/usb_serial_jtag.h>
|
#include <driver/usb_serial_jtag.h>
|
||||||
|
#include <hal/usb_serial_jtag_ll.h>
|
||||||
#endif
|
#endif
|
||||||
#if defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)
|
#if defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)
|
||||||
#include <esp_private/usb_console.h>
|
#include <esp_private/usb_console.h>
|
||||||
|
|
|
@ -17,7 +17,7 @@ static const char *const TAG = "voice_assistant";
|
||||||
|
|
||||||
static const size_t SAMPLE_RATE_HZ = 16000;
|
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 INPUT_BUFFER_SIZE = 32 * SAMPLE_RATE_HZ / 1000; // 32ms * 16kHz / 1000ms
|
||||||
static const size_t BUFFER_SIZE = 1024 * SAMPLE_RATE_HZ / 1000;
|
static const size_t BUFFER_SIZE = 512 * SAMPLE_RATE_HZ / 1000;
|
||||||
static const size_t SEND_BUFFER_SIZE = INPUT_BUFFER_SIZE * sizeof(int16_t);
|
static const size_t SEND_BUFFER_SIZE = INPUT_BUFFER_SIZE * sizeof(int16_t);
|
||||||
static const size_t RECEIVE_SIZE = 1024;
|
static const size_t RECEIVE_SIZE = 1024;
|
||||||
static const size_t SPEAKER_BUFFER_SIZE = 16 * RECEIVE_SIZE;
|
static const size_t SPEAKER_BUFFER_SIZE = 16 * RECEIVE_SIZE;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"""Constants used by esphome."""
|
"""Constants used by esphome."""
|
||||||
|
|
||||||
__version__ = "2024.5.4"
|
__version__ = "2024.5.5"
|
||||||
|
|
||||||
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
||||||
VALID_SUBSTITUTIONS_CHARACTERS = (
|
VALID_SUBSTITUTIONS_CHARACTERS = (
|
||||||
|
|
Loading…
Reference in a new issue