loading

As a grade 11 student, I spent 4 weeks learning some basics about programming and computer science in University of Califonia, Berkeley. One of my dreams has always been to make a roboter talk, so I talked to my professor Gerald Friedland and he suggested to use and Arduino in combination with a MOVI speech dialog board. The task is then to translate AIML into the Arduino language to control MOVI. It turns out, all of this isn't as hard as you might think. So I decided to create and Instructable for it

In this Introduction, I will first help you to setup the basic environment and list the necessary hardware. Then I will provide links to basic instructions for Arduino and AIML. The Instructable itself will then focus on show to translate a given AIML script to Arduino (with MOVI library).

Step 1: Step 1: Necessary Environment and Hardware

1. MOVI board(http://www.audeme.com/movi.html)

2.Arduino IDE(https://www.arduino.cc/en/Main/Software)

3.AIML basic setting(http://www.tutorialspoint.com/aiml/aiml_environmen...)

Here is my step of playing with them:

1.I first learn basic language of Arduino(quite clear, similiar to C i guess)

2.then I try to understand MOVI's special function by the example provided by its zip.

3. I next turn to basic tag of AIML

4. at last i try to translate AIML to arduino(actually it's only for basic tags, the real AIML is out of my scale lol)

Step 2: Step 2: Getting Started With Arduino Language

This Link is for Arduino Reference.

https://www.arduino.cc/en/Reference/HomePage

I think learning the first 5 lines in Structures, the data types, Functions and operators are enough to both understand and write basic MOVI.

Step 3: Step 3 : Getting Started With AIML

AIML is Artificial Intelligence Markup Language.

For this part, my goal is to understand them at least, write some simple dialogues at most.

here is the link of AIML tutorials.(http://www.tutorialspoint.com/aiml/index.htm)

About the program ab(read the environmet setup part and you will see this), i want to add something about it.

I by the way learned commend prompt in order to 100% follow the tutorials(http://www.bleepingcomputer.com/tutorials/windows-...). If you are a beginner who want to study computer science, i stronly recommend you to do so too.

Step 4: Step 4 I Will Put My Translation Tag by Tag

Actually, our original goal is to write a automatic translator from AIML to Arduino by JAVA. Like the example i linked, this program will read AIML and then print relevant MOVI language. Some part of MOVI is all the same(headers, setup()) So we first print the generic part. But i found it too diffcult to do so, so here i will offer manual translation of the function i wrote in JAVA and in Arduino.

Step 5: Step 5: for Data Structure

I created a hashmap for the class patternTemplate which contain two arraylists (AIML's pattern and template). They are merely created for clearer explanation of the following tag translation.

I tried to make

1.the arraylist Pattern correspond to the AIML's Pattern and the MOVI's addSentence function

2.the arraylist Template corespond to the AIML's Template and the MOVI's answer

3. the Integer parameter correspond to the MOVI's recognizer.poll().

ps: it is not necesary in arduino programs, so if you are not interested in automatic translation, it is ok to skip.

Step 6: Random Tag

this one is easy.

User inputs a specific sentence and then computer return a random sentence.

In arduino, i first created a StringArray for all the Template sentence. and then use math.random to creat a random int from 0 to the size of array.

JAVA version:

<p>public static String randomLoop(int index)<br>	{
		String begin="signed int res=recognizer.poll();/n"+
			   "if (res=="+index+") {\n"
			   +"	int ran=random(0,"+patterntemplateindex.get(index).template.size()+");\n" 
			   +"	String sentences[]={\n";
		String middle="";
		for (int i=0;i<patterntemplateindex.get(index).template.size();i++) {</p><p>			middle=middle+"\""+patterntemplateindex.get(index).template.get(i)+"\",\n";
		}   
	    String end="	};"
			   +"   recognizer.say(sentences[ran]);\n"
			   +"}";
	    return begin+middle+end;
	}</p>

Arduino version:

<p>#include "MOVIShield.h"     // Include MOVI library, needs to be *before* the next #include</p><p>#ifdef ARDUINO_ARCH_AVR
#include  // This is nice and flexible but only supported on AVR architecture, other boards need to use Serial1 
#endif</p><p>MOVI recognizer(true);            // Get a MOVI object, true enables serial monitor interface, rx and tx can be passed as parameters for alternate communication pins on AVR architecture</p><p>void setup() {
   recognizer.init();   
   recognizer.callSign("Arduino");
   recognizer.addSentence(F("hi"));
   recognizer.train(); 
}</p><p>void loop() {
   signed int res = recognizer.poll(); 
   int ran= random(0,1);
   if(res==1){
    if(ran==1){
    recognizer.say("hello");
   }
   if(ran==0){
    recognizer.say("what's up");
   }
   }
  // put your main code here, to run repeatedly:</p><p>}</p>

Step 7: That Tag

That tag is for context conversation. It's like one user input for one specific cpu output(like "yes" for "I like movies too", "no" for "OK! I like movies.") Also, there need to be a signSentence ("do u like movies") to tell computer we now are going to tag. So i first add the sighSentence and then record each user possible input. After that, in arduino's loop part, i make the computer respond to the correspond sentence( like the intermiediate eliza example).

JAVA version:

public static String thatSetup(int index, String signSentence){
String Sentence="recognizer.addSentence(\""+signSentence+"\");"+"// sentence"+index+" \n"; for(String s: patterntemplateindex.get(index).pattern){ int sentenceOrder=index++; Sentence=Sentence+"recognizer.addSentence(\""+s+"\");"+"// sentence"+sentenceOrder+" \n"; } return Sentence; } public static String thatLoop(int index, String askingSentence){ String begin="signed int res=recognizer.poll();\n"+"if(res=="+index+")\n"+"{recognizer.ask(\""+askingSentence+"\");}\n"; String Responses="String sentences[]={\n"; for (int i=0;i<patterntemplateindex.get(index).template.size();i++) { " +index+"&&res<="+index+" responses[].length)\n"+"{recognizer.say(responses[res-"+(index+1)+"])}";="" return="" begin+responses+middle;="" }<="" p="">

Responses=Responses+"\""+patterntemplateindex.get(index).template.get(i)+"\",\n"; } String middle="if(res>"+index+"&&res<="+index+"Responses[].length)\n"+"{recognizer.say(Responses[res-"+(index+1)+"])}"; return begin+Responses+middle; }

Arduino version:

#include "MOVIShield.h" // Include MOVI library, needs to be *before* the next #include

#ifdef ARDUINO_ARCH_AVR #include // This is nice and flexible but only supported on AVR architecture, other boards need to use Serial1 #endif

const int led = 13; MOVI recognizer(true); int stage=0; int moviestage=1;// Get a MOVI object, true enables serial monitor interface, rx and tx can be passed as parameters for alternate communication pins on AVR architecture String[] Responses={ "oh i like movies too" "it's ok but i like movie" }; void setup() { recognizer.init(); // Initialize MOVI (waits for it to boot)

//* // Note: training can only be performed in setup(). // The training functions are "lazy" and only do something if there are changes. // They can be commented out to save memory and startup time once training has been performed. recognizer.callSign("Arduino"); // Train callsign Arduino (may take 20 seconds) recognizer.addSentence("let us discuss movies"); recognizer.addSentence("yes"); // Add sentence 1 recognizer.addSentence("no"); recognizer.train(); // Train (may take 20seconds) //*/

// recognizer.setThreshold(5); // uncomment and set to a higher value (valid range 2-95) if you have a problems due to a noisy environment. }

void loop() // run over and over { signed int res=recognizer.poll(); // Get result from MOVI, 0 denotes nothing happened, negative values denote events (see docs) if (res==1) { // Sentence 1. stage= moviestage; recognizer.ask("do u like comedy movies"); } if(stage==1&&res<4&&res>1){ recognizer.say(Responses[res-2]); stage=0; } // Do more ... }

Step 8: Set Get Tag

These two are really simple.

We can just create and use variables in Arduino(c language);

JAVA version:

<p>public static String set(String name, String value)<br>	{
		return ("String"+" "+name+"="+value+";");
	}
	
	public static String get(String name){
		return name;
	}</p> 

Arduino version:

variabletype variable name = value;

Step 9: Think Tag

actually, this one means nothing in Arduino. So i will just ignore it.

Step 10: Topic Condition Tag

I think both can be expressed in nested dialogues. I first create a state variable(normally an int )When user inputs a keyword or a keysentence, the computer will change the variable. Then comes to the if loop for that state.

Arduino version:

<p>MOVI recognizer(true);  <br>int stage=0;
int moviestage=1;// Get a MOVI object, true enables serial monitor interface, rx and tx can be passed as parameters for alternate communication pins on AVR architecture
String  Responses[]={
"oh i like movies too"
"it's ok but i like movie"
};
void setup()  
{
 
  recognizer.init();      // Initialize MOVI (waits for it to boot)</p><p>
  recognizer.callSign("Arduino"); // Train callsign Arduino (may take 20 seconds)
  recognizer.addSentence("let's discuss movies"); // Add sentence 1
  recognizer.addSentence("i like watch comedy");
  recognizer.addSentence("no");
  recognizer.train();                           // Train (may take 20seconds) 
  //*/
  recognizer.responses(false);
  recognizer.setThreshold(10);			// uncomment and set to a higher value (valid range 2-95) if you have a problems due to a noisy environment.
}</p><p>void loop() // run over and over
{
  signed int res=recognizer.poll(); // Get result from MOVI, 0 denotes nothing happened, negative values denote events (see docs)
  if (res==1) {                     // Sentence 1.
    stage= moviestage;
    recognizer.ask("OK");
  }
    if(stage==moviestage&&res==UNKNOWN_SENTENCE){
      recognizer.say("watching movies refreshes my mind");
      stage=0;
    }
    if(stage==moviestage&&res==2){
      recognizer.say("i like it too");
      stage=0;
    }
  
  // Do more ...
}</p>

In this example, we can see when user says let's discuss movies, the state changes and the program jumpss into the if loop for specific state, and then comes to following dialogues.

Step 11: Star Srai Tag

Those are all i can translate. For other tag i cannot do translation for some reasons. For star, the MOVI had a mechanism that it only can recognize and respond added words and sentences. So unknown words cannot be understood by merely saying it. For srai, I think it's only for programmers to save time. Besides, I cannot fine a way to implement this tag.

<p>Cool way to use an Arduino</p>

About This Instructable

440views

6favorites

License:

More by Liu Hongrui:How to translate AIML to Arduino in MOVI board 
Add instructable to: