def runMain(): # First, we import our devices from our configuration file. These will be split into two different groups, those # controlled by Philips Hue and those controlled by Insteon. configuration = Configuration() config = configuration.loadConfig() hueDevices = {} insteonDevices = {} for device in config['devices']['hue']: hueDevices[device] = config['devices']['hue'][device] for device in config['devices']['insteon']: insteonDevices[device] = config['devices']['insteon'][device] insteon = Insteon() hue = Hue() roomba = Roomba() # Now we set up the voice recognition using Pocketsphinx from CMU Sphinx. pocketSphinxListener = PocketSphinxListener() # We want to run forever, or until the user presses control-c, whichever comes first. while True: try: command = pocketSphinxListener.getCommand().lower() command = command.replace('the', '') if command.startswith('turn'): onOrOff = command.split()[1] deviceName = ''.join(command.split()[2:]) if deviceName in hueDevices: deviceId = hueDevices[deviceName]['deviceID'] hue.turn(deviceId=deviceId, onOrOff=onOrOff) if deviceName in insteonDevices: deviceId = insteonDevices[deviceName]['deviceID'] insteon.turn(deviceId=deviceId, onOrOff=onOrOff) if deviceName == 'roomba': roomba.turn(onOrOff) elif command.startswith('roomba'): action = ' '.join(command.split()[1:]) if action == 'clean': roomba.clean() if action == 'go home': roomba.goHome() # This will allow us to be good cooperators and sleep for a second. # This will give the other greenlets which we have created for talking # to the Hue and Insteon hubs a chance to run. gevent.sleep(1) except (KeyboardInterrupt, SystemExit): print 'People sometimes make mistakes, Goodbye.' sys.exit() except Exception as e: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback, limit=2, file=sys.stdout) sys.exit()
def runMain(): # Now we set up the voice recognition using Pocketsphinx from CMU Sphinx. # We can set debug for the listener here to see messages directly from Pocketsphinx pocketSphinxListener = PocketSphinxListener(debug=False) while True: try: # We can set debug here to see what the decoder thinks we are saying as we say it command = pocketSphinxListener.getCommand(debug=True).lower() # Exit when control-c is pressed except (KeyboardInterrupt, SystemExit): print 'People sometimes make mistakes, Goodbye.' sys.exit()
def runMain(): # Now we set up the voice recognition using Pocketsphinx from CMU Sphinx. # We can set debug for the listener here to see messages directly from Pocketsphinx pocketSphinxListener = PocketSphinxListener(debug=False) while True: try: # We can set debug here to see what the decoder thinks we are saying as we say it command = pocketSphinxListener.getCommand(debug=False).lower() # Exit when control-c is pressed except (KeyboardInterrupt, SystemExit): print 'People sometimes make mistakes, Goodbye.' sys.exit()
def runMyMain(): # Now we set up the voice recognition using Pocketsphinx from CMU Sphinx. pocketSphinxListener = PocketSphinxListener() # We want to run forever, or until the user presses control-c, whichever comes first. while True: try: command = pocketSphinxListener.getCommand().lower() # for a grammar that looks like TURN <state> <device> # if command.startswith('turn'): # onOrOff = command.split()[1] # deviceName = ''.join(command.split()[2:]) # do something # for a grammar that looks like ROOMBA <action> # elif command.startswith('roomba'): # action = ' '.join(command.split()[1:]) # if action == 'clean': # roomba.clean() # if action == 'go home': # roomba.goHome() # speak what was heard filename = '_tmp.txt' file = open(filename, 'w') file.write(command) file.close() subprocess.call('espeak -v en-scottish -k5 -s150 -f ' + filename, shell=True) subprocess.call('rm -f ' + filename, shell=True) # This will allow us to be good cooperators and sleep for a second. print "I'm thinking now" time.sleep(1) except (KeyboardInterrupt, SystemExit): print 'Goodbye.' sys.exit() except Exception as e: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback, limit=2, file=sys.stdout) sys.exit()
def runMain(): pocketSphinxListener = PocketSphinxListener() while True: try: command = pocketSphinxListener.getCommand().lower() print "command: " + command if "time" in command: getTime() elif "temperature" in command: if "shed" in command: getTemperature("shed") if "lab" in command: getTemperature("lab") elif "door" in command: if "shed" in command: getContact("shed") if "lab" in command: getContact("lab") elif "radio" in command: if "turn on" in command: turnOnRadio() if "turn off" in command: turnOffRadio() elif "weather" in command: getWeather() elif "who are you" in command: whoAmI() elif "thank you" in command: thankYou() except (KeyboardInterrupt, SystemExit): print 'People sometimes make mistakes, Goodbye.' sys.exit() except Exception as e: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback, limit=2, file=sys.stdout) sys.exit()
def runMain(): # Now we set up the voice recognition using Pocketsphinx from CMU Sphinx. # We can set debug for the listener here to see messages directly from Pocketsphinx pocketSphinxListener = PocketSphinxListener(debug=False) on_off = "off" while True: try: # We can set debug here to see what the decoder thinks we are saying as we say it command = pocketSphinxListener.getCommand(debug=False).lower() if command == "marcy turn on tv": if on_off == "off": print("I am now turning on the TV.") play_wav("tv_on.wav") on_off = "on" else: print("I cannot perform this task. The TV is already on.") play_wav("cant_turn_on.wav") elif command == "marcy turn off tv": if on_off == "on": print("I am now turning on the TV.") on_off = "off" play_wav("tv_off.wav") elif command == "marcy poop": print("I cannot perform this task, I do not consume food.") elif command == "hello marcy": print("Hello. What would you like me to do?") elif "go left" in command or "go right" in command or "go up" in command or "go down" in command: print("Going.") elif command == "select": print("Selected.") # Exit when control-c is pressed except (KeyboardInterrupt, SystemExit): print 'People sometimes make mistakes, Goodbye.' sys.exit()
def runMain(): # First, we import our devices from our configuration file. These will be split into two different groups, those # controlled by Philips Hue and those controlled by Insteon. # configuration = Configuration() # config = configuration.loadConfig() # Now we set up the voice recognition using Pocketsphinx from CMU Sphinx. pocketSphinxListener = PocketSphinxListener() # We want to run forever, or until the user presses control-c, whichever comes first. while True: try: command = pocketSphinxListener.getCommand().lower() # can just ignore the word marty in the sentence. similarly for 'your' command = command.replace('marty', '') command = command.replace('your', '') cwords = command.split() if command.startswith('walk') or command.startswith('turn'): direction = cwords[1] if len(cwords) > 2: numsteps = nums[cwords[2]] else: numsteps = 1 if cwords[0] == 'walk': if direction.startswith('forward'): distance = STEPLENGTH else: distance = 0 - STEPLENGTH turn = 0 else: if direction == 'left': turn = TURNAMOUNT else: turn = 0 - TURNAMOUNT distance = 0 marty.walk(numsteps, distance, turn, 15) sleep((numsteps * 1.5) + 0.2) elif cwords[0] == 'kick': if cwords[1] == 'left': marty.kickLeft() else: marty.kickRight() sleep(2) elif cwords[0] == 'dance': marty.celebrate() sleep(4) elif cwords[0] == 'hello': marty.hello() sleep(1.0) for i in range(3): marty.arms(200, 0) sleep(0.5) marty.arms(75, 0) sleep(0.5) marty.arms(0, 0) sleep(2) elif cwords[2] == 'arm': if cwords[0] == 'raise': armangle = ARMANGLE else: armangle = 0 # this is not ideal as it'll put the other arm down when one raises. and in practice will lower both arms... if cwords[1] == 'left': leftangle = ARMANGLE rightangle = 0 else: leftangle = 0 rightangle = 0 - ARMANGLE marty.arms(leftangle, rightangle) # This will allow us to be good cooperators and sleep for a second. # This will give the other greenlets which we have created for talking # to the Hue and Insteon hubs a chance to run. gevent.sleep(1) except (KeyboardInterrupt, SystemExit): print 'People sometimes make mistakes, Goodbye.' sys.exit() except Exception as e: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback, limit=2, file=sys.stdout) command = ''