示例#1
0
文件: main.py 项目: sachin1092/Jarvis
def handler(fileName):
	global speech, listen

	cfileName = None
	try:
		engine = pyttsx.init()
		cfileName = psw.convert(fileName)
		print "processing the file: ", fileName
		
		flag = True
		if not listen:
			with open('jarvis_fingerprints_samples', 'r') as f:
				fingerprints_json = json.loads("".join(f.readlines())).get("data")
				finger_prints = fingerprints_json.get("vals")
				finger_print_char = fingerprints_json.get("char")

			current_fingerprint = acoustid.fingerprint_file(fileName)
			print "now recorded", current_fingerprint
			if current_fingerprint[0] > max(finger_prints) or current_fingerprint[0] < min(finger_prints) or current_fingerprint[1] != finger_print_char:
				flag = False

		if flag:
			phrase = speech.getText(cfileName)
			if phrase!=None:
				phrase = phrase.lower()
				if len(phrase.strip())>0:
					print 'text:', phrase
					if listen:
						listen = False
						# commands.execute(phrase, speech)
						if "weather" in phrase.lower():
							engine.say(get_weather())
							engine.runAndWait()
					if "jarvis" in phrase.lower():
						print "got in"
						print engine.isBusy()
						if engine.isBusy():
							engine.say("yes sir?")
							engine.runAndWait()
							listen = True
	except Exception, e:
		import traceback
		traceback.print_exc()
		listen = False
		print "Unexpected error:", sys.exc_info()[0], e
		engine.say("I didn't catch that, sir.")
		engine.runAndWait()
示例#2
0
def handler(fileName):
	global speech, listen

	translator = gapi.Translator(speech.lang, 'en-uk')
	cfileName = None
	try:
		engine = pyttsx.init()
		cfileName = psw.convert(fileName)
		print "processing the file: ", fileName
		
		flag = True
		if not listen:
			finger_prints = []
			finger_print_char = None
			for files in os.listdir(os.getcwd() + '/audio'):
				finger_print = acoustid.fingerprint_file('audio/' + files)
				finger_prints.append(finger_print[0])
				finger_print_char = finger_print[1]
				print files, finger_print

			current_fingerprint = acoustid.fingerprint_file(fileName)
			print "now recorded", current_fingerprint
			if current_fingerprint[0] > max(finger_prints) or current_fingerprint[0] < min(finger_prints) or current_fingerprint[1] != finger_print_char:
				flag = False

		if flag:
			phrase = speech.getText(cfileName)
			if phrase!=None:
				phrase = phrase.lower()
				if len(phrase.strip())>0:
					print 'text:',phrase
					# psw.play(speech.getAudio(phrase))
					if listen:
						listen = False
						if "weather" in phrase.lower():
							engine.say(get_weather())
							engine.runAndWait()
					if "ok jarvis" in phrase.lower() or "okay jarvis" in phrase.lower():
						if engine.isBusy():
							engine.say("yes sir?")
							engine.runAndWait()
							listen = True
	except Exception, e:
		import traceback
		traceback.print_exc()
		print "Unexpected error:", sys.exc_info()[0], e
示例#3
0
def handler(fileName):
    global speech
    translator = gapi.Translator(speech.lang, 'en-uk')
    try:
        cfileName = psw.convert(fileName)
        phrase = speech.getText(cfileName)
        import os
        os.remove(fileName)
        os.remove(cfileName)

        all_words = phrase.split(' ')
        words = phrase.split(' ')
        for i in range(len(words)):
            words[i] = str(words[i])
            all_words[i] = str(all_words[i])
            print all_words[i]

        print 'the phrase is:', phrase

        if 'wake' in words:
            speak('Ready to work!, sir.')
            Tuck_arms(False)

        elif 'sleep' in words:
            speak('Going to sleep!, sir.')
            Tuck_arms(True)

        elif 'yourself' in words:
            speak(
                'Welcome to the school of computing! my name is Lucas. Which stands for. Leeds university cognative artificial system. Researchers here in leeds are teaching me how to become a smarter robot! so that I can help humans in their daily activities! One of the many interesting things I can do is, you can ask me to pick up an object and I will pick it up for you! Please try and ask me to pick something!'
            )

        elif 'pick' in words or 'picked' in words:
            speak('going to pick up the object')
            print 'pick detected'
            pub2.publish(all_words, [], [], [], [], [], [], [], [])

        elif 'lucas' in words or 'hello' in words:
            speak('Hello, sir.')

    except Exception, e:
        print "Unexpected error:", sys.exc_info()[0], e
示例#4
0
def handler(fileName):
	global speech

	translator = gapi.Translator(speech.lang, 'en-uk')
	try:
		cfileName = psw.convert(fileName)
		phrase = speech.getText(cfileName)
		import os
		os.remove(fileName)
		os.remove(cfileName)
		if phrase!=None:
			phrase = phrase.lower()
			if len(phrase.strip())>0:
				print 'text:',phrase
				#psw.play(speech.getAudio(phrase))
				cmd = translator.translate(phrase).strip().lower()
				print 'cmd:',cmd
				commands.execute(cmd, speech)
	except Exception, e:
		print "Unexpected error:", sys.exc_info()[0], e
