Calling Voice recognition with its name

hi folks !

i designed voice recognition for controlling home lights and tv.my codes run smoothly. After every command she tells me what is she doing with mp3player module. it is fine ,

But ;

i want to give a name to my arduino like "Siri" of Apple.

it must always wait for her name first. After the name called, it must wait for my commands for 5 seconds (like Siri). After 5 seconds it must return to the standby for the name again.

Thanks everyone for the replies !

vr_sample_control_led.ino (5.51 KB)

Did you write that code ?

If so then you will know how to make the system recognise a particular word, such as a name. Then, using millis() for timing it can continue to listen for commands for a period before going back to listening for its name. See Using millis() for timing. A beginners guide, Several things at the same time and look at the BlinkWithoutDelay example in the IDE.

NOTE : because you did not use code tags when posting your program it has been mangled.

Delta_G:
That is ridiculous. How will she hear her name if she isn't listening? She must be actively listening and looking for her name if you want that sort of behavior.

no, it isn't... OP wants the device to not respond unless the name preceeds the commands, just like Google Home or Alexa or Siri works.

what OP should try is a simple state machine (pseudo code):

const char* KEYWORD = "Arduino";
uint32_t listeningMillis;
const uint32_t TIMEOUT = 15* 1000UL;

enum ListeningState {
  WAITING_FOR_KEYWORD,
  ACTIVE_LISTENING,
} listeningState = WAITING_FOR_KEYWORD;

void setup() {

}

void loop() {
  int ret = myVR.recognize(buf, 50);
  if (ret) {
    switch (listeningState) {
      case WAITING_FOR_KEYWORD:
        if (ret == KEYWORD) {
          listeningState = ACTIVE_LISTENING;
          listeningMillis = millis();
        }
        break;
      case ACTIVE_LISTENING:
        // process ret here!!
        if (millis() - listeningMillis > TIMEOUT)
        {
          listeningState = WAITING_FOR_KEYWORD;
        }
        break;
    }
  }
}

Delta_G:
No that's not what he said. He didn't say he just didn't want it to respond. He said he didn't want it to listen. It can't hear it's name if it doesn't actively listening for its name.

No kidding...

it is very clear Delta_G ;

"it must always wait for her name first. After the name called, it must wait for the commands for 5 seconds (like Siri). after 5 seconds it must return to standby again. "

if you used a vr before,you have to know that vr module get confused sometimes when the programmer speak. Naming is the best and the naturel solution of that bug

Thanks BulldogLowell. I'm gonna try that now

BulldogLowell:
no, it isn't... OP wants the device to not respond unless the name preceeds the commands, just like Google Home or Alexa or Siri works.

what OP should try is a simple state machine (pseudo code):

const char* KEYWORD = "Arduino";

uint32_t listeningMillis;
const uint32_t TIMEOUT = 15* 1000UL;

enum ListeningState {
  WAITING_FOR_KEYWORD,
  ACTIVE_LISTENING,
} listeningState = WAITING_FOR_KEYWORD;

void setup() {

}

void loop() {
  int ret = myVR.recognize(buf, 50);
  if (ret) {
    switch (listeningState) {
      case WAITING_FOR_KEYWORD:
        if (ret == KEYWORD) {
          listeningState = ACTIVE_LISTENING;
          listeningMillis = millis();
        }
        break;
      case ACTIVE_LISTENING:
        // process ret here!!
        if (millis() - listeningMillis > TIMEOUT)
        {
          listeningState = WAITING_FOR_KEYWORD;
        }
        break;
    }
  }
}

BulldogLowell:
no, it isn't... OP wants the device to not respond unless the name preceeds the commands, just like Google Home or Alexa or Siri works.

what OP should try is a simple state machine (pseudo code):

const char* KEYWORD = "Arduino";

uint32_t listeningMillis;
const uint32_t TIMEOUT = 15* 1000UL;

enum ListeningState {
  WAITING_FOR_KEYWORD,
  ACTIVE_LISTENING,
} listeningState = WAITING_FOR_KEYWORD;

void setup() {

}

void loop() {
  int ret = myVR.recognize(buf, 50);
  if (ret) {
    switch (listeningState) {
      case WAITING_FOR_KEYWORD:
        if (ret == KEYWORD) {
          listeningState = ACTIVE_LISTENING;
          listeningMillis = millis();
        }
        break;
      case ACTIVE_LISTENING:
        // process ret here!!
        if (millis() - listeningMillis > TIMEOUT)
        {
          listeningState = WAITING_FOR_KEYWORD;
        }
        break;
    }
  }
}

i tried for 1 hour but failed.i uploaded my code correctly. can you update it please ? thanks !

Delta_G:
How did it fail? How should we know what to change if you don't tell us what it did or didn't do that was wrong? You do realize that what he posted was just an example to show you the concept. It wasn't supposed to do anything on its own. You were supposed to learn from it and write something similar for your code.

Delta_G thanks for your comments but i am one step behind finishing my script. Please write to other posts. They may need your help. Thanks

UKHeliBob:
Did you write that code ?

If so then you will know how to make the system recognise a particular word, such as a name. Then, using millis() for timing it can continue to listen for commands for a period before going back to listening for its name. See Using millis() for timing. A beginners guide, Several things at the same time and look at the BlinkWithoutDelay example in the IDE.

NOTE : because you did not use code tags when posting your program it has been mangled.

i updated my code. can you check it again please ? Thanks

egeunilicem:
i updated my code. can you check it again please ? Thanks

