mirror of
https://github.com/espressif/esp-sr.git
synced 2025-09-15 15:28:44 +08:00
refact: rename AFE handle for voice communication
This commit is contained in:
parent
af859c9012
commit
bbbe7849cd
@ -132,7 +132,7 @@ Now The ESP32S3 API is compatible with ESP32. You can refer to the ESP32S3 metho
|
||||
//
|
||||
// step1: initialize spiffs and return models in spiffs
|
||||
//
|
||||
srmodel_list_t *models = esp_srmodel_init();
|
||||
srmodel_list_t *models = esp_srmodel_init("model");
|
||||
|
||||
//
|
||||
// step2: select the specific model by keywords
|
||||
|
||||
@ -39,8 +39,8 @@ typedef struct {
|
||||
bool vad_init;
|
||||
bool wakenet_init;
|
||||
bool voice_communication_init;
|
||||
bool voip_agc_init; // AGC swich for voice communication
|
||||
int voip_agc_gain; // AGC gain(dB) for voice communication
|
||||
bool voice_communication_agc_init; // AGC swich for voice communication
|
||||
int voice_communication_agc_gain; // AGC gain(dB) for voice communication
|
||||
vad_mode_t vad_mode; // The value can be: VAD_MODE_0, VAD_MODE_1, VAD_MODE_2, VAD_MODE_3, VAD_MODE_4
|
||||
char *wakenet_model_name; // The model name of wakenet
|
||||
det_mode_t wakenet_mode;
|
||||
@ -61,8 +61,8 @@ typedef struct {
|
||||
.vad_init = true, \
|
||||
.wakenet_init = true, \
|
||||
.voice_communication_init = false, \
|
||||
.voip_agc_init = false, \
|
||||
.voip_agc_gain = 15, \
|
||||
.voice_communication_agc_init = false, \
|
||||
.voice_communication_agc_gain = 15, \
|
||||
.vad_mode = VAD_MODE_3, \
|
||||
.wakenet_model_name = NULL, \
|
||||
.wakenet_mode = DET_MODE_90, \
|
||||
@ -83,8 +83,8 @@ typedef struct {
|
||||
.vad_init = true, \
|
||||
.wakenet_init = true, \
|
||||
.voice_communication_init = false, \
|
||||
.voip_agc_init = false, \
|
||||
.voip_agc_gain = 15, \
|
||||
.voice_communication_agc_init = false, \
|
||||
.voice_communication_agc_gain = 15, \
|
||||
.vad_mode = VAD_MODE_3, \
|
||||
.wakenet_model_name = NULL, \
|
||||
.wakenet_mode = DET_MODE_2CH_90, \
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
|
||||
#if CONFIG_AFE_INTERFACE_V1
|
||||
extern const esp_afe_sr_iface_t esp_afe_sr_v1;
|
||||
extern const esp_afe_sr_iface_t esp_afe_voip_v1;
|
||||
extern const esp_afe_sr_iface_t esp_afe_vc_v1;
|
||||
#define ESP_AFE_SR_HANDLE esp_afe_sr_v1
|
||||
#define ESP_AFE_VOIP_HANDLE esp_afe_voip_v1
|
||||
#define ESP_AFE_VC_HANDLE esp_afe_vc_v1
|
||||
|
||||
#else
|
||||
#error No valid afe selected.
|
||||
@ -20,8 +20,8 @@ extern const esp_afe_sr_iface_t esp_afe_voip_v1;
|
||||
|
||||
#include "esp_afe_sr_iface.h"
|
||||
extern const esp_afe_sr_iface_t esp_afe_sr_v1;
|
||||
extern const esp_afe_sr_iface_t esp_afe_voip_v1;
|
||||
extern const esp_afe_sr_iface_t esp_afe_vc_v1;
|
||||
#define ESP_AFE_SR_HANDLE esp_afe_sr_v1
|
||||
#define ESP_AFE_VOIP_HANDLE esp_afe_voip_v1
|
||||
#define ESP_AFE_VC_HANDLE esp_afe_vc_v1
|
||||
|
||||
#endif
|
||||
@ -2,8 +2,9 @@
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char **model_name; // the name of models, like "wn9_hilexin"(wakenet9, hilexin), "mn5_en"(multinet5, english)
|
||||
int num; // the number of models
|
||||
char **model_name; // the name of models, like "wn9_hilexin"(wakenet9, hilexin), "mn5_en"(multinet5, english)
|
||||
char *partition_label; // partition label used to save the files of model
|
||||
int num; // the number of models
|
||||
} srmodel_list_t;
|
||||
|
||||
#define MODEL_NAME_MAX_LENGTH 64
|
||||
@ -11,9 +12,11 @@ typedef struct
|
||||
/**
|
||||
* @brief Return all avaliable models in spiffs or selected in Kconfig.
|
||||
*
|
||||
* @param partition_label The spiffs label defined in your partition file used to save models.
|
||||
*
|
||||
* @return all avaliable models in spiffs,save as srmodel_list_t.
|
||||
*/
|
||||
srmodel_list_t* esp_srmodel_init(void);
|
||||
srmodel_list_t* esp_srmodel_init(const char* partition_label);
|
||||
|
||||
/**
|
||||
* @brief Free srmodel_list_t and unregister SPIFFS filesystem if open SPIFFS filesystem.
|
||||
@ -52,9 +55,11 @@ int esp_srmodel_exists(srmodel_list_t *models, char *model_name);
|
||||
/**
|
||||
* @brief Initialize and mount SPIFFS filesystem, return all avaliable models in spiffs.
|
||||
*
|
||||
* @param partition_label The spiffs label defined in your partition file used to save models.
|
||||
*
|
||||
* @return all avaliable models in spiffs,save as srmodel_list_t.
|
||||
*/
|
||||
srmodel_list_t *srmodel_spiffs_init(void);
|
||||
srmodel_list_t *srmodel_spiffs_init(const char* partition_label);
|
||||
|
||||
/**
|
||||
* @brief unregister SPIFFS filesystem and free srmodel_list_t.
|
||||
|
||||
@ -39,8 +39,8 @@ typedef struct {
|
||||
bool vad_init;
|
||||
bool wakenet_init;
|
||||
bool voice_communication_init;
|
||||
bool voip_agc_init; // AGC swich for voice communication
|
||||
int voip_agc_gain; // AGC gain(dB) for voice communication
|
||||
bool voice_communication_agc_init; // AGC swich for voice communication
|
||||
int voice_communication_agc_gain; // AGC gain(dB) for voice communication
|
||||
vad_mode_t vad_mode; // The value can be: VAD_MODE_0, VAD_MODE_1, VAD_MODE_2, VAD_MODE_3, VAD_MODE_4
|
||||
char *wakenet_model_name; // The model name of wakenet
|
||||
det_mode_t wakenet_mode;
|
||||
@ -61,8 +61,8 @@ typedef struct {
|
||||
.vad_init = true, \
|
||||
.wakenet_init = true, \
|
||||
.voice_communication_init = false, \
|
||||
.voip_agc_init = false, \
|
||||
.voip_agc_gain = 15, \
|
||||
.voice_communication_agc_init = false, \
|
||||
.voice_communication_agc_gain = 15, \
|
||||
.vad_mode = VAD_MODE_3, \
|
||||
.wakenet_model_name = NULL, \
|
||||
.wakenet_mode = DET_MODE_90, \
|
||||
@ -83,8 +83,8 @@ typedef struct {
|
||||
.vad_init = true, \
|
||||
.wakenet_init = true, \
|
||||
.voice_communication_init = false, \
|
||||
.voip_agc_init = false, \
|
||||
.voip_agc_gain = 15, \
|
||||
.voice_communication_agc_init = false, \
|
||||
.voice_communication_agc_gain = 15, \
|
||||
.vad_mode = VAD_MODE_3, \
|
||||
.wakenet_model_name = NULL, \
|
||||
.wakenet_mode = DET_MODE_2CH_90, \
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
|
||||
#if CONFIG_AFE_INTERFACE_V1
|
||||
extern const esp_afe_sr_iface_t esp_afe_sr_v1;
|
||||
extern const esp_afe_sr_iface_t esp_afe_voip_v1;
|
||||
extern const esp_afe_sr_iface_t esp_afe_vc_v1;
|
||||
#define ESP_AFE_SR_HANDLE esp_afe_sr_v1
|
||||
#define ESP_AFE_VOIP_HANDLE esp_afe_voip_v1
|
||||
#define ESP_AFE_VC_HANDLE esp_afe_vc_v1
|
||||
|
||||
#else
|
||||
#error No valid afe selected.
|
||||
@ -20,8 +20,8 @@ extern const esp_afe_sr_iface_t esp_afe_voip_v1;
|
||||
|
||||
#include "esp_afe_sr_iface.h"
|
||||
extern const esp_afe_sr_iface_t esp_afe_sr_v1;
|
||||
extern const esp_afe_sr_iface_t esp_afe_voip_v1;
|
||||
extern const esp_afe_sr_iface_t esp_afe_vc_v1;
|
||||
#define ESP_AFE_SR_HANDLE esp_afe_sr_v1
|
||||
#define ESP_AFE_VOIP_HANDLE esp_afe_voip_v1
|
||||
#define ESP_AFE_VC_HANDLE esp_afe_vc_v1
|
||||
|
||||
#endif
|
||||
@ -2,8 +2,9 @@
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char **model_name; // the name of models, like "wn9_hilexin"(wakenet9, hilexin), "mn5_en"(multinet5, english)
|
||||
int num; // the number of models
|
||||
char **model_name; // the name of models, like "wn9_hilexin"(wakenet9, hilexin), "mn5_en"(multinet5, english)
|
||||
char *partition_label; // partition label used to save the files of model
|
||||
int num; // the number of models
|
||||
} srmodel_list_t;
|
||||
|
||||
#define MODEL_NAME_MAX_LENGTH 64
|
||||
@ -11,9 +12,11 @@ typedef struct
|
||||
/**
|
||||
* @brief Return all avaliable models in spiffs or selected in Kconfig.
|
||||
*
|
||||
* @param partition_label The spiffs label defined in your partition file used to save models.
|
||||
*
|
||||
* @return all avaliable models in spiffs,save as srmodel_list_t.
|
||||
*/
|
||||
srmodel_list_t* esp_srmodel_init(void);
|
||||
srmodel_list_t* esp_srmodel_init(const char* partition_label);
|
||||
|
||||
/**
|
||||
* @brief Free srmodel_list_t and unregister SPIFFS filesystem if open SPIFFS filesystem.
|
||||
@ -52,9 +55,11 @@ int esp_srmodel_exists(srmodel_list_t *models, char *model_name);
|
||||
/**
|
||||
* @brief Initialize and mount SPIFFS filesystem, return all avaliable models in spiffs.
|
||||
*
|
||||
* @param partition_label The spiffs label defined in your partition file used to save models.
|
||||
*
|
||||
* @return all avaliable models in spiffs,save as srmodel_list_t.
|
||||
*/
|
||||
srmodel_list_t *srmodel_spiffs_init(void);
|
||||
srmodel_list_t *srmodel_spiffs_init(const char* partition_label);
|
||||
|
||||
/**
|
||||
* @brief unregister SPIFFS filesystem and free srmodel_list_t.
|
||||
|
||||
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.
@ -16,7 +16,7 @@ void check_chip_config(void)
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ESPTOOLPY_FLASHFREQ_80M
|
||||
ESP_LOGE(TAG, "Flash freq should be 240MHz");
|
||||
ESP_LOGE(TAG, "Flash freq should be 80MHz");
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SPIRAM_SPEED_80M
|
||||
@ -892,6 +892,7 @@ esp_err_t esp_mn_commands_update_from_sdkconfig(esp_mn_iface_t *multinet, const
|
||||
#else
|
||||
ESP_LOGE(TAG, "Incorrect language");
|
||||
#endif
|
||||
|
||||
if (command_str == NULL) continue;
|
||||
command_str_len = strlen(command_str);
|
||||
if (command_str_len <= 0) continue;
|
||||
|
||||
@ -7,29 +7,37 @@
|
||||
#include "model_path.h"
|
||||
#include "esp_wn_models.h"
|
||||
#include "esp_mn_models.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
static char *TAG = "MODEL_LOADER";
|
||||
static char *SRMODE_BASE_PATH = "/srmodel";
|
||||
|
||||
char *get_model_base_path(void)
|
||||
{
|
||||
#if defined CONFIG_MODEL_IN_SDCARD
|
||||
return "sdcard";
|
||||
#elif defined CONFIG_MODEL_IN_SPIFFS
|
||||
return "srmodel";
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
return SRMODE_BASE_PATH;
|
||||
}
|
||||
|
||||
srmodel_list_t *read_models_form_spiffs(const char *path)
|
||||
int set_model_base_path(const char *base_path)
|
||||
{
|
||||
if (base_path == NULL) return 0;
|
||||
|
||||
SRMODE_BASE_PATH = base_path;
|
||||
return 1;
|
||||
}
|
||||
|
||||
srmodel_list_t *read_models_form_spiffs(esp_vfs_spiffs_conf_t *conf)
|
||||
{
|
||||
struct dirent *ret;
|
||||
DIR *dir;
|
||||
dir = opendir(path);
|
||||
dir = opendir(conf->base_path);
|
||||
srmodel_list_t *models = malloc(sizeof(srmodel_list_t*));
|
||||
models->num = 0;
|
||||
models->partition_label = conf->partition_label;
|
||||
int idx = 0;
|
||||
|
||||
if (dir != NULL)
|
||||
{
|
||||
// get the number of models
|
||||
while ((ret = readdir(dir)) != NULL)
|
||||
{ // NULL if reach the end of directory
|
||||
|
||||
@ -42,13 +50,15 @@ srmodel_list_t *read_models_form_spiffs(const char *path)
|
||||
if (strcmp(suffix, "_MODEL_INFO_") == 0)
|
||||
models->num ++;
|
||||
}
|
||||
|
||||
// allocate model names
|
||||
models->model_name = malloc(models->num*sizeof(char*));
|
||||
for (int i=0; i<models->num; i++) {
|
||||
models->model_name[i] = (char*) calloc(MODEL_NAME_MAX_LENGTH, sizeof(char));
|
||||
}
|
||||
|
||||
dir = opendir(path);
|
||||
// read& save model names
|
||||
dir = opendir(conf->base_path);
|
||||
while ((ret = readdir(dir)) != NULL)
|
||||
{ // NULL if reach the end of directory
|
||||
|
||||
@ -70,13 +80,14 @@ srmodel_list_t *read_models_form_spiffs(const char *path)
|
||||
}
|
||||
|
||||
|
||||
srmodel_list_t* srmodel_spiffs_init(void)
|
||||
srmodel_list_t* srmodel_spiffs_init(const char *partition_label)
|
||||
{
|
||||
printf("Initializing models from SPIFFS\n");
|
||||
printf(" \n");
|
||||
ESP_LOGI(TAG, "Initializing models from SPIFFS, partition label: %s", partition_label);
|
||||
|
||||
esp_vfs_spiffs_conf_t conf = {
|
||||
.base_path = "/srmodel",
|
||||
.partition_label = "model",
|
||||
.base_path = SRMODE_BASE_PATH,
|
||||
.partition_label = partition_label,
|
||||
.max_files = 5,
|
||||
.format_if_mount_failed = true
|
||||
};
|
||||
@ -87,30 +98,39 @@ srmodel_list_t* srmodel_spiffs_init(void)
|
||||
|
||||
if (ret != ESP_OK) {
|
||||
if (ret == ESP_FAIL) {
|
||||
printf("Failed to mount or format filesystem\n");
|
||||
ESP_LOGE(TAG, "Failed to mount or format filesystem\n");
|
||||
} else if (ret == ESP_ERR_NOT_FOUND) {
|
||||
printf("Failed to find SPIFFS partition\n");
|
||||
ESP_LOGE(TAG, "Failed to find SPIFFS partition\n");
|
||||
} else {
|
||||
printf("Failed to initialize SPIFFS (%s)\n", esp_err_to_name(ret));
|
||||
ESP_LOGE(TAG, "Failed to initialize SPIFFS (%s)\n", esp_err_to_name(ret));
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t total = 0, used = 0;
|
||||
ret = esp_spiffs_info("model", &total, &used);
|
||||
ret = esp_spiffs_info(partition_label, &total, &used);
|
||||
if (ret != ESP_OK) {
|
||||
printf("Failed to get SPIFFS partition information (%s)\n", esp_err_to_name(ret));
|
||||
ESP_LOGE(TAG, "Failed to get SPIFFS partition information (%s)\n", esp_err_to_name(ret));
|
||||
} else {
|
||||
printf("Partition size: total: %d, used: %d\n", total, used);
|
||||
ESP_LOGI(TAG, "Partition size: total: %d, used: %d\n", total, used);
|
||||
}
|
||||
|
||||
// Read all model from path
|
||||
return read_models_form_spiffs(conf.base_path);
|
||||
return read_models_form_spiffs(&conf);
|
||||
}
|
||||
|
||||
|
||||
void srmodel_spiffs_deinit(srmodel_list_t *models)
|
||||
{
|
||||
if (models->partition_label != NULL) {
|
||||
esp_err_t ret = esp_vfs_spiffs_unregister(models->partition_label);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGW(TAG, "Already unregistered\n");
|
||||
} else {
|
||||
ESP_LOGI(TAG, "%s has been unregistered\n", models->partition_label);
|
||||
}
|
||||
}
|
||||
|
||||
if (models != NULL) {
|
||||
if (models->num>0) {
|
||||
for (int i=0; i<models->num; i++) {
|
||||
@ -120,13 +140,6 @@ void srmodel_spiffs_deinit(srmodel_list_t *models)
|
||||
free(models);
|
||||
}
|
||||
|
||||
esp_vfs_spiffs_conf_t conf = {
|
||||
.base_path = "/srmodel",
|
||||
.partition_label = "model",
|
||||
.max_files = 5,
|
||||
.format_if_mount_failed = true
|
||||
};
|
||||
esp_vfs_spiffs_unregister(conf.partition_label);
|
||||
}
|
||||
|
||||
srmodel_list_t *srmodel_config_init()
|
||||
@ -176,12 +189,12 @@ void srmodel_config_deinit(srmodel_list_t *models)
|
||||
}
|
||||
|
||||
|
||||
srmodel_list_t* esp_srmodel_init()
|
||||
srmodel_list_t* esp_srmodel_init(const char* base_path)
|
||||
{
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32
|
||||
return srmodel_config_init();
|
||||
#else
|
||||
return srmodel_spiffs_init();
|
||||
return srmodel_spiffs_init(base_path);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user