I am using esp-idf v5.5 with esp-sr v2.1.4. below is my updated github repo with complete build available (complete!). I thank you greatly for your help.
github_repo : https://github.com/abdulbaseer-1/ESP32_chatbot_hijason.git
Below is the minimum code required to reproduce the error.
The backtrace points the error out in wn_handle = wakenet->create(wn_name, WAKE_MODE); from wakeword.c
main.c:
**#include <stdio.h>
#include <inttypes.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_chip_info.h"
#include "esp_flash.h"
#include "esp_system.h"
#include "mic_i2s.h"
#include "wakeword.h"
#include "esp_log.h"
#define TAG "MAIN"
static void wakeword_detected_callback() {
ESP_LOGI(TAG, "Wake word callback triggered");
}
void app_main(void)
{
ESP_LOGI(TAG, "Starting application");
// Initialize I2S microphone
ESP_LOGI(TAG, "Starting audio recording...");
i2s_mic_init();
// Initialize wake-word detection
wakeword_init_multinet(wakeword_detected_callback); //, NULL // Init WakeNet
}**
wakeword.c:
**#include "esp_wn_models.h"
#include "wakeword.h"
#include "mic_i2s.h"
#include "esp_log.h"
#include "model_path.h"
#include "esp_wn_iface.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
static const char *TAG = "WakeMultinet";
#define SAMPLE_RATE 16000
#define BUFFER_SIZE 512
#define WAKE_MODE DET_MODE_95
#define CMD_TIMEOUT 40 // ~0.5s @ 16kHz
static wakeword_callback_t ww_callback = NULL;
static srmodel_list_t *sr_models = NULL;
static const esp_wn_iface_t *wakenet = NULL;
static model_iface_data_t *wn_handle = NULL;
void wakeword_init_multinet(wakeword_callback_t wake_cb) {
ww_callback = wake_cb;
// Initialize model list from partition
sr_models = esp_srmodel_init("model");
if (!sr_models) {
ESP_LOGE(TAG, "Failed to init model list");
return;
}
// Initialize WakeNet
char *wn_name = esp_srmodel_filter(sr_models, ESP_WN_PREFIX, NULL);
if (!wn_name) {
ESP_LOGE(TAG, "No WakeNet model found");
esp_srmodel_deinit(sr_models);
return;
}
int wn_index = esp_srmodel_exists(sr_models, wn_name);
if (wn_index < 0 || wn_index >= sr_models->num) {
ESP_LOGE(TAG, "WakeNet model %s not found in list", wn_name);
esp_srmodel_deinit(sr_models);
return;
}
//srmodel_data_t *wn_data = sr_models->model_data[wn_index];//dev says dont need this ,just add name
wakenet = esp_wn_handle_from_name(wn_name);
if (!wakenet) {
ESP_LOGE(TAG, "Failed to get WakeNet handle for %s", wn_name);
esp_srmodel_deinit(sr_models);
return;
}
//for debugging
ESP_LOGI(TAG, "Using WakeNet: %s", wn_name);
wn_handle = wakenet->create(wn_name, WAKE_MODE);
if (!wn_handle) {
ESP_LOGE(TAG, "WakeNet creation failed for %s", wn_name);
esp_srmodel_deinit(sr_models);
return;
}
ESP_LOGI(TAG, "WakeNet (%s) and MultiNet (%s) initialized", wn_name, "placeholder");//mn_name
}
void wakeword_task(void *arg) {
int16_t *buffer = calloc(BUFFER_SIZE, sizeof(int16_t));
if (!buffer) {
ESP_LOGE(TAG, "Buffer allocation failed");
vTaskDelete(NULL);
return;
}
while (1) {
int bytes_read = i2s_mic_read((char *)buffer, BUFFER_SIZE * sizeof(int16_t));
if (bytes_read <= 0) continue;
if (wakenet->detect(wn_handle, buffer) == WAKENET_DETECTED) {
ESP_LOGI(TAG, "Wake word detected");
if (ww_callback) ww_callback();
}
}
// Cleanup (not usually reached)
free(buffer);
wakenet->destroy(wn_handle);
esp_srmodel_deinit(sr_models);
vTaskDelete(NULL);
}**
Error Log:
I (303) MODEL_LOADER: The storage free size is 32448 KB I (303) MODEL_LOADER: The partition size is 8192 KB I (313) MODEL_LOADER: Successfully load srmodels I (313) WakeMultinet: Using WakeNet: wn9_hijason_tts2 Guru Meditation Error: Core 0 panic'ed (StoreProhibited). Exception was unhandled.
Core 0 register dump: PC : 0x40055835 PS : 0x00060b30 A0 : 0x8201f218 A1 : 0x3fc9bea0 A2 : 0x00000000 A3 : 0x3fceb888 A4 : 0x0000002a A5 : 0x0000ff00 A6 : 0x00ff0000 A7 : 0xff000000 A8 : 0x656b6177 A9 : 0x3fc9be70 A10 : 0x00000000 A11 : 0x000000ff A12 : 0x3c049f00 A13 : 0x3fc9be30 A14 : 0x3fc9bd14 A15 : 0x0000002a SAR : 0x00000016 EXCCAUSE: 0x0000001d EXCVADDR: 0x00000000 LBEG : 0x40055825 LEND : 0x4005583f LCOUNT : 0xffffffff
Backtrace: 0x40055832:0x3fc9bea0 0x4201f215:0x3fc9beb0 0x4200d4a6:0x3fc9bef0 0x4200dba4:0x3fc9c0b0 0x4200a4f0:0x3fc9c0d0 0x4200a315:0x3fc9c100 0x4203d8fc:0x3fc9c120 0x4037b4ed:0x3fc9c150
I tried to initialize wakenet model using esp-sr lirary but got no success as it always results in the same error. I have tried changing the partitions, the way I load the models and even the models themselves but nothing seems to be working.
StoreProhibitedwithEXCVADDR: 0x00000000indicates an attempted write to a null pointer. This may be due to a failure to allocate heap memory and subsequent use of the null pointer returned by mallo() without a check. You may be out of heap memory, or missing an initialization step which would initialize some pointer field.