// include the speech recognition library
#include <SpeechRecognition.h>
// create an instance of the speech recognition module
SpeechRecognition speech;
// define the word "hello" as a command
#define CMD_HELLO 0
// define the pin for the speech recognition module
#define SR_PIN 2
void setup() {
// initialize serial communication
Serial.begin(9600);
// initialize the speech recognition module
speech.init(SR_PIN);
// train the module to recognize the word "hello"
speech.train(CMD_HELLO, "hello");
}
void loop() {
// check if the module has recognized a word
if (speech.available()) {
// get the command number of the recognized word
int command = speech.getCommand();
// check if the command is "hello"
if (command == CMD_HELLO) {
// print "hello" on the serial monitor
Serial.println("Hello");
}
}
}
--------------------------------------------------------
// include the speech recognition library
#include <SpeechRecognition.h>
// create an instance of the speech recognition module
SpeechRecognition speech;
// define the pin for the speech recognition module
#define SR_PIN 2
// define the maximum number of words to recognize
#define MAX_WORDS 10
// define an array of words to recognize
const char* words[MAX_WORDS] = {"hello", "world", "arduino", "bing", "code", "fun", "cool", "yes", "no", "bye"};
// define an array of command numbers for each word
int commands[MAX_WORDS] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
void setup() {
// initialize serial communication
Serial.begin(9600);
// initialize the speech recognition module
speech.init(SR_PIN);
// train the module to recognize the words in the array
for (int i = 0; i < MAX_WORDS; i++) {
speech.train(commands[i], words[i]);
}
}
void loop() {
// check if the module has recognized a word
if (speech.available()) {
// get the command number of the recognized word
int command = speech.getCommand();
// find the index of the command in the array
int index = -1;
for (int i = 0; i < MAX_WORDS; i++) {
if (command == commands[i]) {
index = i;
break;
}
}
// check if the index is valid
if (index != -1) {
// print the corresponding word on the serial monitor
Serial.println(words[index]);
}
}
}
-------------------------------------------------------












Comments
Post a Comment