def handler(fileName):
	global speech
	translator = gapi.Translator(speech.lang, 'en-uk')
	try:
		cfileName = psw.convert(fileName)
		phrase = speech.getText(cfileName)
		import os
		os.remove(fileName)
		os.remove(cfileName)

		all_words = phrase.split(' ')
		words = phrase.split(' ')
		for i in range(len(words)):
			words[i] = str(words[i])
			all_words[i] = str(all_words[i])
			print all_words[i]

		print 'the phrase is:',phrase

		if 'wake' in words:
			speak('Ready to work!, sir.')
			Tuck_arms(False)

		elif 'sleep' in words:
			speak('Going to sleep!, sir.')
			Tuck_arms(True)

		elif 'yourself' in words:
			speak('Welcome to the school of computing! my name is Lucas. Which stands for. Leeds university cognative artificial system. Researchers here in leeds are teaching me how to become a smarter robot! so that I can help humans in their daily activities! One of the many interesting things I can do is, you can ask me to pick up an object and I will pick it up for you! Please try and ask me to pick something!')

		elif 'pick' in words or 'picked' in words:
			speak('going to pick up the object')
			print 'pick detected'
			pub2.publish(all_words,[],[],[],[],[],[],[],[])

		elif 'lucas' in words or 'hello' in words:
			speak('Hello, sir.')
			
		
	except Exception, e:
		print "Unexpected error:", sys.exc_info()[0], e
def handler(fileName):
	global speech

	translator = gapi.Translator(speech.lang, 'en-uk')
	try:
		cfileName = psw.convert(fileName)
		city = speech.getText(cfileName)
		import os
		os.remove(fileName)
		os.remove(cfileName)
		if city!=None:
			city = city.lower()
			if len(city.strip())>0:
				print 'You said:',city
				w.update(city)
				print 'Status:', w.status
				print 'Temperature: %f celsius' % w.temp
				print 'Humidity: %d%%' % w.humidity
				print 'Wind: %fm/s, %ddegrees' % (w.wind[0], w.wind[1])


	except Exception, e:
		print "Unexpected error:", sys.exc_info()[0], e
def handler(fileName):
    global speech, COUNTER
    translator = gapi.Translator(speech.lang, 'en-uk')
    try:
        cfileName = psw.convert(fileName)
        phrase = speech.getText(cfileName)
        import os
        os.remove(fileName)
        os.remove(cfileName)

        all_phrases = {}
        count = 0
        max_key = 0
        max_value = 0
        dictionary_words = [
            'pick', 'hello', 'Lucas', 'lucas', 'wake', 'sleep', 'work',
            'working', 'yourself', 'blue', 'green', 'red', 'near', 'far',
            'right', 'left'
        ]
        hyp = {}
        hyp['valid_dir_hyp'] = ['left', 'right', 'below', 'above']
        hyp['valid_dis_hyp'] = ['near', 'far']
        hyp['valid_HSV_hyp'] = ['red', 'blue', 'green', 'yellow', 'black']
        #commands = {}
        #commands[0] = 'pick up the green object'
        #commands[1] = 'pick up the blue object below the green object'
        #commands[2] = 'pick up the blue object far from the green object'
        for j in phrase:
            all_phrases[count] = {}
            all_phrases[count]['text'] = str(j['text'])
            all_phrases[count]['score'] = 0

            for i in dictionary_words:
                if i in all_phrases[count]['text']:
                    all_phrases[count]['score'] += 1

            if max_value < all_phrases[count]['score']:
                max_value = all_phrases[count]['score']
                max_key = count

            print 'phrase ' + str(count + 1) + ' : ', str(
                j['text']), ' score : ', str(all_phrases[count]['score'])

            count += 1

        phrase = all_phrases[max_key]['text']
        all_words = phrase.split(' ')
        words = phrase.split(' ')
        for i in range(len(words)):
            words[i] = str(words[i])
            all_words[i] = str(all_words[i])
            print all_words[i]

        print 'the phrase is:', phrase

        if 'wake' in words or 'working' in words:
            speak('Ready to work!, sir.')
            Tuck_arms(False)

        elif 'sleep' in words:
            speak('Going to sleep!, sir.')
            Tuck_arms(True)

        elif 'yourself' in words:
            speak(
                'Welcome to the school of computing! my name is Lucas. Which stands for. Leeds university cognative artificial system. Researchers here in leeds are teaching me how to become a smarter robot! so that I can help humans in their daily activities! One of the many interesting things I can do is, you can ask me to pick up an object and I will pick it up for you! Please try and ask me to pick something!'
            )

        elif 'pick' in words:
            sentence = phrase
            #sentence = commands[COUNTER]
            #COUNTER += 1
            words = sentence.split(' ')
            action = ''
            obj1 = ''
            obj2 = ''
            dir_rel = ''
            dis_rel = ''
            if 'pick' in words: action = 'pick'
            if 'put' in words: action = 'put'

            look_for_relations = 0
            for i in words:

                if look_for_relations:
                    if i in hyp['valid_dir_hyp']: dir_rel = i
                    if i in hyp['valid_dis_hyp']: dis_rel = i

                if i in hyp['valid_HSV_hyp'] and look_for_relations == 0:
                    look_for_relations = 1
                    obj1 = i
                elif i in hyp['valid_HSV_hyp'] and look_for_relations == 1:
                    look_for_relations = 0
                    obj2 = i

            print action, obj1, obj2, dir_rel, dis_rel

            #print Learn.hyp['valid_HSV_hyp']
            #print Learn.hyp['valid_dis_hyp']
            #print Learn.hyp['valid_dir_hyp']
            pub2.publish([action], [obj1], [obj2], [dir_rel], [dis_rel])

        elif 'lucas' in words or 'hello' in words:
            speak('Hello, sir.')

    except Exception, e:
        print "Unexpected error:", sys.exc_info()[0], e