Voice recognition may not work (voice_control_led_en)



  • Voice_control_led_en is running on Maixduino board. Since there is no LED on the Maixduino board, a GPIO definition has been added.
    #define LED_RED 12
    #define LED_BLUE 13
    #define LED_GREEN 14
    Speech recognition works correctly with the original sketch.
    I am a Maixduino board, so I corrected the color display on the LCD instead of the LED.

    Question 1.
    Character display on the LCD is slow. When DMA interrupt for microphone input is disabled, it operates at normal speed.
    Since I am not in speech recognition, I would like you to display it at normal speed.

    Question 2.
    If you make corrections, voice recognition may not respond. The phenomenon is not constant.

    1. Does not respond after displaying speeking ...
    2. Only reacts the first time.
    3. Response is poor.
      The phenomenon changes even when a printf for debugging is added.

    This is a sketch that I modified. This setting did not respond.
    If define LARGE_CHAR is enabled, it will react only the first time.
    Is my board broken? Since compile switches are not related to speech recognition, I think that any combination will work.

    #include "Maix_Speech_Recognition.h"
    #include "voice_model.h"
    #include "Sipeed_ST7789.h"
    #include "plic.h"
    #include "dmac.h"

    /--------------------------------------/
    //#define GPIO_EN
    //#define LARGE_CHAR
    //#define DISP_HIGH
    #define SPEEK_DISP_BLAK
    #define TEXT_COLOR
    /--------------------------------------/

    #ifdef GPIO_EN
    #define LED_RED 12
    #define LED_BLUE 13
    #define LED_GREEN 14
    #endif // GPIO_EN
    SPIClass spi_(SPI0); // MUST be SPI0 for Maix series on board LCD
    Sipeed_ST7789 lcd(320, 240, spi_);

    SpeechRecognizer rec;

    void setup()
    {
    #ifdef GPIO_EN
    pinMode(LED_RED, OUTPUT);
    pinMode(LED_BLUE, OUTPUT);
    pinMode(LED_GREEN, OUTPUT);
    #endif // GPIO_EN
    lcd.begin(15000000, COLOR_BLACK);
    #ifdef TEXT_COLOR
    lcd.setTextColor(COLOR_WHITE);
    #endif

    rec.begin();
    Serial.begin(115200);
    Serial.println("init model...");
    rec.addVoiceModel(0, 0, red_0, fram_num_red_0); 
    rec.addVoiceModel(0, 1, red_1, fram_num_red_1); 
    rec.addVoiceModel(0, 2, red_2, fram_num_red_2); 
    rec.addVoiceModel(0, 3, red_3, fram_num_red_3); 
    rec.addVoiceModel(1, 0, green_0, fram_num_green_0);     
    rec.addVoiceModel(1, 1, green_1, fram_num_green_1);     
    rec.addVoiceModel(1, 2, green_2, fram_num_green_2);     
    rec.addVoiceModel(1, 3, green_3, fram_num_green_3);     
    rec.addVoiceModel(2, 0, blue_0, fram_num_blue_0);   
    rec.addVoiceModel(2, 1, blue_1, fram_num_blue_1);   
    rec.addVoiceModel(2, 2, blue_2, fram_num_blue_2);   
    rec.addVoiceModel(2, 3, blue_3, fram_num_blue_3);   
    rec.addVoiceModel(3, 0, turnoff_0, fram_num_turnoff_0);  
    rec.addVoiceModel(3, 1, turnoff_1, fram_num_turnoff_1);  
    rec.addVoiceModel(3, 2, turnoff_2, fram_num_turnoff_2);  
    rec.addVoiceModel(3, 3, turnoff_3, fram_num_turnoff_3);  
    Serial.println("init model ok!");
    

    }
    void loop()
    {
    int res;

    #ifndef LARGE_CHAR
    lcd.setTextSize(1);
    #else
    lcd.setTextSize(2);
    #endif

    #ifdef DISP_HIGH
    plic_irq_disable((plic_irq_t)(IRQN_DMA0_INTERRUPT + DMAC_CHANNEL3));
    #endif
    lcd.setCursor(50, 110);
    lcd.println("speeking...");
    #ifdef DISP_HIGH
    plic_irq_enable((plic_irq_t)(IRQN_DMA0_INTERRUPT + DMAC_CHANNEL3));
    #endif
    delay(100);

    res = rec.recognize();
    Serial.printf("res : %d ", res);
    if (res > 0){
        switch (res)
        {
        case 1:
    		lcd.fillScreen(COLOR_RED);
    

    #ifdef TEXT_COLOR
    lcd.setTextColor(COLOR_RED);
    #endif
    #ifdef GPIO_EN
    digitalWrite(LED_RED, LOW); //power on red led
    digitalWrite(LED_GREEN, HIGH);
    digitalWrite(LED_BLUE, HIGH);
    #endif // GPIO_EN
    Serial.println("rec : red ");
    break;
    case 2:
    lcd.fillScreen(COLOR_GREEN);
    #ifdef TEXT_COLOR
    lcd.setTextColor(COLOR_GREEN);
    #endif
    #ifdef GPIO_EN
    digitalWrite(LED_GREEN, LOW); //power on green led
    digitalWrite(LED_RED, HIGH);
    digitalWrite(LED_BLUE, HIGH);
    #endif // GPIO_EN
    Serial.println("rec : green ");
    break;
    case 3:
    lcd.fillScreen(COLOR_BLUE);
    #ifdef TEXT_COLOR
    lcd.setTextColor(COLOR_BLUE);
    #endif
    #ifdef GPIO_EN
    digitalWrite(LED_BLUE, LOW); //power on blue led
    digitalWrite(LED_RED, HIGH);
    digitalWrite(LED_GREEN, HIGH);
    #endif // GPIO_EN
    Serial.println("rec : blue ");
    break;
    case 4:
    lcd.fillScreen(COLOR_BLACK);
    #ifdef TEXT_COLOR
    lcd.setTextColor(COLOR_WHITE);
    #endif
    #ifdef GPIO_EN
    digitalWrite(LED_RED, HIGH);
    digitalWrite(LED_GREEN, HIGH);
    digitalWrite(LED_BLUE, HIGH); //power off all leds
    #endif // GPIO_EN
    Serial.println("rec : turnoff ");
    default:
    break;
    }
    }else
    {
    Serial.println("recognize failed.");
    }
    delay(1000);

    #ifdef SPEEK_DISP_BLAK
    lcd.fillScreen(COLOR_BLACK);
    delay(100);
    #endif
    }