I don't know your library, but your code may end up looking like this:

void loop() {
  int ret = myVR.recognize(buf, 50);
  if (ret) {
    switch (listeningState) {
      case WAITING_FOR_KEYWORD:
        switch (buf[1]) {
          case keyword:
            listeningState = ACTIVE_LISTENING;
            listeningMillis = millis();
            break;
          default:
            //
            break;
        }
        break;
      case ACTIVE_LISTENING:
        processCommand(ret);
        if (millis() - listeningMillis > TIMEOUT)
        {
          listeningState = WAITING_FOR_KEYWORD;
        }
        break;
    }
  }
}

void processCommand(int ret) {
  if (ret > 0) {
    listeningMillis = millis();
    switch (buf[1])
    {
      case los:
        myDFPlayer.play(8);  //Play the 8 mp3
        delay(5000);
        myDFPlayer.play(9);  //Play the 9 mp3
        delay(1);
        /** turn on LED */
        digitalWrite(led, LOW);
        digitalWrite(spot, HIGH);
        break;
      case aydinlik:
        myDFPlayer.play(7);  //Play the 7 mp3
        delay(5000);
        /** turn off LED*/
        digitalWrite(spot, LOW);
        digitalWrite(led, LOW);
        break;
      case tv:
        myDFPlayer.play(6);  //Play the 6 mp3
        delay(3000);
        for (int i = 0; i < 3; i++) {
          irsend.sendNEC(0xE0E040BF, 32);
          delay(40);
        }
        break;
      case sesiac:
        myDFPlayer.play(5);  //Play the 5 mp3
        delay(1);
        for (int i = 0; i < 12; i++) {
          irsend.sendNEC(0xE0E0E01F, 32);
          delay(40);
        }
        break;
      case kanal:
        myDFPlayer.play(4);  //Play the 4 mp3
        delay(1);
        for (int i = 0; i < 3; i++) {
          irsend.sendNEC(0xE0E048B7, 32);
          delay(40);
        }
        break;
      case acilsusam:
        myDFPlayer.play(2);  //Play the 2 mp3
        delay(5000);
        digitalWrite(spot, LOW);
        digitalWrite(led, LOW);
        for (int i = 0; i < 3; i++) {
          irsend.sendNEC(0xE0E040BF, 32);
          delay(40);
        }
        break;
      case adios:
        myDFPlayer.play(1);  //Play the 1 mp3
        delay(8000);
        digitalWrite(spot, HIGH);
        digitalWrite(led, HIGH);
        for (int i = 0; i < 3; i++) {
          irsend.sendNEC(0xE0E040BF, 32);
          delay(40);
        }
        break;
      default:
        Serial.println("func problem");
        break;
    }

    printVR(buf);
  }
}

BulldogLowell:
I don't know your library, but your code may end up looking like this:

void loop() {

int ret = myVR.recognize(buf, 50);
  if (ret) {
    switch (listeningState) {
      case WAITING_FOR_KEYWORD:
        switch (buf[1]) {
          case keyword:
            listeningState = ACTIVE_LISTENING;
            listeningMillis = millis();
            break;
          default:
            //
            break;
        }
        break;
      case ACTIVE_LISTENING:
        processCommand(ret);
        if (millis() - listeningMillis > TIMEOUT)
        {
          listeningState = WAITING_FOR_KEYWORD;
        }
        break;
    }
  }
}

void processCommand(int ret) {
  if (ret > 0) {
    listeningMillis = millis();
    switch (buf[1])
    {
      case los:
        myDFPlayer.play(8);  //Play the 8 mp3
        delay(5000);
        myDFPlayer.play(9);  //Play the 9 mp3
        delay(1);
        /** turn on LED /
        digitalWrite(led, LOW);
        digitalWrite(spot, HIGH);
        break;
      case aydinlik:
        myDFPlayer.play(7);  //Play the 7 mp3
        delay(5000);
        /
* turn off LED*/
        digitalWrite(spot, LOW);
        digitalWrite(led, LOW);
        break;
      case tv:
        myDFPlayer.play(6);  //Play the 6 mp3
        delay(3000);
        for (int i = 0; i < 3; i++) {
          irsend.sendNEC(0xE0E040BF, 32);
          delay(40);
        }
        break;
      case sesiac:
        myDFPlayer.play(5);  //Play the 5 mp3
        delay(1);
        for (int i = 0; i < 12; i++) {
          irsend.sendNEC(0xE0E0E01F, 32);
          delay(40);
        }
        break;
      case kanal:
        myDFPlayer.play(4);  //Play the 4 mp3
        delay(1);
        for (int i = 0; i < 3; i++) {
          irsend.sendNEC(0xE0E048B7, 32);
          delay(40);
        }
        break;
      case acilsusam:
        myDFPlayer.play(2);  //Play the 2 mp3
        delay(5000);
        digitalWrite(spot, LOW);
        digitalWrite(led, LOW);
        for (int i = 0; i < 3; i++) {
          irsend.sendNEC(0xE0E040BF, 32);
          delay(40);
        }
        break;
      case adios:
        myDFPlayer.play(1);  //Play the 1 mp3
        delay(8000);
        digitalWrite(spot, HIGH);
        digitalWrite(led, HIGH);
        for (int i = 0; i < 3; i++) {
          irsend.sendNEC(0xE0E040BF, 32);
          delay(40);
        }
        break;
      default:
        Serial.println("func problem");
        break;
    }

printVR(buf);
  }
}

worked. u r Elvis the king