Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion libraries/ESP_SR/examples/Basic/Basic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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() {}
4 changes: 3 additions & 1 deletion libraries/ESP_SR/examples/Basic/ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -12,7 +15,6 @@
"esp32c3": false,
"esp32c6": false,
"esp32h2": false,
"esp32p4": false,
"esp32s2": false,
"esp32c5": false
}
Expand Down
6 changes: 3 additions & 3 deletions libraries/ESP_SR/src/ESP_SR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}

Expand Down
16 changes: 14 additions & 2 deletions libraries/ESP_SR/src/ESP_SR.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions libraries/ESP_SR/src/esp32-hal-sr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions libraries/ESP_SR/src/esp32-hal-sr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down
Loading