纳入固件源码、屏幕组件、nand_xfer 工具和文档。忽略本机构建产物、sdkconfig,以及含本机路径的依赖锁。 Co-authored-by: Cursor <[email protected]>
100 lines
3.4 KiB
C
100 lines
3.4 KiB
C
#include "speech_init.h"
|
|
#include "speech_app.h"
|
|
#include "main.h"
|
|
|
|
srmodel_list_t *models = NULL;
|
|
afe_config_t *afe_config = NULL;
|
|
esp_afe_sr_iface_t *afe_handle = NULL;
|
|
esp_afe_sr_data_t *afe_data = NULL;
|
|
const esp_mn_iface_t *multinet = NULL;
|
|
model_iface_data_t *model_data = NULL;
|
|
char *mn_name = NULL;
|
|
|
|
|
|
static const char *TAG_LVGL = "sr";
|
|
|
|
|
|
|
|
esp_err_t app_sr_init(void)
|
|
{
|
|
//record_dev = ES7243E_Init();
|
|
|
|
/* 配置音频前端参数 */
|
|
// srmodel_list_t *models = esp_srmodel_init("model");
|
|
/*
|
|
models = esp_srmodel_init("model");
|
|
// afe_config_t *afe_config = afe_config_init("MM", models, AFE_TYPE_SR, AFE_MODE_LOW_COST);
|
|
afe_config = afe_config_init("MM", models, AFE_TYPE_SR, AFE_MODE_LOW_COST);
|
|
|
|
// afe_config>memory_alloc_mode = AFE_MEMORY_ALLOC_MORE_PSRAM;
|
|
afe_config->wakenet_model_name = NULL;
|
|
afe_config->aec_init = false; // 关闭回声消除(根据需求调整)
|
|
afe_config->vad_init = false; // 启用VAD(语音活动检测)
|
|
afe_config->pcm_config.total_ch_num = 2; // 总通道数 = 2
|
|
afe_config->pcm_config.mic_num = 2; // 麦克风通道数 = 2
|
|
afe_config->pcm_config.ref_num = 0; // 回放参考通道数 = 0
|
|
afe_config->afe_ringbuf_size = 20;
|
|
//afe_config->vad_mode = VAD_MODE_0;
|
|
afe_config->agc_init = false; // 关闭自动增益控制(根据需求调整)
|
|
afe_config->ns_init = false;
|
|
afe_config->afe_linear_gain = 2.0;
|
|
ESP_LOGE(TAG_LVGL, "配置前 afe_ringbuf_size = %d", afe_config->afe_ringbuf_size);
|
|
|
|
afe_handle = esp_afe_handle_from_config(afe_config);
|
|
// esp_afe_sr_data_t *afe_data = afe_handle->create_from_config(afe_config);
|
|
afe_data = afe_handle->create_from_config(afe_config);
|
|
*/
|
|
// char *mn_name = esp_srmodel_filter(models, ESP_MN_CHINESE, NULL);
|
|
srmodel_list_t *models = esp_srmodel_init("model");
|
|
if (models == NULL) {
|
|
ESP_LOGE(TAG_LVGL, "未找到 model 分区,跳过语音模型");
|
|
return ESP_OK;
|
|
}
|
|
mn_name = esp_srmodel_filter(models, ESP_MN_CHINESE, NULL);
|
|
if (NULL == mn_name)
|
|
{
|
|
ESP_LOGE(TAG_LVGL, "未找到多网络模型");
|
|
return ESP_OK;
|
|
}
|
|
|
|
multinet = esp_mn_handle_from_name(mn_name);
|
|
model_data = multinet->create(mn_name, 30000); // 设置语音识别超时时间
|
|
|
|
/* 配置语音命令 */
|
|
esp_mn_commands_clear(); // 清除现有命令
|
|
// 添加所有语音命令
|
|
for (int i = 0; i < cmd_phoneme_number; i++)
|
|
{
|
|
esp_mn_commands_add(i, (char *)cmd_phoneme[i]);
|
|
}
|
|
|
|
esp_mn_commands_update(); // 更新命令词列表
|
|
esp_mn_commands_print();
|
|
multinet->print_active_speech_commands(model_data); // 输出目前激活的命令词
|
|
|
|
afe_config_free(afe_config); /* 释放配置内存 */
|
|
|
|
feed_task_stack = heap_caps_malloc(FEED_TASK_STACK_SIZE, MALLOC_CAP_SPIRAM);
|
|
detect_task_stack = heap_caps_malloc(DETECT_TASK_STACK_SIZE, MALLOC_CAP_SPIRAM);
|
|
|
|
if (feed_task_stack == NULL || detect_task_stack == NULL)
|
|
{
|
|
ESP_LOGE(TAG_LVGL, "PSRAM 内存分配失败");
|
|
return ESP_OK;
|
|
}
|
|
|
|
//xTaskCreateStaticPinnedToCore(feed_Task, "feed", FEED_TASK_STACK_SIZE, (void *)afe_data, FEED_TASK_PRIORITY, feed_task_stack, &feed_task_tcb, 1);
|
|
xTaskCreateStaticPinnedToCore(detect_Task, "detect", DETECT_TASK_STACK_SIZE, (void *)afe_data, DETECT_TASK_PRIORITY, detect_task_stack, &detect_task_tcb, 1);
|
|
|
|
return ESP_OK;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|