diff --git a/boards.txt b/boards.txt index fafec87916e..c5addf570f4 100644 --- a/boards.txt +++ b/boards.txt @@ -502,6 +502,10 @@ esp32p4.menu.PartitionScheme.app5M_little24M_32MB.upload.maximum_size=4718592 esp32p4.menu.PartitionScheme.app13M_data7M_32MB=32M Flash (13MB APP/6.75MB SPIFFS) esp32p4.menu.PartitionScheme.app13M_data7M_32MB.build.partitions=default_32MB esp32p4.menu.PartitionScheme.app13M_data7M_32MB.upload.maximum_size=13107200 +esp32p4.menu.PartitionScheme.esp_sr_16=ESP SR 16M (3MB APP/7MB SPIFFS/2.9MB MODEL) +esp32p4.menu.PartitionScheme.esp_sr_16.upload.maximum_size=3145728 +esp32p4.menu.PartitionScheme.esp_sr_16.upload.extra_flags=0xD10000 {build.path}/srmodels.bin +esp32p4.menu.PartitionScheme.esp_sr_16.build.partitions=esp_sr_16 esp32p4.menu.PartitionScheme.custom=Custom esp32p4.menu.PartitionScheme.custom.build.partitions= esp32p4.menu.PartitionScheme.custom.upload.maximum_size=16777216 diff --git a/libraries/ESP_SR/examples/Basic/Basic.ino b/libraries/ESP_SR/examples/Basic/Basic.ino index 30aab69d79b..c8a16b1bc92 100644 --- a/libraries/ESP_SR/examples/Basic/Basic.ino +++ b/libraries/ESP_SR/examples/Basic/Basic.ino @@ -9,6 +9,17 @@ #define LIGHT_PIN 40 #define FAN_PIN 41 +/** + * The input format: + * M to represent the microphone channel + * R to represent the playback reference channel + * N to represent an unknown or unused channel + * + * For example, input_format="MMNR" indicates that the input data consists of four channels, + * which are the microphone channel, the microphone channel, an unused channel, and the playback channel + */ +#define SR_INPUT_FORMAT "MM" + I2SClass i2s; // Generated using the following command: @@ -69,7 +80,7 @@ void setup() { i2s.begin(I2S_MODE_STD, 16000, I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO); ESP_SR.onEvent(onSrEvent); - ESP_SR.begin(i2s, sr_commands, sizeof(sr_commands) / sizeof(sr_cmd_t), SR_CHANNELS_STEREO, SR_MODE_WAKEWORD); + ESP_SR.begin(i2s, sr_commands, sizeof(sr_commands) / sizeof(sr_cmd_t), SR_CHANNELS_STEREO, SR_MODE_WAKEWORD, SR_INPUT_FORMAT); } void loop() {} diff --git a/libraries/ESP_SR/examples/Basic/ci.json b/libraries/ESP_SR/examples/Basic/ci.json index ec0e969a7d0..ed7699a7857 100644 --- a/libraries/ESP_SR/examples/Basic/ci.json +++ b/libraries/ESP_SR/examples/Basic/ci.json @@ -2,6 +2,9 @@ "fqbn": { "esp32s3": [ "espressif:esp32:esp32s3:USBMode=default,PartitionScheme=esp_sr_16,FlashSize=16M,FlashMode=dio" + ], + "esp32p4": [ + "espressif:esp32:esp32p4:USBMode=default,PartitionScheme=esp_sr_16,FlashSize=16M,FlashMode=qio" ] }, "requires": [ @@ -12,7 +15,6 @@ "esp32c3": false, "esp32c6": false, "esp32h2": false, - "esp32p4": false, "esp32s2": false, "esp32c5": false } diff --git a/libraries/ESP_SR/src/ESP_SR.cpp b/libraries/ESP_SR/src/ESP_SR.cpp index 8d90c0fff11..31cf85efd37 100644 --- a/libraries/ESP_SR/src/ESP_SR.cpp +++ b/libraries/ESP_SR/src/ESP_SR.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ #include "sdkconfig.h" -#if (CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32P4) && (CONFIG_USE_WAKENET || CONFIG_USE_MULTINET) +#if (CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32P4) && (CONFIG_MODEL_IN_FLASH || CONFIG_MODEL_IN_SDCARD) #include "ESP_SR.h" static esp_err_t on_sr_fill(void *arg, void *out, size_t len, size_t *bytes_read, uint32_t timeout_ms) { @@ -25,9 +25,9 @@ void ESP_SR_Class::onEvent(sr_cb event_cb) { cb = event_cb; } -bool ESP_SR_Class::begin(I2SClass &_i2s, const sr_cmd_t *sr_commands, size_t sr_commands_len, sr_channels_t rx_chan, sr_mode_t mode) { +bool ESP_SR_Class::begin(I2SClass &_i2s, const sr_cmd_t *sr_commands, size_t sr_commands_len, sr_channels_t rx_chan, sr_mode_t mode, const char *input_format) { i2s = &_i2s; - esp_err_t err = sr_start(on_sr_fill, this, rx_chan, mode, sr_commands, sr_commands_len, on_sr_event, this); + esp_err_t err = sr_start(on_sr_fill, this, rx_chan, mode, input_format, sr_commands, sr_commands_len, on_sr_event, this); return (err == ESP_OK); } diff --git a/libraries/ESP_SR/src/ESP_SR.h b/libraries/ESP_SR/src/ESP_SR.h index 13fe22a4b12..05393504cb9 100644 --- a/libraries/ESP_SR/src/ESP_SR.h +++ b/libraries/ESP_SR/src/ESP_SR.h @@ -6,7 +6,7 @@ #pragma once #include "sdkconfig.h" -#if (CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32P4) && (CONFIG_USE_WAKENET || CONFIG_USE_MULTINET) +#if (CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32P4) && (CONFIG_MODEL_IN_FLASH || CONFIG_MODEL_IN_SDCARD) #include "ESP_I2S.h" #include "esp32-hal-sr.h" @@ -23,7 +23,19 @@ class ESP_SR_Class { ~ESP_SR_Class(); void onEvent(sr_cb cb); - bool begin(I2SClass &i2s, const sr_cmd_t *sr_commands, size_t sr_commands_len, sr_channels_t rx_chan = SR_CHANNELS_STEREO, sr_mode_t mode = SR_MODE_WAKEWORD); + /** + * The input format: + * M to represent the microphone channel + * R to represent the playback reference channel + * N to represent an unknown or unused channel + * + * For example, input_format="MMNR" indicates that the input data consists of four channels, + * which are the microphone channel, the microphone channel, an unused channel, and the playback channel + */ + bool begin( + I2SClass &i2s, const sr_cmd_t *sr_commands, size_t sr_commands_len, sr_channels_t rx_chan = SR_CHANNELS_STEREO, sr_mode_t mode = SR_MODE_WAKEWORD, + const char *input_format = "MN" + ); bool end(void); bool setMode(sr_mode_t mode); bool pause(void); diff --git a/libraries/ESP_SR/src/esp32-hal-sr.c b/libraries/ESP_SR/src/esp32-hal-sr.c index 80295d41f5a..1ae96d616eb 100644 --- a/libraries/ESP_SR/src/esp32-hal-sr.c +++ b/libraries/ESP_SR/src/esp32-hal-sr.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ #include "sdkconfig.h" -#if (CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32P4) && (CONFIG_USE_WAKENET || CONFIG_USE_MULTINET) +#if (CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32P4) && (CONFIG_MODEL_IN_FLASH || CONFIG_MODEL_IN_SDCARD) #if !defined(ARDUINO_PARTITION_esp_sr_32) && !defined(ARDUINO_PARTITION_esp_sr_16) && !defined(ARDUINO_PARTITION_esp_sr_8) #warning Compatible partition must be selected for ESP_SR to work @@ -313,7 +313,8 @@ esp_err_t sr_set_mode(sr_mode_t mode) { } esp_err_t sr_start( - sr_fill_cb fill_cb, void *fill_cb_arg, sr_channels_t rx_chan, sr_mode_t mode, const sr_cmd_t sr_commands[], size_t cmd_number, sr_event_cb cb, void *cb_arg + sr_fill_cb fill_cb, void *fill_cb_arg, sr_channels_t rx_chan, sr_mode_t mode, const char *input_format, const sr_cmd_t sr_commands[], size_t cmd_number, + sr_event_cb cb, void *cb_arg ) { esp_err_t ret = ESP_OK; ESP_RETURN_ON_FALSE(NULL == g_sr_data, ESP_ERR_INVALID_STATE, "SR already running"); @@ -340,12 +341,11 @@ esp_err_t sr_start( models = esp_srmodel_init("model"); // Load WakeWord Detection - g_sr_data->afe_handle = (esp_afe_sr_iface_t *)&ESP_AFE_SR_HANDLE; - afe_config_t afe_config = AFE_CONFIG_DEFAULT(); - afe_config.wakenet_model_name = esp_srmodel_filter(models, ESP_WN_PREFIX, "hiesp"); - afe_config.aec_init = false; + afe_config_t *afe_config = afe_config_init(input_format, models, AFE_TYPE_SR, AFE_MODE_LOW_COST); + g_sr_data->afe_handle = esp_afe_handle_from_config(afe_config); log_d("load wakenet '%s'", afe_config.wakenet_model_name); - g_sr_data->afe_data = g_sr_data->afe_handle->create_from_config(&afe_config); + g_sr_data->afe_data = g_sr_data->afe_handle->create_from_config(afe_config); + afe_config_free(afe_config); // Load Custom Command Detection char *mn_name = esp_srmodel_filter(models, ESP_MN_PREFIX, ESP_MN_ENGLISH); diff --git a/libraries/ESP_SR/src/esp32-hal-sr.h b/libraries/ESP_SR/src/esp32-hal-sr.h index 6bdd9e89a44..ac3df3f07ac 100644 --- a/libraries/ESP_SR/src/esp32-hal-sr.h +++ b/libraries/ESP_SR/src/esp32-hal-sr.h @@ -6,7 +6,7 @@ #pragma once #include "sdkconfig.h" -#if (CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32P4) && (CONFIG_USE_WAKENET || CONFIG_USE_MULTINET) +#if (CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32P4) && (CONFIG_MODEL_IN_FLASH || CONFIG_MODEL_IN_SDCARD) #include "driver/i2s_types.h" #include "esp_err.h" @@ -49,7 +49,8 @@ typedef void (*sr_event_cb)(void *arg, sr_event_t event, int command_id, int phr typedef esp_err_t (*sr_fill_cb)(void *arg, void *out, size_t len, size_t *bytes_read, uint32_t timeout_ms); esp_err_t sr_start( - sr_fill_cb fill_cb, void *fill_cb_arg, sr_channels_t rx_chan, sr_mode_t mode, const sr_cmd_t *sr_commands, size_t cmd_number, sr_event_cb cb, void *cb_arg + sr_fill_cb fill_cb, void *fill_cb_arg, sr_channels_t rx_chan, sr_mode_t mode, const char *input_format, const sr_cmd_t *sr_commands, size_t cmd_number, + sr_event_cb cb, void *cb_arg ); esp_err_t sr_stop(void); esp_err_t sr_pause(void);