Markus

9 years 9 months ago

from java.lang import String
from org.myrobotlab.service import Speech
from org.myrobotlab.service import Sphinx
from org.myrobotlab.service import Runtime
 
 
 
first = 0
second = 0
number = (first+second)
 
# create ear and mouth
ear = Runtime.createAndStart("ear","Sphinx")
mouth = Runtime.createAndStart("mouth","Speech")
 
# start listening for the words we are interested in
ear.startListening("what is that | one | two | three | four | five | plus one | plus two | plus three | plus four | plus five | start counting")
 
# set up a message route from the ear --to--> python method "heard"
ear.addListener("recognized", python.getName(), "heard"); 
 
def heard():
      data = msg_ear_recognized.data[0]
 
      
      if (data == "one"):
          global first
          first += 1
          print(first)
 
      if (data == "two"):
          global first
          first += 2
          print(first)
 
      if (data == "three"):
          global first
          first += 3
          print(first)
 
      if (data == "four"):
          global first
          first += 4
          print(first)
 
      if (data == "five"):
          global first
          first += 5
          print(first)
 
      if (data == "plus one"):
          global second
          second += 1
          print(second)
 
      if (data == "plus two"):
          global second
          second += 2
          print(second)
 
      if (data == "plus three"):
          global second
          second += 3
          print(second)
 
      if (data == "plus four"):
          global second
          second += 4
          print(second)
 
      if (data == "plus five"):
          global second
          second += 5
          print(second)
 
      if (data == "what is that"):
          global number
          number = (first+second)
          mouth.speak(str(first) + "plus" + str(second) + "is" + str(number))
          global first
          first = (first + second)
          global second
          second = 0
 
      if (data == "start counting"):
          global first
          first = 0
          global second
          second = 0
          print("starting from 0")
 
 
ear.attach("mouth")
 

GroG

9 years 9 months ago

Ahahaha !  Nice Markus !

Who knew InMoov was so smart ! 

Now if Sphinx could recognize "free form" text ! ... so you wouldn't have to do this - 
ear.startListening("what is that | one | two | three | four | five | plus one | plus two | plus three | plus four | plus five | start counting")

excellent work !

Oh,  bhouston and I got Service events to call python methods ..

for example there is a Python powerUp function called when the powerUp event  happens in InMoov ..
this might add to to power and complexity of InMoov...

It would be nice if someone came up with a FSM (finite state machine) diagram of possible states for InMoov
 

dwilli9013

9 years 9 months ago

Nice script Markus. I always enjoy your scripts.

You are all updated to InMoov 2.0 now arent you?

I really enjoy your work I can always count on an interesting twist with you scripts. 

Keep em coming. And thanks for the sharing of your work.

dwilli9013