Update sr.
This commit is contained in:
parent
29c08f655b
commit
f0d0856b7e
|
|
@ -1,4 +1,3 @@
|
|||
build
|
||||
managed_components
|
||||
*.lock
|
||||
sdkconfig
|
||||
*.lock
|
||||
|
|
@ -46,6 +46,7 @@
|
|||
"stdbool.h": "c",
|
||||
"esp_afe_sr_models.h": "c",
|
||||
"esp_afe_config.h": "c",
|
||||
"esp_afe_sr_iface.h": "c"
|
||||
"esp_afe_sr_iface.h": "c",
|
||||
"esp_err.h": "c"
|
||||
}
|
||||
}
|
||||
117
main/app_sr.c
117
main/app_sr.c
|
|
@ -7,6 +7,7 @@
|
|||
// #include "audio_player.h"
|
||||
// #include "esp32_s3_szp.h"
|
||||
|
||||
#include "dl_lib_coefgetter_if.h"
|
||||
#include "esp_afe_sr_iface.h"
|
||||
#include "esp_afe_sr_models.h"
|
||||
#include "esp_err.h"
|
||||
|
|
@ -14,6 +15,7 @@
|
|||
#include "esp_mn_iface.h"
|
||||
#include "esp_mn_models.h"
|
||||
#include "esp_mn_speech_commands.h"
|
||||
#include "esp_nsn_models.h"
|
||||
#include "esp_process_sdkconfig.h"
|
||||
#include "esp_wn_iface.h"
|
||||
#include "esp_wn_models.h"
|
||||
|
|
@ -57,7 +59,7 @@ esp_err_t record_start2() {
|
|||
esp_err_t ret = ESP_OK;
|
||||
|
||||
const wav_header_t wav_header2 =
|
||||
WAV_HEADER_PCM_DEFAULT(16000 * 1 * 16 / 8 * 20, 16, 16000, 1);
|
||||
WAV_HEADER_PCM_DEFAULT(16000 * 2 * 16 / 8 * 20, 16, 16000, 2);
|
||||
|
||||
f2 = fopen("/sdcard/bbbbb.wav", "w");
|
||||
ESP_LOGI(TAG, "fopen error: %s", strerror(errno));
|
||||
|
|
@ -78,6 +80,7 @@ esp_err_t record_add1(int16_t* data1, uint32_t size) {
|
|||
// ESP_RETURN_ON_FALSE(fwrite(data1, size, 1, f1), ESP_FAIL, TAG,
|
||||
// "error while writing samples to wav file");
|
||||
wav_written1 += size;
|
||||
// ESP_LOGI(TAG, "Recording %d !", wav_written1);
|
||||
return ESP_OK;
|
||||
} else {
|
||||
if (wav_written1 < 0xFFFFFFFF) {
|
||||
|
|
@ -93,7 +96,7 @@ bool record_end1() { return wav_written1 == 0xFFFFFFFF; }
|
|||
bool record_end2() { return wav_written2 == 0xFFFFFFFF; }
|
||||
|
||||
esp_err_t record_add2(int16_t* data2, uint32_t size) {
|
||||
uint32_t byte_rate = 16000 * 1 * 16 / 8;
|
||||
uint32_t byte_rate = 16000 * 2 * 16 / 8;
|
||||
uint32_t wav_size = byte_rate * 20;
|
||||
|
||||
if (wav_written2 < wav_size) {
|
||||
|
|
@ -112,9 +115,30 @@ esp_err_t record_add2(int16_t* data2, uint32_t size) {
|
|||
return ESP_OK;
|
||||
}
|
||||
|
||||
void afe(esp_afe_sr_data_t* afe_data, int16_t* i2s_buff) {
|
||||
afe_handle->feed(afe_data, i2s_buff); // 把获取到的I2S数据输入给afe_data
|
||||
afe_fetch_result_t* res = afe_handle->fetch(afe_data);
|
||||
uint32_t afe_pipe = 0;
|
||||
|
||||
afe_fetch_result_t* afe(esp_afe_sr_data_t* afe_data, int16_t* i2s_buff) {
|
||||
afe_handle->feed(afe_data, i2s_buff);
|
||||
|
||||
// printf("AFE get_feed_chunksize: %d\n",
|
||||
// afe_handle->get_feed_chunksize(afe_data));
|
||||
// printf("AFE get_fetch_chunksize: %d\n",
|
||||
// afe_handle->get_fetch_chunksize(afe_data));
|
||||
// afe_handle->print_pipeline(afe_data);
|
||||
// printf("AFE get_channel_num: %d\n", afe_handle->get_channel_num(afe_data));
|
||||
// printf("AFE get_samp_rate: %d\n", afe_handle->get_samp_rate(afe_data));
|
||||
|
||||
afe_fetch_result_t* res = NULL;
|
||||
if (afe_pipe >= 5) {
|
||||
res = afe_handle->fetch(afe_data);
|
||||
// printf("AFE data_size: %d\n", res->data_size);
|
||||
// printf("AFE data_volume: %f\n", res->data_volume);
|
||||
// printf("AFE vad_state: %d\n", res->vad_state);
|
||||
// printf("AFE ret_value: %d\n", res->ret_value);
|
||||
} else {
|
||||
afe_pipe++;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void feed_Task(void* arg) {
|
||||
|
|
@ -288,82 +312,13 @@ void detect_Task(void* arg) {
|
|||
}
|
||||
|
||||
esp_afe_sr_data_t* sr_init() {
|
||||
// 获取模型 名称“model”和分区表中装载模型的名称一致
|
||||
models = esp_srmodel_init("model");
|
||||
|
||||
afe_handle = (esp_afe_sr_iface_t*)&ESP_AFE_SR_HANDLE;
|
||||
// 先配置afe句柄
|
||||
// 随后才可以调用afe接口
|
||||
// afe_config_t afe_config = AFE_CONFIG_DEFAULT(); // 配置afe
|
||||
afe_config_t afe_config = {
|
||||
.aec_init = true,
|
||||
.se_init = true,
|
||||
.vad_init = true,
|
||||
.wakenet_init = true,
|
||||
.voice_communication_init = false,
|
||||
.voice_communication_agc_init = false,
|
||||
.voice_communication_agc_gain = 15,
|
||||
.vad_mode = VAD_MODE_3,
|
||||
.wakenet_model_name = NULL,
|
||||
.wakenet_model_name_2 = NULL,
|
||||
.wakenet_mode = DET_MODE_2CH_90,
|
||||
.afe_mode = SR_MODE_LOW_COST,
|
||||
.afe_perferred_core = 0,
|
||||
.afe_perferred_priority = 5,
|
||||
.afe_ringbuf_size = 50,
|
||||
.memory_alloc_mode = AFE_MEMORY_ALLOC_MORE_PSRAM,
|
||||
.afe_linear_gain = 1.0,
|
||||
.agc_mode = AFE_MN_PEAK_AGC_MODE_2,
|
||||
.pcm_config =
|
||||
{
|
||||
.total_ch_num = 3,
|
||||
.mic_num = 2,
|
||||
.ref_num = 1,
|
||||
.sample_rate = 16000,
|
||||
},
|
||||
.debug_init = false,
|
||||
.debug_hook = {{AFE_DEBUG_HOOK_MASE_TASK_IN, NULL},
|
||||
{AFE_DEBUG_HOOK_FETCH_TASK_IN, NULL}},
|
||||
.afe_ns_mode = NS_MODE_SSP,
|
||||
.afe_ns_model_name = NULL,
|
||||
.fixed_first_channel = true,
|
||||
};
|
||||
|
||||
// 配置唤醒模型 必须在create_from_config之前配置
|
||||
|
||||
afe_config.aec_init = true;
|
||||
afe_config.se_init = true;
|
||||
afe_config.vad_init = true;
|
||||
afe_config.wakenet_init = false;
|
||||
afe_config.voice_communication_init = false;
|
||||
afe_config.voice_communication_agc_init = true;
|
||||
afe_config.voice_communication_agc_gain = 15;
|
||||
afe_config.vad_mode = VAD_MODE_3;
|
||||
afe_config.wakenet_model_name = NULL;
|
||||
afe_config.wakenet_model_name_2 = NULL;
|
||||
afe_config.wakenet_mode = DET_MODE_2CH_90;
|
||||
afe_config.afe_mode = SR_MODE_LOW_COST;
|
||||
afe_config.afe_perferred_core = 0;
|
||||
afe_config.afe_perferred_priority = 5;
|
||||
afe_config.afe_ringbuf_size = 50;
|
||||
afe_config.memory_alloc_mode = AFE_MEMORY_ALLOC_MORE_PSRAM;
|
||||
afe_config.afe_linear_gain = 4.0;
|
||||
afe_config.agc_mode = AFE_MN_PEAK_AGC_MODE_2;
|
||||
afe_config.pcm_config.total_ch_num = 3;
|
||||
afe_config.pcm_config.mic_num = 2;
|
||||
afe_config.pcm_config.ref_num = 1;
|
||||
afe_config.pcm_config.sample_rate = 16000;
|
||||
afe_config.debug_init = false;
|
||||
// afe_config.debug_hook = {{AFE_DEBUG_HOOK_MASE_TASK_IN, NULL},
|
||||
// {AFE_DEBUG_HOOK_FETCH_TASK_IN, NULL}};
|
||||
afe_config.afe_ns_mode = NS_MODE_SSP;
|
||||
afe_config.afe_ns_model_name = NULL;
|
||||
|
||||
// afe_config.wakenet_model_name =
|
||||
// esp_srmodel_filter(models, ESP_WN_PREFIX, NULL);
|
||||
return afe_handle->create_from_config(&afe_config); // 创建afe_data
|
||||
// ESP_LOGI(TAG, "wakenet:%s", afe_config.wakenet_model_name); //
|
||||
// 打印唤醒名称
|
||||
srmodel_list_t* models = esp_srmodel_init("model");
|
||||
afe_config_t* afe_config =
|
||||
afe_config_init("MM", models, AFE_TYPE_VC, AFE_MODE_LOW_COST);
|
||||
afe_handle = esp_afe_handle_from_config(afe_config);
|
||||
esp_afe_sr_data_t* afe_data = afe_handle->create_from_config(afe_config);
|
||||
afe_config_free(afe_config);
|
||||
return afe_data;
|
||||
}
|
||||
|
||||
void app_sr_init(void) {
|
||||
|
|
|
|||
|
|
@ -6,11 +6,9 @@
|
|||
#include "esp_afe_sr_models.h"
|
||||
#include "esp_err.h"
|
||||
|
||||
void app_sr_init(void);
|
||||
esp_afe_sr_data_t* sr_init();
|
||||
|
||||
void app_sr_init(void);
|
||||
|
||||
void afe(esp_afe_sr_data_t* afe_data, int16_t* i2s_buff);
|
||||
afe_fetch_result_t* afe(esp_afe_sr_data_t* afe_data, int16_t* i2s_buff);
|
||||
|
||||
bool record_end1();
|
||||
bool record_end2();
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ dependencies:
|
|||
version: "^2.0.0"
|
||||
espressif/es7210: "^1.0.0"
|
||||
chmorgan/esp-file-iterator: "1.0.0" # 获取文件
|
||||
espressif/esp-sr: "^1.6.0" # 语音识别
|
||||
espressif/esp-sr: "^2.0.0" # 语音识别
|
||||
idf:
|
||||
version: ">=5.4.0"
|
||||
|
||||
|
|
|
|||
26
main/main.c
26
main/main.c
|
|
@ -69,7 +69,7 @@
|
|||
#define SAMPLE_RATE 16000
|
||||
#define I2S_PORT I2S_NUM_0
|
||||
#define DMA_BUF_COUNT 8
|
||||
#define DMA_BUF_LEN 1024
|
||||
#define DMA_BUF_LEN 512
|
||||
#define SAMPLE_BITS I2S_DATA_BIT_WIDTH_16BIT
|
||||
|
||||
// 引脚定义
|
||||
|
|
@ -82,6 +82,8 @@
|
|||
static const char* TAG = "I2S_DMA_ISR";
|
||||
static i2s_chan_handle_t rx_chan = NULL;
|
||||
|
||||
esp_afe_sr_data_t* afe_sr_data = NULL;
|
||||
|
||||
// 中断服务程序的数据处理任务句柄
|
||||
static TaskHandle_t rx_task_handle = NULL;
|
||||
|
||||
|
|
@ -247,9 +249,22 @@ static void i2s_rx_task(void* arg) {
|
|||
// }
|
||||
|
||||
record_add1(data_buffer, bytes_read);
|
||||
if (!record_end1()) ESP_LOGI(TAG, "处理 %d 字节的I2S数据", bytes_read);
|
||||
// if (!record_end1()) ESP_LOGI(TAG, "处理 %d 字节的I2S数据", bytes_read);
|
||||
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
afe_fetch_result_t* res = afe(afe_sr_data, data_buffer);
|
||||
if (res != NULL) {
|
||||
record_add2(res->data, res->data_size);
|
||||
if (res->vad_state > 0) {
|
||||
printf("AFE data_size: %d\n", res->data_size);
|
||||
// printf("AFE data_volume: %f\n", res->data_volume);
|
||||
// printf("AFE vad_state: %d\n", res->vad_state);
|
||||
// printf("AFE ret_value: %d\n", res->ret_value);
|
||||
}
|
||||
}
|
||||
|
||||
if (record_end1() && record_end2()) break;
|
||||
|
||||
// vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
|
||||
// esp_sleep_enable_timer_wakeup(50 * 1000);
|
||||
// esp_light_sleep_start();
|
||||
|
|
@ -407,11 +422,12 @@ void app_main(void) {
|
|||
|
||||
ESP_LOGI(TAG, "启动I2S DMA接收示例");
|
||||
|
||||
// app_sr_init(); // 语音识别初始化
|
||||
afe_sr_data = sr_init();
|
||||
|
||||
config_power_manager();
|
||||
|
||||
record_start1();
|
||||
record_start2();
|
||||
|
||||
BaseType_t task_ret = xTaskCreate(i2s_rx_task, "i2s_rx_task", 4096, NULL,
|
||||
tskIDLE_PRIORITY + 2, &rx_task_handle);
|
||||
|
|
@ -429,7 +445,7 @@ void app_main(void) {
|
|||
// vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
// }
|
||||
|
||||
while (!record_end1()) {
|
||||
while (!record_end1() || !record_end2()) {
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -67,10 +67,11 @@ CONFIG_MODEL_IN_FLASH=y
|
|||
# CONFIG_MODEL_IN_SDCARD is not set
|
||||
CONFIG_USE_AFE=y
|
||||
CONFIG_AFE_INTERFACE_V1=y
|
||||
# CONFIG_USE_NSNET is not set
|
||||
CONFIG_USE_WAKENET=y
|
||||
CONFIG_USE_NSNET=y
|
||||
CONFIG_SR_NSN_NSNET2=y
|
||||
# CONFIG_USE_WAKENET=y
|
||||
# CONFIG_SR_WN_WN8_ALEXA is not set
|
||||
CONFIG_SR_WN_WN9_HILEXIN=y
|
||||
# CONFIG_SR_WN_WN9_HILEXIN=y
|
||||
# CONFIG_SR_WN_WN9_XIAOAITONGXUE is not set
|
||||
# CONFIG_SR_WN_WN9_ALEXA is not set
|
||||
# CONFIG_SR_WN_WN9_HIESP is not set
|
||||
|
|
@ -81,14 +82,14 @@ CONFIG_SR_WN_WN9_HILEXIN=y
|
|||
# CONFIG_SR_WN_WN9_HEYWILLOW_TTS is not set
|
||||
# CONFIG_SR_WN_WN9_CUSTOMWORD is not set
|
||||
# CONFIG_SR_WN_LOAD_MULIT_WORD is not set
|
||||
CONFIG_USE_MULTINET=y
|
||||
# CONFIG_USE_MULTINET=y
|
||||
# CONFIG_SR_MN_CN_NONE is not set
|
||||
# CONFIG_SR_MN_CN_MULTINET5_RECOGNITION_QUANT8 is not set
|
||||
CONFIG_SR_MN_CN_MULTINET6_QUANT=y
|
||||
# CONFIG_SR_MN_CN_MULTINET6_QUANT=y
|
||||
# CONFIG_SR_MN_CN_MULTINET6_AC_QUANT is not set
|
||||
# CONFIG_SR_MN_CN_MULTINET7_QUANT is not set
|
||||
# CONFIG_SR_MN_CN_MULTINET7_AC_QUANT is not set
|
||||
CONFIG_SR_MN_EN_NONE=y
|
||||
# CONFIG_SR_MN_EN_NONE=y
|
||||
# CONFIG_SR_MN_EN_MULTINET5_SINGLE_RECOGNITION_QUANT8 is not set
|
||||
# CONFIG_SR_MN_EN_MULTINET6_QUANT is not set
|
||||
# CONFIG_SR_MN_EN_MULTINET7_QUANT is not set
|
||||
|
|
|
|||
Loading…
Reference in New Issue