mirror of
https://github.com/espressif/esp-sr.git
synced 2025-09-15 15:28:44 +08:00
feat: Support ESP-IDF v5.0
This commit is contained in:
parent
5ec99ffbde
commit
51bc9f7d23
@ -1,35 +1,38 @@
|
||||
if(IDF_TARGET STREQUAL "esp32")
|
||||
set(COMPONENT_ADD_INCLUDEDIRS
|
||||
set(include_dirs
|
||||
src/include
|
||||
esp-tts/esp_tts_chinese/include
|
||||
include/esp32
|
||||
)
|
||||
set(COMPONENT_SRCS
|
||||
set(srcs
|
||||
src/model_path.c
|
||||
src/esp_mn_speech_commands.c
|
||||
src/esp_process_sdkconfig.c
|
||||
)
|
||||
|
||||
set(COMPONENT_REQUIRES
|
||||
set(requires
|
||||
json
|
||||
spiffs
|
||||
esp_partition
|
||||
)
|
||||
|
||||
register_component()
|
||||
idf_component_register(SRCS ${srcs}
|
||||
INCLUDE_DIRS ${include_dirs}
|
||||
REQUIRES ${requires}
|
||||
PRIV_REQUIRES spi_flash)
|
||||
|
||||
target_link_libraries(${COMPONENT_TARGET} "-L ${CMAKE_CURRENT_SOURCE_DIR}/lib/esp32")
|
||||
target_link_libraries(${COMPONENT_TARGET} "-L ${CMAKE_CURRENT_SOURCE_DIR}/esp-tts/esp_tts_chinese/esp32")
|
||||
IF (IDF_VERSION_MAJOR GREATER 3)
|
||||
add_prebuilt_library(esp_audio_processor "${CMAKE_CURRENT_SOURCE_DIR}/lib/esp32/libesp_audio_processor.a" PRIV_REQUIRES ${COMPONENT_NAME})
|
||||
add_prebuilt_library(wakenet "${CMAKE_CURRENT_SOURCE_DIR}/lib/esp32/libwakenet.a" PRIV_REQUIRES ${COMPONENT_NAME})
|
||||
add_prebuilt_library(multinet "${CMAKE_CURRENT_SOURCE_DIR}/lib/esp32/libmultinet.a" PRIV_REQUIRES ${COMPONENT_NAME})
|
||||
add_prebuilt_library(esp_audio_front_end "${CMAKE_CURRENT_SOURCE_DIR}/lib/esp32/libesp_audio_front_end.a" PRIV_REQUIRES ${COMPONENT_NAME})
|
||||
ENDIF (IDF_VERSION_MAJOR GREATER 3)
|
||||
|
||||
target_link_libraries(${COMPONENT_TARGET} "-Wl,--start-group"
|
||||
multinet
|
||||
dl_lib
|
||||
c_speech_features
|
||||
wakeword_model
|
||||
wakeword_model
|
||||
multinet2_ch
|
||||
esp_audio_processor
|
||||
esp_audio_front_end
|
||||
@ -38,23 +41,28 @@ ENDIF (IDF_VERSION_MAJOR GREATER 3)
|
||||
wakenet
|
||||
"-Wl,--end-group")
|
||||
elseif(${IDF_TARGET} STREQUAL "esp32s3")
|
||||
set(COMPONENT_ADD_INCLUDEDIRS
|
||||
src/include
|
||||
set(include_dirs
|
||||
src/include
|
||||
esp-tts/esp_tts_chinese/include
|
||||
include/esp32s3
|
||||
)
|
||||
set(COMPONENT_SRCS
|
||||
set(srcs
|
||||
src/model_path.c
|
||||
src/esp_mn_speech_commands.c
|
||||
src/esp_process_sdkconfig.c
|
||||
)
|
||||
|
||||
set(COMPONENT_REQUIRES
|
||||
set(requires
|
||||
json
|
||||
spiffs
|
||||
esp_partition
|
||||
)
|
||||
|
||||
register_component()
|
||||
idf_component_register(SRCS ${srcs}
|
||||
INCLUDE_DIRS ${include_dirs}
|
||||
REQUIRES ${requires}
|
||||
PRIV_REQUIRES spi_flash)
|
||||
|
||||
target_link_libraries(${COMPONENT_TARGET} "-L ${CMAKE_CURRENT_SOURCE_DIR}/lib/esp32s3")
|
||||
target_link_libraries(${COMPONENT_TARGET} "-L ${CMAKE_CURRENT_SOURCE_DIR}/esp-tts/esp_tts_chinese/esp32s3")
|
||||
|
||||
@ -106,22 +114,22 @@ elseif(${IDF_TARGET} STREQUAL "esp32s3")
|
||||
"Please add a line(Name=model, Size>recommended size in log) to the partition file.")
|
||||
endif()
|
||||
elseif(${IDF_TARGET} STREQUAL "esp32s2")
|
||||
set(COMPONENT_ADD_INCLUDEDIRS
|
||||
esp-tts/esp_tts_chinese/include
|
||||
)
|
||||
idf_component_register(SRCS .
|
||||
INCLUDE_DIRS esp-tts/esp_tts_chinese/include
|
||||
REQUIRES esp_partition
|
||||
PRIV_REQUIRES spi_flash)
|
||||
|
||||
register_component()
|
||||
target_link_libraries(${COMPONENT_TARGET} INTERFACE "-L ${CMAKE_CURRENT_SOURCE_DIR}/esp-tts/esp_tts_chinese/esp32s2")
|
||||
target_link_libraries(${COMPONENT_TARGET} INTERFACE "-Wl,--start-group"
|
||||
esp_tts_chinese
|
||||
voice_set_xiaole
|
||||
"-Wl,--end-group")
|
||||
elseif(${IDF_TARGET} STREQUAL "esp32c3")
|
||||
set(COMPONENT_ADD_INCLUDEDIRS
|
||||
esp-tts/esp_tts_chinese/include
|
||||
)
|
||||
|
||||
register_component()
|
||||
idf_component_register(SRCS .
|
||||
INCLUDE_DIRS esp-tts/esp_tts_chinese/include
|
||||
REQUIRES esp_partition
|
||||
PRIV_REQUIRES spi_flash)
|
||||
|
||||
target_link_libraries(${COMPONENT_TARGET} INTERFACE "-L ${CMAKE_CURRENT_SOURCE_DIR}/esp-tts/esp_tts_chinese/esp32c3")
|
||||
target_link_libraries(${COMPONENT_TARGET} INTERFACE "-Wl,--start-group"
|
||||
esp_tts_chinese
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -7,20 +7,19 @@
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// char *name; // the name of model, like "wn9_hilexin"(wakenet9, hilexin)
|
||||
int num; // the number of files
|
||||
char **files; // the model files, like wn9_index, wn9_data
|
||||
int num; // the number of files
|
||||
char **files; // the model files, like wn9_index, wn9_data
|
||||
char **data; // the pointer of file data
|
||||
int *sizes; // the size of different file
|
||||
} srmodel_data_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char **model_name; // the name of models, like "wn9_hilexin"(wakenet9, hilexin), "mn5_en"(multinet5, english)
|
||||
char **model_name; // the name of models, like "wn9_hilexin"(wakenet9, hilexin), "mn5_en"(multinet5, english)
|
||||
esp_partition_t *partition; // partition label used to save the files of model
|
||||
spi_flash_mmap_handle_t mmap_handle; // mmap_handle if using esp_partition_mmap else NULL;
|
||||
int num; // the number of models
|
||||
srmodel_data_t **model_data; // the model data , NULL if spiffs format
|
||||
esp_partition_mmap_handle_t mmap_handle; // mmap_handle if using esp_partition_mmap else NULL; // support esp-idf v5.0
|
||||
int num; // the number of models
|
||||
srmodel_data_t **model_data; // the model data , NULL if spiffs format
|
||||
} srmodel_list_t;
|
||||
|
||||
|
||||
|
||||
@ -236,7 +236,7 @@ static uint32_t read_int32(char *data) {
|
||||
return value;
|
||||
}
|
||||
|
||||
srmodel_list_t *srmodel_mmap_init(const esp_partition_t *part)
|
||||
srmodel_list_t *srmodel_mmap_init(const esp_partition_t *partition)
|
||||
{
|
||||
if (static_srmodels == NULL)
|
||||
static_srmodels = srmodel_list_alloc();
|
||||
@ -245,15 +245,9 @@ srmodel_list_t *srmodel_mmap_init(const esp_partition_t *part)
|
||||
|
||||
srmodel_list_t *models = static_srmodels;
|
||||
const void *root;
|
||||
esp_err_t err=esp_partition_mmap(part, 0, part->size, SPI_FLASH_MMAP_DATA, &root, &models->mmap_handle);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Can not map %s partition!", part->label);
|
||||
return NULL;
|
||||
} else {
|
||||
ESP_LOGI(TAG, "partition %s size: %d by mmap", part->label, part->size);
|
||||
}
|
||||
ESP_ERROR_CHECK(esp_partition_mmap(partition, 0, partition->size, ESP_PARTITION_MMAP_DATA, &root, &models->mmap_handle));
|
||||
|
||||
models->partition = (esp_partition_t *)part;
|
||||
models->partition = (esp_partition_t *)partition;
|
||||
char *start = (char *)root;
|
||||
char *data = (char *)root;
|
||||
int str_len = SRMODEL_STRING_LENGTH;
|
||||
@ -295,6 +289,7 @@ srmodel_list_t *srmodel_mmap_init(const esp_partition_t *part)
|
||||
}
|
||||
models->model_data[i] = model_data;
|
||||
}
|
||||
ESP_LOGI(TAG, "Successfully map %s partition", partition->label);
|
||||
|
||||
set_model_base_path(NULL);
|
||||
return models;
|
||||
@ -303,8 +298,8 @@ srmodel_list_t *srmodel_mmap_init(const esp_partition_t *part)
|
||||
void srmodel_mmap_deinit(srmodel_list_t *models)
|
||||
{
|
||||
if (models != NULL) {
|
||||
// esp_partition_munmap(models->mmap_handle); // support esp-idf v5.0
|
||||
spi_flash_munmap(models->mmap_handle);
|
||||
esp_partition_munmap(models->mmap_handle); // support esp-idf v5.0
|
||||
// spi_flash_munmap(models->mmap_handle);
|
||||
|
||||
if (models->num>0) {
|
||||
for (int i=0; i<models->num; i++) {
|
||||
@ -452,15 +447,14 @@ srmodel_list_t* esp_srmodel_init(const char* partition_label)
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32
|
||||
return srmodel_config_init();
|
||||
#else
|
||||
const esp_partition_t* part = NULL;
|
||||
const esp_partition_t* partition = NULL;
|
||||
// find spiffs partition
|
||||
part = esp_partition_find_first(
|
||||
partition = esp_partition_find_first(
|
||||
ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, partition_label
|
||||
);
|
||||
return srmodel_mmap_init(part);
|
||||
|
||||
if (part) {
|
||||
return srmodel_mmap_init(part);
|
||||
|
||||
if (partition) {
|
||||
return srmodel_mmap_init(partition);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Can not find %s in partition table", partition_label);
|
||||
}
|
||||
|
||||
@ -31,6 +31,7 @@ TEST_CASE("multinet create/destroy API & memory leak", "[mn]")
|
||||
// test model loading time
|
||||
struct timeval tv_start, tv_end;
|
||||
gettimeofday(&tv_start, NULL);
|
||||
printf("load multinet!\n");
|
||||
model_iface_data_t *model_data = multinet->create(model_name, 6000);
|
||||
gettimeofday(&tv_end, NULL);
|
||||
int tv_ms=(tv_end.tv_sec-tv_start.tv_sec)*1000+(tv_end.tv_usec-tv_start.tv_usec)/1000;
|
||||
|
||||
@ -44,9 +44,7 @@ TEST_CASE("wakenet create/destroy API & memory leak", "[wn]")
|
||||
|
||||
// test memory leak
|
||||
int first_end_size = heap_caps_get_free_size(MALLOC_CAP_8BIT);
|
||||
int first_end_internal_size = heap_caps_get_free_size(MALLOC_CAP_INTERNAL);
|
||||
int last_end_size = first_end_size;
|
||||
int last_end_internal_size = first_end_internal_size;
|
||||
int mem_leak = start_size - last_end_size;
|
||||
printf("create&destroy times:%d, memory leak:%d\n", 1, mem_leak);
|
||||
|
||||
@ -72,7 +70,6 @@ TEST_CASE("wakenet create/destroy API & memory leak", "[wn]")
|
||||
esp_srmodel_deinit(models);
|
||||
|
||||
last_end_size = heap_caps_get_free_size(MALLOC_CAP_8BIT);
|
||||
last_end_internal_size = heap_caps_get_free_size(MALLOC_CAP_INTERNAL);
|
||||
mem_leak = start_size - last_end_size;
|
||||
printf("create&destroy times:%d, memory leak:%d\n", i+2, mem_leak);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user