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 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(): # 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 = ''