ESP-SR compile error

Hello. I'm trying to test ESP-SR on my ESP32, but I get an error while compiling: 'sr_cmd_t' does not name a type. The code was taken from the ESP-SR example. The board I am using is an ESP32.

Which exact ESP32 board have you selected in the IDE?

Based on the library files it looks like you need an ESP32S3 based board.

Please post your code here, using code tags when you do

ESP32 Dev Module

#include "ESP_I2S.h"
#include "ESP_SR.h"

#define I2S_PIN_BCK 17
#define I2S_PIN_WS  47
#define I2S_PIN_DIN 16

#define LIGHT_PIN 40
#define FAN_PIN   41

I2SClass i2s;

// Generated using the following command:
// python3 tools/gen_sr_commands.py "Turn on the light,Switch on the light;Turn off the light,Switch off the light,Go dark;Start fan;Stop fan"
enum {
  SR_CMD_TURN_ON_THE_LIGHT,
  SR_CMD_TURN_OFF_THE_LIGHT,
  SR_CMD_START_FAN,
  SR_CMD_STOP_FAN,
};
static const sr_cmd_t sr_commands[] = {
  {0, "Turn on the light", "TkN nN jc LiT"},
  {0, "Switch on the light", "SWgp nN jc LiT"},
  {1, "Turn off the light", "TkN eF jc LiT"},
  {1, "Switch off the light", "SWgp eF jc LiT"},
  {1, "Go dark", "Gb DnRK"},
  {2, "Start fan", "STnRT FaN"},
  {3, "Stop fan", "STnP FaN"},
};

void onSrEvent(sr_event_t event, int command_id, int phrase_id) {
  switch (event) {
    case SR_EVENT_WAKEWORD: Serial.println("WakeWord Detected!"); break;
    case SR_EVENT_WAKEWORD_CHANNEL:
      Serial.printf("WakeWord Channel %d Verified!\n", command_id);
      ESP_SR.setMode(SR_MODE_COMMAND);  // Switch to Command detection
      break;
    case SR_EVENT_TIMEOUT:
      Serial.println("Timeout Detected!");
      ESP_SR.setMode(SR_MODE_WAKEWORD);  // Switch back to WakeWord detection
      break;
    case SR_EVENT_COMMAND:
      Serial.printf("Command %d Detected! %s\n", command_id, sr_commands[phrase_id].str);
      switch (command_id) {
        case SR_CMD_TURN_ON_THE_LIGHT:  digitalWrite(LIGHT_PIN, HIGH); break;
        case SR_CMD_TURN_OFF_THE_LIGHT: digitalWrite(LIGHT_PIN, LOW); break;
        case SR_CMD_START_FAN:          digitalWrite(FAN_PIN, HIGH); break;
        case SR_CMD_STOP_FAN:           digitalWrite(FAN_PIN, LOW); break;
        default:                        Serial.println("Unknown Command!"); break;
      }
      ESP_SR.setMode(SR_MODE_COMMAND);  // Allow for more commands to be given, before timeout
      // ESP_SR.setMode(SR_MODE_WAKEWORD); // Switch back to WakeWord detection
      break;
    default: Serial.println("Unknown Event!"); break;
  }
}

void setup() {
  Serial.begin(115200);

  pinMode(LIGHT_PIN, OUTPUT);
  digitalWrite(LIGHT_PIN, LOW);
  pinMode(FAN_PIN, OUTPUT);
  digitalWrite(FAN_PIN, LOW);

  i2s.setPins(I2S_PIN_BCK, I2S_PIN_WS, -1, I2S_PIN_DIN);
  i2s.setTimeout(1000);
  i2s.begin(I2S_MODE_STD, 16000, I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO);

  ESP_SR.onEvent(onSrEvent);
  ESP_SR.begin(i2s, sr_commands, sizeof(sr_commands) / sizeof(sr_cmd_t), SR_CHANNELS_STEREO, SR_MODE_WAKEWORD);
}

void loop() {}```

I tried the basic example on a variety of ESP32 based boards and it failed in the same fashion as you posted. Next I search for sr_cmd_t and found the below in C:\Users\bugge\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.1\libraries\ESP_SR\src\esp32-hal-sr.h (where bugge is my user name)

#if CONFIG_IDF_TARGET_ESP32S3 && (CONFIG_USE_WAKENET || CONFIG_USE_MULTINET)

Note the CONFIG_IDF_TARGET_ESP32S3.

So next I tried to compile for an ESP32S3 based board and that compiles without issues.

So, does that mean I can’t use ESP-SR with my ESP32? If so, then what other offline speech recognition library can I use for it?

I suspect that that is the case but I'm not an ESP32 user.

I have no idea.

I haven't used any Espressif hardware, yet, but I found this. Don't know if it helps at all.

The new library supports the base ESP32 family, the ESP32-S3, and the ESP32-S2 and ESP32-C3 — though while speech recognition is available in Chinese and English on all devices, the library's support for text-to-speech was limited to Chinese at the time of writing.

The new ESP-SR release is now available on GitHub, along with the source code under a permissive variant of the MIT license.

Actually I don’t think there are any offline speech recognition software for the regular ESP32 chips.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.