20. 1Sheeld Voice recognition

Mål: Att småprata med en trevlig dam och kontrollera en servo med hjälp av röstigenkänning och talsyntes.

Teori: Prata i 1Sheeld appen. Talet analyseras och modifieras till text som skickas via bluetooth till Arduino. Arduino koden jämför texten med givna meningar. Om det matchar, utförs blocket i en if – sats. T.ex. vrid en servo och talsyntesen svarar “servo turned left”.

Koppling: Koppla en miniservo till din Arduino precis som i arbete 19


 

Arduino koden

#define CUSTOM_SETTINGS
#define INCLUDE_TEXT_TO_SPEECH_SHIELD
#define INCLUDE_VOICE_RECOGNIZER_SHIELD

#include <OneSheeld.h>
#include <Servo.h>

Servo myservo;
const char firstCommand[]="good morning darling";
const char secondCommand[]="are you ready to play";
const char thirdCommand[]="turn left";
const char fourthCommand[]="turn right";

void setup()
{
  OneSheeld.begin();
  myservo.attach(10); 
}

void loop()
{
   
   if(VoiceRecognition.isNewCommandReceived())
   {
     if(!strcmp(firstCommand,VoiceRecognition.getLastCommand()))
     {
       TextToSpeech.say("good morning handsome");
     }
     else if(!strcmp(secondCommand,VoiceRecognition.getLastCommand()))
     {
       TextToSpeech.say("i am ready lets go");
     }
     else if(!strcmp(thirdCommand,VoiceRecognition.getLastCommand()))
     {
       myservo.write(10);
       TextToSpeech.say("servo turned left");
     }
     else if(!strcmp(fourthCommand,VoiceRecognition.getLastCommand()))
     {
       myservo.write(170);
       TextToSpeech.say("servo turned right");
     }
     else
     {
      
     }
   }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s