Ejemplo n.º 1
0
def getUserPermission(question):
	answer = 0
	saySomething(question,"en")
	response = getUsersVoice(2)
	if "yes" in response or "sure" in response or "okay" in response:
		answer = 1
	return answer
Ejemplo n.º 2
0
def saveImage():
	keepDiskSpaceFree(config.diskSpaceToReserve)
	time = datetime.datetime.now()
	filenameFull = config.filepath + config.filenamePrefix + "-%04d%02d%02d%02d%02d%02d" % (time.year, time.month, time.day, time.hour, time.minute, time.second)+ "." + config.fileType
	
	# save onto webserver
	filename = "/var/www/temp.jpg"
	subprocess.call("sudo raspistill -w "+ str(config.saveWidth) +" -h "+ str(config.saveHeight) + " -t 1 -n -vf -e " + config.fileType + " -q 15 -o %s" % filename, shell=True)
	print "Captured image: %s" % filename

	theSpeech = recognizeFace(filename,filenameFull)
	if len(theSpeech)>2:
		print theSpeech
		saySomething(theSpeech,"en")
		config.lookForFaces = 0
Ejemplo n.º 3
0
def saveImage():
    keepDiskSpaceFree(config.diskSpaceToReserve)
    time = datetime.datetime.now()
    filenameFull = config.filepath + config.filenamePrefix + "-%04d%02d%02d%02d%02d%02d" % (
        time.year, time.month, time.day, time.hour, time.minute,
        time.second) + "." + config.fileType

    # save onto webserver
    filename = "/var/www/temp.jpg"
    subprocess.call("sudo raspistill -w " + str(config.saveWidth) + " -h " +
                    str(config.saveHeight) + " -t 1 -n -vf -e " +
                    config.fileType + " -q 15 -o %s" % filename,
                    shell=True)
    print "Captured image: %s" % filename

    theSpeech = recognizeFace(filename, filenameFull)
    if len(theSpeech) > 2:
        print theSpeech
        saySomething(theSpeech, "en")
        config.lookForFaces = 0
Ejemplo n.º 4
0
def process_input(s, config):
    # check that recognizer and microphone arguments are appropriate type
    if not isinstance(config, Config.Config):
        raise TypeError("`recognizer` must be `Config` instance")

    s = s.lower()
    print("You entered %s" % (s))
    rsp = ""
    language = "en"
    if "spanish" in s:
        language = 'es'
        try:
            rsp = translateText(s, language)
        except:
            language = 'en'
            print("Unexpected error:", sys.exc_info()[0])
            rsp = 'Language services not accessible at this time'
    elif "german" in s:
        language = 'de'
        try:
            rsp = translateText(s, language)
        except:
            language = 'en'
            rsp = 'Language services not accessible at this time'
    elif "italian" in s:
        language = 'it'
        try:
            rsp = translateText(s, language)
        except:
            language = 'en'
            rsp = 'Language services not accessible at this time'
    elif "weather" in s:
        result = pywapi.get_weather_from_noaa('KRDU')  # RDU
        rsp = 'It is currently ' + str(int(float(result['temp_f']))) + ' degrees and ' + result['weather']
    elif ("i doing" in s) or (("to do" in s) and ("have" in s or "need" in s)):
        if "tomorrow" in s or "week" in s or "next" in s:
            rsp = getTasksToday(1)
            print("Got response " + rsp)
        else:
            rsp = getTasksToday(0)
            print("Got response " + rsp)
    elif "play" in s:
        rsp = playMusic(s)
    elif "music" in s:
        if "stop" in s:
            os.system('pkill vlc')
        elif "cancel" in s:
            os.system('pkill vlc')
        elif "kill" in s:
            os.system('pkill vlc')
        elif "close" in s:
            os.system('pkill vlc')
    elif "what is the" in s or "what's the" in s:
        rsp = wolframLookUp(s)
        if "Sorry" in rsp:
            rsp = getAIresponse(s)
    elif "how many" in s:
        rsp = wolframLookUp(s)
        if "Sorry" in rsp:
            rsp = getAIresponse(s)
    elif "tell me" in s:
        if "lot" in s:
            try:
                rsp = wikipediaLookUp(s, 2)
            except:
                try:
                    rsp = wikipediaLookUp(s, 2)
                except:
                    rsp = "I am sorry, I can not access that information."
        else:
            try:
                rsp = wikipediaLookUp(s, 2)
            except:
                try:
                    rsp = wikipediaLookUp(s, 2)
                except:
                    rsp = "I am sorry, I can not access that information."
    elif "do you know" in s:
        try:
            rsp = wikipediaLookUp(s, 2)
        except:
            try:
                rsp = wikipediaLookUp(s, 2)
            except:
                rsp = "I am sorry, I can not access that information."
    elif "who am i" in s or "who do you see" in s or "do you recognize" in s or "do you know me" in s:
        config.lookForFaces = 1
        rsp = "Let me see you and think."
        config.gettingStillImages = 0
    elif "off" in s and "light" in s:
        os.system("echo 'rf a1 off' | nc localhost 1099")
        os.system("echo 'rf c1 off' | nc localhost 1099")
        rsp = "Turning off the lights"
    elif "on" in s and "light" in s:
        os.system("echo 'rf a1 on' | nc localhost 1099")
        os.system("echo 'rf c1 on' | nc localhost 1099")
        rsp = "Turning on the lights"
    elif "who" in s:
        try:
            rsp = wikipediaLookUp(s, 1)
        except:
            try:
                rsp = wikipediaLookUp(s, 1)
            except:
                rsp = "I am sorry, I can not access that information."
    elif "shut" in s and "down" in s:
        saySomething("Shutting the computer down", "en")
        os.system("sudo shutdown now &")
    else:
        rsp = getAIresponse(s)
    print(rsp)

    pattern = re.compile("([^a-zA-Z\d\s:,.']|_)+")
    rsp = re.sub(pattern, '', rsp)
    print(rsp + " in " + language)
    saySomething(rsp, language)
