tia GroG

I want to create a script to hold a conversation with MRL. I want to say something to him and have him react verbally to my words, dependent on those words. 

 

GroG

10 years 8 months ago

mouth = Runtime.createAndStart("mouth","Speech")
ear = Runtime.createAndStart("ear","Sphinx")
 
# important to attach ear to mouth
# so it won't attempt to recognize its own speech
ear.attach(mouth)
 
mouth.speak("hello")
 
# create the grammar and start listening
ear.startListening("hello | what is your name | what are you | who made you | tell me a joke | tell me a riddle ")
 
# set up a message route from the ear --to--> python method "heard"
ear.addListener("recognized", python.name, "heard"); 
 
# this method is invoked when something is 
# recognized by the ear - in this case we
# have the mouth "talk back" the word it recognized
def heard():
      data = msg_ear_recognized.data[0]
      # mouth.speak("you said " + data)
      print "heard ", data
      if (data == "hello" or data == "hi"):
         mouth.speak("hello yourself")
      elif (data == "tell me a joke" or data == "tell me a riddle"):
         mouth.speak("there once was a man from nantucket")
 

 

wkinne

10 years 8 months ago

 
mouth = Runtime.createAndStart("mouth","Speech")
ear = Runtime.createAndStart("ear","Sphinx")
 
# important to attach ear to mouth
# so it won't attempt to recognize its own speech
ear.attach(mouth)
 
mouth.speak("hello")
 
# create the grammar and start listening
ear.startListening("hello | what is your name | what are you | who made you | dog | really | does this work | tell me a joke | dog| tell me a riddle ")
 
# set up a message route from the ear --to--> python method "heard"
ear.addListener("recognized", python.name, "heard"); 
 
# this method is invoked when something is 
# recognized by the ear - in this case we
# have the mouth "talk back" the word it recognized
def heard():
      data = msg_ear_recognized.data[0]
      # mouth.speak("you said " + data)
      print "heard ", data
      if (data == "hello" or data == "hi"):
         mouth.speak("hello yourself")
      elif (data == "tell me a joke" or data == "tell me a riddle"):
         mouth.speak("there once was a man from nantucket")
      elif (data == "what are you"):
         mouth.speak("I am Inmoov an open sorce robot you can build")
      elif (data == "does this work"):
         mouth.speak("wow it works")
 
# here is where I get crazy
 
 
      elif (data =="dog"):
         ear.releaseService()
         ear.startListening("cat | rock | stone| book")
         ear.addListener("recognized", python.name, "heard");  
         def heard():
               data = msg_ear_recognized.data[0]
               print "heard ", data
               if (data == "cat"):
                  mouth.speak("cats are fun")
               elif (data == "rock"):
                  mouth.speak("rocks are hard")
               elif (data == "stone"):
                  mouth.speak("stone cold")
               elif (data == "book"):
                  mouth.speak("time to read")
 

wkinne

10 years 8 months ago

ear.releaseService()
ear2 = Runtime.createAndStart("ear2","Sphinx")

GroGyou release it - you can't use it again .. you need to create a new one