diff --git a/include/esp32s3/esp_mn_models.h b/include/esp32s3/esp_mn_models.h index c65e0aa..37fba80 100644 --- a/include/esp32s3/esp_mn_models.h +++ b/include/esp32s3/esp_mn_models.h @@ -29,9 +29,8 @@ char *esp_mn_language_from_name(char *model_name); /* Configure wake word to use based on what's selected in menuconfig. */ -#if defined CONFIG_USE_MULTINET -#if CONFIG_SR_MN_CN_MULTINET2_SINGLE_RECOGNITION +#ifdef CONFIG_SR_MN_CN_MULTINET2_SINGLE_RECOGNITION #include "multinet2_ch.h" #define MULTINET_COEFF get_coeff_multinet2_ch #define MULTINET_MODEL_NAME "mn2_cn" @@ -41,10 +40,6 @@ char *esp_mn_language_from_name(char *model_name); #define MULTINET_MODEL_NAME "NULL" #endif -#else -#define MULTINET_COEFF "COEFF_NULL" -#define MULTINET_MODEL_NAME "NULL" -#endif /* example diff --git a/lib/esp32s3/libdl_lib.a b/lib/esp32s3/libdl_lib.a index be7b121..18e3130 100644 Binary files a/lib/esp32s3/libdl_lib.a and b/lib/esp32s3/libdl_lib.a differ diff --git a/lib/esp32s3/libesp_audio_front_end.a b/lib/esp32s3/libesp_audio_front_end.a index 1596800..2bb839b 100644 Binary files a/lib/esp32s3/libesp_audio_front_end.a and b/lib/esp32s3/libesp_audio_front_end.a differ diff --git a/lib/esp32s3/libesp_audio_processor.a b/lib/esp32s3/libesp_audio_processor.a index 503bd90..50b58b5 100644 Binary files a/lib/esp32s3/libesp_audio_processor.a and b/lib/esp32s3/libesp_audio_processor.a differ diff --git a/lib/esp32s3/libmultinet.a b/lib/esp32s3/libmultinet.a index 3810641..566aea7 100644 Binary files a/lib/esp32s3/libmultinet.a and b/lib/esp32s3/libmultinet.a differ diff --git a/lib/esp32s3/libwakenet.a b/lib/esp32s3/libwakenet.a index 9d51a43..96825f7 100644 Binary files a/lib/esp32s3/libwakenet.a and b/lib/esp32s3/libwakenet.a differ diff --git a/model/movemodel.py b/model/movemodel.py index f0cde23..1329949 100644 --- a/model/movemodel.py +++ b/model/movemodel.py @@ -54,8 +54,6 @@ if "CONFIG_SR_WN_WN9_ALEXA" in WN_STRING: wakenet_model.append('wn9_alexa') if "CONFIG_SR_WN_WN9_HIESP" in WN_STRING: wakenet_model.append('wn9_hiesp') -if "CONFIG_SR_WN_WN9_NIHAOXIAOZHI" in WN_STRING: - wakenet_model.append('wn9_nihaoxiaozhi') multinet_model = [] if "CONFIG_SR_MN_CN_MULTINET3_SINGLE_RECOGNITION" in MN_STRING and len(multinet_model) < 2: diff --git a/model/wakenet_model/wn9_alexa/_MODEL_INFO_ b/model/wakenet_model/wn9_alexa/_MODEL_INFO_ index 07402d1..3e4e3a9 100644 --- a/model/wakenet_model/wn9_alexa/_MODEL_INFO_ +++ b/model/wakenet_model/wn9_alexa/_MODEL_INFO_ @@ -1 +1,2 @@ -wakeNet9l_v2h24_alexa_3_0.585_0.605 +# (neural network type)_(model data version)_(lable1_detection windown length_threshold for 90%_threshold for 95%)_(lable2 ...)_... +wakenet9l_v2h24_alexa_3_0.615_0.645 diff --git a/model/wakenet_model/wn9_alexa/wn9_data b/model/wakenet_model/wn9_alexa/wn9_data index 9b191a9..341b4f6 100644 Binary files a/model/wakenet_model/wn9_alexa/wn9_data and b/model/wakenet_model/wn9_alexa/wn9_data differ diff --git a/model/wakenet_model/wn9_alexa/wn9_index b/model/wakenet_model/wn9_alexa/wn9_index index d441c75..86618bc 100644 Binary files a/model/wakenet_model/wn9_alexa/wn9_index and b/model/wakenet_model/wn9_alexa/wn9_index differ diff --git a/src/esp_process_sdkconfig.c b/src/esp_process_sdkconfig.c index 0cab6d9..1e23a4d 100644 --- a/src/esp_process_sdkconfig.c +++ b/src/esp_process_sdkconfig.c @@ -55,7 +55,7 @@ void check_chip_config(void) char *get_id_name_cn(int i) { #if defined CONFIG_USE_MULTINET -#if defined CONFIG_SR_MN_CN_MULTINET2_SINGLE_RECOGNITION || defined CONFIG_SR_MN_CN_MULTINET4_5_SINGLE_RECOGNITION || defined CONFIG_SR_MN_CN_MULTINET4_5_SINGLE_RECOGNITION_QUANT8 +#if defined CONFIG_SR_MN_CN_MULTINET2_SINGLE_RECOGNITION || defined CONFIG_SR_MN_CN_MULTINET4_5_SINGLE_RECOGNITION || defined CONFIG_SR_MN_CN_MULTINET4_5_SINGLE_RECOGNITION_QUANT8 || defined CONFIG_SR_MN_CN_MULTINET5_SINGLE_RECOGNITION_QUANT8 if (i == 0) return CONFIG_CN_SPEECH_COMMAND_ID0; else if (i == 1) @@ -885,7 +885,7 @@ esp_err_t esp_mn_commands_update_from_sdkconfig(esp_mn_iface_t *multinet, const char *command_str = NULL; int command_str_len = 0; -#if defined CONFIG_SR_MN_CN_MULTINET2_SINGLE_RECOGNITION || defined CONFIG_SR_MN_CN_MULTINET4_SINGLE_RECOGNITION || defined CONFIG_SR_MN_CN_MULTINET4_5_SINGLE_RECOGNITION || defined CONFIG_SR_MN_CN_MULTINET4_5_SINGLE_RECOGNITION_QUANT8 +#if defined CONFIG_SR_MN_CN_MULTINET2_SINGLE_RECOGNITION || defined CONFIG_SR_MN_CN_MULTINET4_SINGLE_RECOGNITION || defined CONFIG_SR_MN_CN_MULTINET4_5_SINGLE_RECOGNITION || defined CONFIG_SR_MN_CN_MULTINET4_5_SINGLE_RECOGNITION_QUANT8 || defined CONFIG_SR_MN_CN_MULTINET5_SINGLE_RECOGNITION_QUANT8 command_str = get_id_name_cn(i); #elif defined CONFIG_SR_MN_EN_MULTINET5_SINGLE_RECOGNITION || defined CONFIG_SR_MN_EN_MULTINET5_SINGLE_RECOGNITION_QUANT8 command_str = get_id_name_en(i); diff --git a/src/model_path.c b/src/model_path.c index 86139f7..ad45064 100644 --- a/src/model_path.c +++ b/src/model_path.c @@ -1,38 +1,29 @@ #include "stdio.h" -#include "sdkconfig.h" -#include "esp_spiffs.h" #include -#include +#include #include "string.h" #include "model_path.h" #include "esp_wn_models.h" #include "esp_mn_models.h" + +#ifdef ESP_PLATFORM +#include +#include "sdkconfig.h" #include "esp_log.h" +#include "esp_spiffs.h" +#endif static char *TAG = "MODEL_LOADER"; static char *SRMODE_BASE_PATH = "/srmodel"; -char *get_model_base_path(void) -{ - return SRMODE_BASE_PATH; -} - -int set_model_base_path(const char *base_path) -{ - if (base_path == NULL) return 0; - - SRMODE_BASE_PATH = base_path; - return 1; -} - +#ifdef ESP_PLATFORM srmodel_list_t *read_models_form_spiffs(esp_vfs_spiffs_conf_t *conf) { struct dirent *ret; DIR *dir; dir = opendir(conf->base_path); - srmodel_list_t *models = malloc(sizeof(srmodel_list_t*)); - models->num = 0; - models->partition_label = conf->partition_label; + srmodel_list_t *models = NULL; + int model_num = 0; int idx = 0; if (dir != NULL) @@ -48,13 +39,19 @@ srmodel_list_t *read_models_form_spiffs(esp_vfs_spiffs_conf_t *conf) char *suffix = ret->d_name + len - 12; if (strcmp(suffix, "_MODEL_INFO_") == 0) - models->num ++; + model_num ++; } // allocate model names - models->model_name = malloc(models->num*sizeof(char*)); - for (int i=0; inum; i++) { - models->model_name[i] = (char*) calloc(MODEL_NAME_MAX_LENGTH, sizeof(char)); + if (model_num == 0) { + return models; + } else { + models = malloc(sizeof(srmodel_list_t*)); + models->num = model_num; + models->partition_label = conf->partition_label; + models->model_name = malloc(models->num*sizeof(char*)); + for (int i=0; inum; i++) + models->model_name[i] = (char*) calloc(MODEL_NAME_MAX_LENGTH, sizeof(char)); } // read& save model names @@ -188,23 +185,152 @@ void srmodel_config_deinit(srmodel_list_t *models) } } +#endif + +char *get_model_base_path(void) +{ + return SRMODE_BASE_PATH; +} + +int set_model_base_path(const char *base_path) +{ + if (base_path == NULL) return 0; + + SRMODE_BASE_PATH = base_path; + return 1; +} + +char* join_path(char* dirname, char *filename) +{ + if (dirname == NULL || filename == NULL) + return NULL; + int dirname_len = strlen(dirname); + int filename_len = strlen(filename); + int len = filename_len + dirname_len + 2; + char *path = calloc(len, sizeof(char)); + memcpy(path, dirname, dirname_len); + if (dirname[dirname_len-1] == '/') { + memcpy(path+dirname_len, filename, filename_len); + } else { + path[dirname_len] = '/'; + memcpy(path+dirname_len+1, filename, filename_len); + } + return path; +} + +// read srmodel from sdcard +srmodel_list_t* srmodel_sdcard_init(const char *base_path) +{ + printf("Initializing models from path: %s\n", base_path); + set_model_base_path(base_path); + struct dirent *ret, *sub_ret; + DIR *dir, *sub_dir; + dir = opendir(base_path); + srmodel_list_t *models = NULL; + int model_num = 0; + int idx = 0; + FILE* fp; + + if (dir != NULL) + { + // get the number of models + while ((ret = readdir(dir)) != NULL) + { // NULL if reach the end of directory + + if (ret->d_type == DT_DIR) { // if d_type is directory + char *sub_path = join_path(base_path, ret->d_name); + char *info_file = join_path(sub_path, "_MODEL_INFO_"); + fp = fopen(info_file, "r"); + if (fp != NULL) { + model_num ++; // If _MODLE_INFO_ file exists, model_num ++ + } + printf("%s -> %s\n", sub_path, info_file); + fclose(fp); + free(sub_path); + free(info_file); + } + } + closedir(dir); + + // allocate srmodel_list_t struct + if (model_num == 0) { + return models; + } else { + models = malloc(sizeof(srmodel_list_t*)); + models->num = model_num; + models->partition_label = NULL; + models->model_name = malloc(models->num*sizeof(char*)); + for (int i=0; inum; i++) + models->model_name[i] = (char*) calloc(MODEL_NAME_MAX_LENGTH, sizeof(char)); + } + + + // read & save model names + dir = opendir(base_path); + while ((ret = readdir(dir)) != NULL) + { // NULL if reach the end of directory + + if (ret->d_type == DT_DIR) { // if d_type is directory + char *sub_path = join_path(base_path, ret->d_name); + char *info_file = join_path(sub_path, "_MODEL_INFO_"); + fp = fopen(info_file, "r"); + if (fp != NULL) { + memcpy(models->model_name[idx], ret->d_name, strlen(ret->d_name)); + idx++; + } + fclose(fp); + free(sub_path); + free(info_file); + } + } + closedir(dir); + } + return models; +} + + +void srmodel_sdcard_deinit(srmodel_list_t *models) +{ + if (models != NULL) { + if (models->num>0) { + for (int i=0; inum; i++) { + free(models->model_name[i]); + } + } + free(models); + } +} + + srmodel_list_t* esp_srmodel_init(const char* base_path) { +#ifdef ESP_PLATFORM + #ifdef CONFIG_IDF_TARGET_ESP32 return srmodel_config_init(); #else return srmodel_spiffs_init(base_path); #endif + +#else + return srmodel_sdcard_init(base_path); +#endif } void esp_srmodel_deinit(srmodel_list_t *models) { +#ifdef ESP_PLATFORM + #ifdef CONFIG_IDF_TARGET_ESP32 return srmodel_config_deinit(models); #else return srmodel_spiffs_deinit(models); #endif + +#else + return srmodel_sdcard_deinit(models); +#endif } // repackage strstr function to support needle==NULL