Ejemplo n.º 5
0
def processInput(s):
	s = s.lower()
	print "You entered %s" % (s)
	rsp = ""
	language="en"
	if "spanish" in s:
		language = 'es'
		try:
			rsp = translateText(s,language)
		except:
			language = 'en'
			print "Unexpected error:", sys.exc_info()[0]
			rsp = 'Language services not accessible at this time'
	elif "german" in s:
		language = 'de'
		try:
			rsp = translateText(s,language)
		except:
			language = 'en'
			rsp = 'Language services not accessible at this time'
	elif "italian" in s:
		language = 'it'
		try:
			rsp = translateText(s,language)
		except:
			language = 'en'
			rsp = 'Language services not accessible at this time'
	elif "weather" in s:
		result = pywapi.get_weather_from_noaa('KRDU') # RDU
		rsp = 'It is currently ' + str(int(float(result['temp_f']))) + ' degrees and ' + result['weather']
	elif ("i doing" in s) or (("to do" in s) and ("have" in s or "need" in s)):
		if "tomorrow" in s or "week" in s or "next" in s:
			rsp = getTasksToday(1)
			print "Got response " + rsp
		else:
			rsp = getTasksToday(0)
			print "Got response " + rsp
	elif "play" in s:
		rsp = playMusic(s)
	elif "music" in s:
		if "stop" in s:
			os.system('pkill vlc')
		elif "cancel" in s:
			os.system('pkill vlc')
		elif "kill" in s:
			os.system('pkill vlc')
		elif "close" in s:
			os.system('pkill vlc')
	elif "what is the" in s or "what's the" in s:	
		rsp = wolframLookUp(s)
		if "Sorry" in rsp:
			rsp = getAIresponse(s)
	elif "how many" in s:
		rsp = wolframLookUp(s)
		if "Sorry" in rsp:
			rsp = getAIresponse(s)
	elif "tell me" in s:
		if "lot" in s:
			try:
				rsp = wikipediaLookUp(s,2)
			except:
				try:
					rsp = wikipediaLookUp(s,2)
				except:
					rsp = "I am sorry, I can not access that information."
		else:
			try:
				rsp = wikipediaLookUp(s,2)
			except:
				try:
					rsp = wikipediaLookUp(s,2)
				except:
					rsp = "I am sorry, I can not access that information."
	elif "do you know" in s:
		try:
			rsp = wikipediaLookUp(s,2)
		except:
			try:
				rsp = wikipediaLookUp(s,2)
			except:
				rsp = "I am sorry, I can not access that information."
	elif "who am i" in s or "who do you see" in s or "do you recognize" in s or "do you know me" in s:
		config.lookForFaces = 1
		rsp = "Let me see you and think."
		config.gettingStillImages = 0
	elif "off" in s and "light" in s:
		os.system("echo 'rf a1 off' | nc localhost 1099")
		os.system("echo 'rf c1 off' | nc localhost 1099")
		rsp = "Turning off the lights"
	elif "on" in s and "light" in s:
		os.system("echo 'rf a1 on' | nc localhost 1099")
		os.system("echo 'rf c1 on' | nc localhost 1099")
		rsp = "Turning on the lights"
	elif "who" in s:
		try:
			rsp = wikipediaLookUp(s,1)
		except:
			try:
				rsp = wikipediaLookUp(s,1)
			except:
				rsp = "I am sorry, I can not access that information."
	elif "shut" in s and "down" in s:
		saySomething("Shutting the computer down","en")
		os.system("sudo shutdown now &")
	else:
		rsp = getAIresponse(s)
	print rsp

	pattern = re.compile("([^a-zA-Z\d\s:,.']|_)+")
	rsp = re.sub(pattern, '', rsp)
	print rsp + " in " + language
	saySomething(rsp,language)