def __init__(self): MODELDIR = "cmusphinx-code/pocketsphinx/model" config = Decoder.default_config() config.set_string('-hmm', path.join(MODELDIR, 'hmm/en_US/hub4wsj_sc_8k_adapt')) config.set_string('-lm', path.join(MODELDIR, 'lm/en_US/num_adapt.dmp')) config.set_string('-dict', path.join(MODELDIR, 'lm/en_US/num_adapt.dic')) self.decoder = Decoder(config) self.speechCue = AudioFeedback()
def provideGuidance(self): reachDestination = False calculatePath = True sayPathRoute = True speaker = AudioFeedback() while reachDestination == False: if calculatePath == True: path = myMap.SSSP(startNode, destNode) calculatePath = False if sayPathRoute: routeSpeechInfo = '' for i in range(len(path)): #print in reverse order print path[len(path) - 1 - i], mapinfo['map'][path[len(path) - 1 - i] - 1]['nodeName'] if i == 0: firstNode = 'the path route starts from %s ' % mapinfo[ 'map'][path[len(path) - 1 - i] - 1]['nodeName'] routeSpeechInfo = routeSpeechInfo + firstNode else: nextNode = 'followed by %s ' % mapinfo['map'][ path[len(path) - 1 - i] - 1]['nodeName'] routeSpeechInfo = routeSpeechInfo + nextNode routeSpeechInfo = routeSpeechInfo + '\n' speaker.threadedFeedback(routeSpeechInfo) sayPathRoute = False reachCheckPoint = True currentCheckPoint = path.pop() pos_x = mapinfo['map'][currentCheckPoint - 1]['x'] pos_y = mapinfo['map'][currentCheckPoint - 1]['y'] print "pos_x = ", pos_x, " pos_y = ", pos_y while path: if reachCheckPoint: reachCheckPoint = False nextCheckPoint = path.pop() if not path: reachDestination = True print nextCheckPoint, mapinfo['map'][nextCheckPoint - 1]['nodeName'] try: #start_time = time.time() #timing_interval = 1 #count_time = 0 while not reachCheckPoint: #time.sleep(start_time + count_time * timing_interval - time.time()) reachCheckPoint, pos_x, pos_y, detourCheckPoint = self.provideDirections( nextCheckPoint, currentCheckPoint, pos_x, pos_y, speaker) if reachCheckPoint: currentCheckPoint = nextCheckPoint if detourCheckPoint: print "detour!" calculatePath = True path[:] = [] sayPathRoute = True break #count_time = count_time + 1 except Exception: print "INVALID DISTANCE!" if ((not path) and (reachDestination == True)): sayDestinationReached = 'destination reached!\n' speaker.threadedFeedback(sayDestinationReached)