The voice model is trained on the Edge Ipulse to control the lighting and turning off of LED

Hi!I need some help.
Now I have trained a voice model on the edge ipulse that can recognize the “light on” and “light off” instructions. Now I want to call this model on Arduino IDE and write a program to control the LED on or off of Arduino nano 33 ble sense development board. After I follow the steps in the document to convert the pulse into C + + source code, I don’t know how to take the next step. I hope you can give me some advice. What can I do next?

Here is the converted code:

Hi @Joker,

I used the nano_ble33_sense_microphone_continous.ino example.

You can add something similar to this in the loop function :

void loop()
{
    bool m = microphone_inference_record();
    if (!m) {
        ei_printf("ERR: Failed to record audio...\n");
        return;
    }

    signal_t signal;
    signal.total_length = EI_CLASSIFIER_SLICE_SIZE;
    signal.get_data = &microphone_audio_signal_get_data;
    ei_impulse_result_t result = {0};

    EI_IMPULSE_ERROR r = run_classifier_continuous(&signal, &result, debug_nn);
    if (r != EI_IMPULSE_OK) {
        ei_printf("ERR: Failed to run classifier (%d)\n", r);
        return;
    }

    if (++print_results >= (EI_CLASSIFIER_SLICES_PER_MODEL_WINDOW)) {
        // print the predictions
        ei_printf("Predictions ");
        ei_printf("(DSP: %d ms., Classification: %d ms., Anomaly: %d ms.)",
            result.timing.dsp, result.timing.classification, result.timing.anomaly);
        ei_printf(": \n");
        for (size_t ix = 0; ix < EI_CLASSIFIER_LABEL_COUNT; ix++) {
            ei_printf("    %s: %.5f\n", result.classification[ix].label,
                      result.classification[ix].value);
        }
        if(result.classification[2].value>CMD_THRESHOLD){
          ei_printf("Turning off the leds \n");
          // turn the LED on (HIGH is the voltage level)                      
          digitalWrite(RED, LOW); 
          digitalWrite(GREEN, LOW);  
          digitalWrite(BLUE, LOW);  
          digitalWrite(LED_PWR, HIGH);
        }
        if(result.classification[5].value>CMD_THRESHOLD){
          ei_printf("Turning on the leds \n");
          // turn the LED on (HIGH is the voltage level)                      
          digitalWrite(RED, HIGH); 
          digitalWrite(GREEN, HIGH);  
          digitalWrite(BLUE, HIGH);  
          digitalWrite(LED_PWR, LOW);
        }
        
#if EI_CLASSIFIER_HAS_ANOMALY == 1
        ei_printf("    anomaly score: %.3f\n", result.anomaly);
#endif

        print_results = 0;
    }
  
}

Change the result.classification[2] with the right index of the keyword you want to detect (in my case the word up is at the index 2 and the word down is at the index 5).

And do not forget to define your LEDs and the threshold you want at the beginning of your Arduino sketch:

// Define LED
 #define RED 22     
 #define BLUE 24     
 #define GREEN 23
 #define LED_PWR 25

 #define CMD_THRESHOLD 0.8

And it is always a good practice to initialise the digital pins in the setup function:

//Initialize digital pin as an output for the LED
  pinMode(RED, OUTPUT);
  pinMode(BLUE, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(LED_PWR, OUTPUT);

Best regards,

Louis

1 Like

This error occurred when I compiled the default code created by edge impulse. What is the problem:

Hello @Joker,

Can you try to select the Arduino Nano 33 BLE instead of the Arduino Uno please?

If I try to compile an audio classification project by selecting the Arduino Uno board, I get this error:

However, if I select the Arduino Nano 33 BLE, it works fine:

Regards,

Louis

1 Like

Hello, sir. I want to express my gratitude to you. With your help, I have solved this problem now, and the project I created can work normally. Thank you very much for your help.

4 Likes