Hello,
I've tryed to control a led on my arduino with voice based on the python exemples from MRL ( arduino ouput and talkback) , and nothing happen, i've just an error . But i just starting to learn python and i don't see the problem . Could someone help me ?
Or perhaps, all is wrong lol ! If it's the case , i'll retry from start ...
Thanks
This is the error returned by MRL :
1799832 [Thread-21] ERROR org.myrobotlab.logging.Logging - ------
SyntaxError: ("mismatched character '\\r' expecting '\\n'", ('<string>', 2, 42, '\n'))
at org.python.core.ParserFacade.fixParseError(ParserFacade.java:92)
at org.python.core.ParserFacade.parse(ParserFacade.java:201)
at org.python.core.Py.compile_flags(Py.java:1737)
at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:206)
at org.myrobotlab.service.Python$PIThread.run(Unknown Source)
------
And the code :
from java.lang import String
from org.myrobotlab.service import Speech
from org.myrobotlab.service import Sphinx
from org.myrobotlab.service import Runtime
from time import sleep
from org.myrobotlab.service import Arduino
# This is a little speech recognition script.
# Use "Led On" or "Led off" to control the led .
# The led is connected on pin 13 by default
# Change the value of the variable "ledPin" if you connect the led on an other pin
# Set the right com port in the variable " comPort " and the right arduino board
# set the pin for the led
ledPin = 13
# set the com port for the arduino
comPort = "COM4"
# create ear and mouth
ear = Runtime.createAndStart("ear","Sphinx")
mouth = Runtime.createAndStart("mouth","Speech")
# create an Arduino service named arduino
arduino = Runtime.createAndStart("arduino","Arduino")
# set the board type
arduino.setBoard("atmega328") # atmega168 | mega2560 | etc
# set serial device
arduino.setSerialDevice(comPort,57600,8,1,0)
sleep(1) # give it a second for the serial device to get ready
# update the gui with configuration changes
arduino.publishState()
# set the pinMode of led pin to output
arduino.pinMode(ledPin, Arduino.OUTPUT)
# start listening for the words we are interested in
ear.startListening("led on | led off ")
# set up a message route from the ear --to--> python method "heard"
ear.addListener("recognized", python.name, "heard", String().getClass());
# this method is invoked when something is
# recognized by the ear - in this case we
# actuate the led state and print the word recognized
def heard():
data = msg_ear_recognized.data[0]
print "heard ", data
if (data == "led on"):
print "Turning on the light"
arduino.digitalWrite(ledPin, Arduino.HIGH)
sleep(0.5) # sleep half a second
mouth.speak("The led is on ")
elif (data == "led off"):
print "Turning off the light"
arduino.digitalWrite(ledPin, Arduino.LOW)
sleep(0.5) # sleep half a second
mouth.speak("The led is on ")
# ... etc
# prevent infinite loop - this will suppress the
# recognition when speaking - default behavior
# when attaching an ear to a mouth :)
ear.attach("mouth")
Try with this one : in red
Try with this one : in red the part modified, and i removed the arduino.pinMode part (not necessary)
BEETLEJUICE !
Heh... You have Gremlins !!!
I use bug spray to get rid of them ;)
I copied your posted script and it works fine for me - albiet I my puter is not attached to an Arduino at the moment I can see the control messages go out.
The \r & \n makes me believe you didn't copy it all the way, have extra lines at the top.. Perhaps an extra space or tab ?
Python is VERY picky about formatting, sometimes you loose or add a little extra in the process of copying code from the web to the Python window...
Thx, Yes, this script work
Thx,
Yes, this script work well but on my desktop pc, not on my laptop ...
The gremlins are gone ( Note for myself: " not eat near my pc after midnight ") , but i've problem with my microphone, i'm looking for repair that