def callback(self, text): """this function is to process the recognized text and send the processed information to Arduino which controls some devices""" global text_last global xm_speech_req global xm_speech_res global sentences #if len(text) != 0 : # if text[28] == '=': # text = text[29:] # elif text[29] == '=': # text = text[30:] if text != "you are right" and text != "no" and len(text) != 0: text_last = text if type(text) == str and len(text) != 0: print("recognized : " + text) if xm_speech_req.command == 1: #Answer a question print('question: ' + text) file_handle_c = open( '/home/moonknight/catkin_ws/src/xm_speech/msc/bnf/c.txt', mode='rb') file_handle_d = open( '/home/moonknight/catkin_ws/src/xm_speech/msc/bnf/d.txt', mode='rb') c_contents = file_handle_c.readlines() d_contents = file_handle_d.readlines() t = '\"' + text + '\"' + '\n' if t in c_contents: c_index = c_contents.index(t) d = d_contents[c_index] print('answer: ' + d) xm_speech_res.num = 1 self.tts(d) elif xm_speech_req.command == 2: #GPSR if text != "you are right" and text != "no" and text != "you can stop here": if len(text_last) != 0: self.tts(text_last) self.tts("am i right") if text == "you are right": if len(text_last) != 0: self.tts("OK") sen = text_last for t in kitchen: sen = sen.replace(t, "kitchen") for t in livingroom: sen = sen.replace(t, "livingroom") for t in bedroom: sen = sen.replace(t, "bedroom") for t in hallway: sen = sen.replace(t, "hallway") if "bed" in sen and "bedroom" not in sen: sen = sen.replace("bed", "bedroom") if "tell the day of the month" in sen: sentences = "tell the day of the month" sen = sen.replace("tell the day of the month", "sentence") if "tell the day of the week" in sen: sentences = "tell the day of the week" sen = sen.replace("tell the day of the week", "sentence") if "tell the date" in sen: sentences = "tell the date" sen = sen.replace("tell the date", "sentence") for i in double_words: sen = sen.replace(i.replace("_", " "), i) print(sen) rd = RecursiveDescentParser(grammar) t = rd.parse_one(sen.split()) print(t) search(t) text_last = '' elif xm_speech_req.command == 3: #WhoIsWho if text != "you are right" and text != "no": if len(text_last) != 0: self.tts(text_last) self.tts("am i right") if text == "you are right": if len(text_last) != 0: self.tts("OK") print("text_last:" + text_last) #name for t in people: if t in text_last: xm_speech_res.name.append(t) xm_speech_res.num += 1 #object if text_last.find('ice tea') >= 0: xm_speech_res.object.append('ice_tea') xm_speech_res.num += 1 elif text_last.find('water') >= 0: xm_speech_res.object.append('water') xm_speech_res.num += 1 elif text_last.find('cracker') >= 0: xm_speech_res.object.append('cracker') xm_speech_res.num += 1 elif text_last.find('duck') >= 0: xm_speech_res.object.append('duck') xm_speech_res.num += 1 elif text_last.find('orange juice') >= 0: xm_speech_res.object.append('orange_juice') xm_speech_res.num += 1 elif text_last.find('porridge') >= 0: xm_speech_res.object.append('porridge') xm_speech_res.num += 1 elif text_last.find('milk') >= 0: xm_speech_res.object.append('milk') xm_speech_res.num += 1 elif text_last.find('milk tea') >= 0: xm_speech_res.object.append('milk_tea') xm_speech_res.num += 1 elif text_last.find('tissue') >= 0: xm_speech_res.object.append('tissue') xm_speech_res.num += 1 elif text_last.find('cola') >= 0: xm_speech_res.object.append('cola') xm_speech_res.num += 1 elif text_last.find('sprite') >= 0: xm_speech_res.object.append('sprite') xm_speech_res.num += 1 elif text_last.find('powder juice') >= 0: xm_speech_res.object.append('powder_juice') xm_speech_res.num += 1 elif text_last.find('green tea') >= 0: xm_speech_res.object.append('green_tea') xm_speech_res.num += 1 elif text_last.find('gum') >= 0: xm_speech_res.object.append('gum') xm_speech_res.num += 1 elif text_last.find('fanta') >= 0: xm_speech_res.object.append('fanta') xm_speech_res.num += 1 elif text_last.find('french fries') >= 0: xm_speech_res.object.append('french_fries') xm_speech_res.num += 1 elif text_last.find('yoghurt') >= 0: xm_speech_res.object.append('yoghurt') xm_speech_res.num += 1 elif text_last.find('noodle') >= 0: xm_speech_res.object.append('noodle') xm_speech_res.num += 1 elif text_last.find('crisp') >= 0: xm_speech_res.object.append('crisp') xm_speech_res.num += 1 elif text_last.find('herbal tea') >= 0: xm_speech_res.object.append('herbal_tea') xm_speech_res.num += 1 elif text_last.find('coconut') >= 0: xm_speech_res.object.append('coconut') xm_speech_res.num += 1 elif text_last.find('peartea') >= 0: xm_speech_res.object.append('pear_tea') xm_speech_res.num += 1 elif text_last.find('tea') >= 0: xm_speech_res.object.append('tea') xm_speech_res.num += 1 elif text_last.find('melon seeds') >= 0: xm_speech_res.object.append('melon_seeds') xm_speech_res.num += 1 elif text_last.find('redbull') >= 0: xm_speech_res.object.append('redbull') xm_speech_res.num += 1 elif text_last.find('toothpaste') >= 0: xm_speech_res.object.append('toothpaste') xm_speech_res.num += 1 elif text_last.find('grapejuice') >= 0: xm_speech_res.object.append('grape_juice') xm_speech_res.num += 1 elif text_last.find('soap') >= 0: xm_speech_res.object.append('soap') xm_speech_res.num += 1 elif text_last.find('shampoo') >= 0: xm_speech_res.object.append('shampoo') xm_speech_res.num += 1 text_last = '' elif xm_speech_req.command == 4: #SPR print('question: ' + text) file_handle_a = open( '/home/domistic/catkin_ws/src/xm_speech_for_linux/xm_speech/msc/bnf/a.txt', mode='rb') file_handle_b = open( '/home/domistic/catkin_ws/src/xm_speech_for_linux/xm_speech/msc/bnf/b.txt', mode='rb') a_contents = file_handle_a.readlines() b_contents = file_handle_b.readlines() t = text + '?\n' if t == a_contents[0]: print('finally') if t in a_contents: a_index = a_contents.index(t) b = b_contents[a_index] xm_speech_res.answer = b print('answer: ' + b) xm_speech_res.num = 1 self.tts(b) elif text == "number of people standing": xm_speech_res.num = 2 time.sleep(1) elif text == "number of people sitting": xm_speech_res.num = 3 time.sleep(1) elif text == "what is the number of the people who waving arms": xm_speech_res.num = 4 time.sleep(1) elif (xm_speech_req.command == 5): #help me carry if text != "you are right" and text != "no": if len(text_last) != 0: self.tts(text_last) self.tts("am i right") if text == "you are right": if len(text_last) != 0: if text_last.find("stop") >= 0: xm_speech_res.action.append('stop') elif text_last.find("follow") >= 0: xm_speech_res.action.append('follow') elif text_last.find("take") >= 0: xm_speech_res.action.append('take') if text_last.find("kitchen") >= 0: xm_speech_res.target.append('kitchen') elif text_last.find("livingroom") >= 0: xm_speech_res.target.append('livingroom') elif text_last.find("bedroom") >= 0: xm_speech_res.target.append('bedroom') elif text_last.find("diningroom") >= 0: xm_speech_res.target.append('diningroom') xm_speech_res.num = 1 print("text_last:" + text_last) text_last = '' if text == "you can stop here": xm_speech_res.action.append('stop') elif (xm_speech_req.command == 6): #shopping if text != "you are right" and text != "no": if len(text_last) != 0: self.tts(text_last) self.tts("am i right") if text == "you are right": if len(text_last) != 0: self.tts("OK") print("text_last:" + text_last) if text_last == "you can stop here": xm_speech_res.action.append('stop') xm_speech_res.num += 1 #follow elif text_last.find('follow') >= 0: xm_speech_res.action.append('follow') xm_speech_res.num += 1 #object elif text_last.find('ice tea') >= 0: xm_speech_res.object.append('ice_tea') xm_speech_res.num += 1 elif text_last.find('redbull') >= 0: xm_speech_res.object.append('redbull') xm_speech_res.num += 1 elif text_last.find('toothpaste') >= 0: xm_speech_res.object.append('toothpaste') xm_speech_res.num += 1 elif text_last.find(' Chips ') >= 0: xm_speech_res.object.append(' Chips ') xm_speech_res.num += 1 elif text_last.find('laoganma') >= 0: xm_speech_res.object.append('laoganma') xm_speech_res.num += 1 elif text_last.find('milk tea') >= 0: xm_speech_res.object.append('milk_tea') xm_speech_res.num += 1 elif text_last.find('water') >= 0: xm_speech_res.object.append('water') xm_speech_res.num += 1 elif text_last.find('cola') >= 0: xm_speech_res.object.append('cola') xm_speech_res.num += 1 elif text_last.find('porridge') >= 0: xm_speech_res.object.append('porridge') xm_speech_res.num += 1 elif text_last.find('sprite') >= 0: xm_speech_res.object.append('sprite') xm_speech_res.num += 1 elif text_last.find('shampoo') >= 0: xm_speech_res.object.append('shampoo') xm_speech_res.num += 1 elif text_last.find('water') >= 0: xm_speech_res.object.append('water') xm_speech_res.num += 1 elif text_last.find('cracker') >= 0: xm_speech_res.object.append('cracker') xm_speech_res.num += 1 elif text_last.find('duck') >= 0: xm_speech_res.object.append('duck') xm_speech_res.num += 1 elif text_last.find('orange juice') >= 0: xm_speech_res.object.append('orange_juice') xm_speech_res.num += 1 elif text_last.find('porridge') >= 0: xm_speech_res.object.append('porridge') xm_speech_res.num += 1 elif text_last.find('milk') >= 0: xm_speech_res.object.append('milk') xm_speech_res.num += 1 elif text_last.find('tissue') >= 0: xm_speech_res.object.append('tissue') xm_speech_res.num += 1 elif text_last.find('cola') >= 0: xm_speech_res.object.append('cola') xm_speech_res.num += 1 elif text_last.find('sprite') >= 0: xm_speech_res.object.append('sprite') xm_speech_res.num += 1 elif text_last.find('powder juice') >= 0: xm_speech_res.object.append('powder_juice') xm_speech_res.num += 1 elif text_last.find('green tea') >= 0: xm_speech_res.object.append('green_tea') xm_speech_res.num += 1 elif text_last.find('gum') >= 0: xm_speech_res.object.append('gum') xm_speech_res.num += 1 elif text_last.find('fanta') >= 0: xm_speech_res.object.append('fanta') xm_speech_res.num += 1 elif text_last.find('french fries') >= 0: xm_speech_res.object.append('french_fries') xm_speech_res.num += 1 elif text_last.find('yoghurt') >= 0: xm_speech_res.object.append('yoghurt') xm_speech_res.num += 1 elif text_last.find('noodle') >= 0: xm_speech_res.object.append('noodle') xm_speech_res.num += 1 elif text_last.find('crisp') >= 0: xm_speech_res.object.append('crisp') xm_speech_res.num += 1 elif text_last.find('herbal tea') >= 0: xm_speech_res.object.append('herbal_tea') xm_speech_res.num += 1 elif text_last.find('coconut') >= 0: xm_speech_res.object.append('coconut') xm_speech_res.num += 1 elif text_last.find('pear tea') >= 0: xm_speech_res.object.append('pear_tea') xm_speech_res.num += 1 elif text_last.find('tea') >= 0: xm_speech_res.object.append('tea') xm_speech_res.num += 1 elif text_last.find('melon seeds') >= 0: xm_speech_res.object.append('melon_seeds') xm_speech_res.num += 1 elif text_last.find('grape juice') >= 0: xm_speech_res.object.append('grape_juice') xm_speech_res.num += 1 elif text_last.find('soap') >= 0: xm_speech_res.object.append('soap') xm_speech_res.num += 1 #方向 if text_last.find('right') >= 0: xm_speech_res.target.append('right') xm_speech_res.num += 1 if text_last.find('left') >= 0: xm_speech_res.target.append('left') xm_speech_res.num += 1 if text_last.find('front') >= 0: xm_speech_res.target.append('front') xm_speech_res.num += 1 text_last = ''
def callback(self, text): """this function is to process the recognized text and send the processed information to Arduino which controls some devices""" global text_last global xm_speech_req global xm_speech_res global sentences #if len(text) != 0 : # if text[28] == '=': # text = text[29:] # elif text[29] == '=': # text = text[30:] if text != "you are right" and text != "no" and len(text) != 0: text_last = text if type(text) == str and len(text) != 0: print("recognized : " + text) if xm_speech_req.command == 1: #Answer a question if text == "you are right": print('question: ' + text_last) file_handle_c = open( '/home/domistic/catkin_ws/src/xm_speech_for_linux/xm_speech/msc/bnf/c.txt', mode='rb') file_handle_d = open( '/home/domistic/catkin_ws/src/xm_speech_for_linux/xm_speech/msc/bnf/d.txt', mode='rb') c_contents = file_handle_c.readlines() d_contents = file_handle_d.readlines() t = '\"' + text_last + '\"' + '\n' if t in c_contents: c_index = c_contents.index(t) d = d_contents[c_index] print('answer: ' + d) xm_speech_res.num = 1 self.tts(d) elif xm_speech_req.command == 2: #GPSR if text != "you are right" and text != "no" and text != "you can stop here": if len(text_last) != 0: self.tts(text_last) self.tts("am i right") if text == "you are right": if len(text_last) != 0: self.tts("OK") sen = text_last if "tell the day of the month" in sen: sentences = "tell the day of the month" sen = sen.replace("tell the day of the month", "sentence") if "tell the day of the week" in sen: sentences = "tell the day of the week" sen = sen.replace("tell the day of the week", "sentence") if "tell the date" in sen: sentences = "tell the date" sen = sen.replace("tell the date", "sentence") for i in double_words: sen = sen.replace(i.replace("_", " "), i) #print(sen) rd = RecursiveDescentParser(grammar) t = rd.parse_one(sen.split()) #print(t) search(t) text_last = '' elif xm_speech_req.command == 3: #WhoIsWho if text != "you are right" and text != "no": if len(text_last) != 0: self.tts(text_last) self.tts("am i right") if text == "you are right": if len(text_last) != 0: print("k") self.tts("OK") print("text_last:" + text_last) #name for t in people: if t in text_last: xm_speech_res.name.append(t) xm_speech_res.num += 1 for i in objectno: if i in text_last: xm_speech_res.object.append(i) xm_speech_res.num += 1 text_last = '' elif xm_speech_req.command == 4: #SPR #print('question: ' + text) file_handle_a = open( '/home/domistic/catkin_ws/src/xm_speech_for_linux/xm_speech/msc/bnf/a.txt', mode='rb') file_handle_b = open( '/home/domistic/catkin_ws/src/xm_speech_for_linux/xm_speech/msc/bnf/b.txt', mode='rb') a_contents = file_handle_a.readlines() b_contents = file_handle_b.readlines() t = text + '?\n' if t == a_contents[0]: print('finally') if t in a_contents: a_index = a_contents.index(t) b = b_contents[a_index] xm_speech_res.answer = b print('answer: ' + b) xm_speech_res.num = 1 self.tts(b) elif text == "number of people standing": xm_speech_res.num = 2 time.sleep(1) elif text == "number of people sitting": xm_speech_res.num = 3 time.sleep(1) elif text == "what is the number of the people who waving arms": xm_speech_res.num = 4 time.sleep(1) elif (xm_speech_req.command == 5): #help me carry if text != "you are right" and text != "no": if len(text_last) != 0: self.tts(text_last) self.tts("am i right") if text == "you are right": if len(text_last) != 0: if text_last.find("stop") >= 0: xm_speech_res.action.append('stop') elif text_last.find("follow") >= 0: xm_speech_res.action.append('follow') elif text_last.find("take") >= 0: xm_speech_res.action.append('take') if text_last.find("kitchen") >= 0: xm_speech_res.target.append('kitchen') elif text_last.find("livingroom") >= 0: xm_speech_res.target.append('livingroom') elif text_last.find("bedroom") >= 0: xm_speech_res.target.append('bedroom') elif text_last.find("diningroom") >= 0: xm_speech_res.target.append('diningroom') xm_speech_res.num = 1 print("text_last:" + text_last) text_last = '' if text == "you can stop here": xm_speech_res.action.append('stop') elif (xm_speech_req.command == 6): #shopping if text != "you are right" and text != "no": if len(text_last) != 0: self.tts(text_last) self.tts("am i right") if text == "you are right": if len(text_last) != 0: self.tts("OK") print("text_last:" + text_last) if text_last == "you can stop here": xm_speech_res.action.append('stop') xm_speech_res.num += 1 #follow elif text_last.find('follow') >= 0: xm_speech_res.action.append('follow') xm_speech_res.num += 1 else: for i in objectno: if i in text_last: xm_speech_res.object.append(i) xm_speech_res.num += 1 #方向 if text_last.find('right') >= 0: xm_speech_res.target.append('right') xm_speech_res.num += 1 if text_last.find('left') >= 0: xm_speech_res.target.append('left') xm_speech_res.num += 1 if text_last.find('front') >= 0: xm_speech_res.target.append('front') xm_speech_res.num += 1 text_last = ''
def callback(recognizer, audio): # received audio data, now we'll recognize it using xunfei Speech Recognition global xm_speech_req global xm_speech_res global text_last audio_wav_data = audio.get_wav_data() with open("microphone-results.wav", "wb") as f: f.write(audio.get_wav_data()) # print("audio_len : " + str(len(audio_wav_data))) # audio data length # print("Got it! Now to recognize it...") print("detecting...") if len(audio_wav_data) > 50000 and len(audio_wav_data) < 300000: print("pcm_len : " + str(len(audio_wav_data))) # audio data length rospy.wait_for_service('xm_speech') try: xm_speech = rospy.ServiceProxy('xm_speech', xm_Speech) resp1 = xm_speech(audio_wav_data) text = resp1.sr_text if text != "yes" and text != "no" and len(text) != 0: text_last = text if type(text) == str and len(text) != 0: print("recognized : " + text) if xm_speech_req.command == 0: if text == "what is the captital of china": subprocess.call([ "espeak", "-v", "f3+en_us", "-s", "130", "bei jing" ]) xm_speech_res.num = 1 elif text == "how many hours in a day": subprocess.call( ["espeak", "-v", "f3+en_us", "-s", "130", "24"]) xm_speech_res.num = 1 elif text == "how many season are there in one year": subprocess.call( ["espeak", "-v", "f3+en_us", "-s", "130", "4"]) xm_speech_res.num = 1 elif text == "how many seconds in one minute": subprocess.call( ["espeak", "-v", "f3+en_us", "-s", "130", "60"]) xm_speech_res.num = 1 elif text == "what is the world biggest island": subprocess.call([ "espeak", "-v", "f3+en_us", "-s", "130", "green land" ]) xm_speech_res.num = 1 elif text == "what is the biggest province of china": subprocess.call([ "espeak", "-v", "f3+en_us", "-s", "130", "xin jiang" ]) xm_speech_res.num = 1 elif text == "how large is the area of china": subprocess.call([ "espeak", "-v", "f3+en_us", "-s", "130", "nine million and six hundred thousand saquare kilometers" ]) xm_speech_res.num = 1 elif text == "who was the first president of the usa": subprocess.call([ "espeak", "-v", "f3+en_us", "-s", "130", "george washington" ]) xm_speech_res.num = 1 elif text == "what is china's national animal": subprocess.call( ["espeak", "-v", "f3+en_us", "-s", "130", "panda"]) xm_speech_res.num = 1 elif xm_speech_req.command == 1: #GPSR if text != "yes" and text != "no": if len(text_last) != 0: subprocess.call([ "espeak", "-v", "f3+en_us", "-s", "130", text_last ]) subprocess.call([ "espeak", "-v", "f3+en_us", "-s", "130", "yes or no" ]) if text == "yes": if len(text_last) != 0: sen = text_last rd = RecursiveDescentParser(grammar) t = rd.parse_one(sen.split()) search(t) elif xm_speech_req.command == 2: #HelpMeCarry if text != "yes" and text != "no": if len(text_last) != 0: subprocess.call([ "espeak", "-v", "f3+en_us", "-s", "130", text_last ]) subprocess.call([ "espeak", "-v", "f3+en_us", "-s", "130", "yes or no" ]) if text == "yes": if len(text_last) != 0: subprocess.call([ "espeak", "-v", "f3+en_us", "-s", "130", "OK" ]) print("text_last:" + text_last) if text_last == "follow me": xm_speech_res.action.append('follow') xm_speech_res.num += 1 elif text_last == "remember location": xm_speech_res.action.append('remember') xm_speech_res.num += 1 elif text_last == "take it": xm_speech_res.action.append('grasp') xm_speech_res.num += 1 elif text_last == "carry to the kitchen": xm_speech_res.target.append('kitchen') xm_speech_res.num += 1 elif text_last == "carry to the bedroom": xm_speech_res.target.append('bedroom') xm_speech_res.num += 1 elif text_last == "take to the dining room": xm_speech_res.target.append('diningroom') xm_speech_res.num += 1 elif text_last == "carry to the living room": xm_speech_res.target.append('livingroom') xm_speech_res.num += 1 else: pass except rospy.ServiceException, e: print "Service call failed: %s" % e
def callback(self, text): """this function is to process the recognized text and send the processed information to Arduino which controls some devices""" global text_last global xm_speech_req global xm_speech_res #if len(text) != 0 : # if text[28] == '=': # text = text[29:] # elif text[29] == '=': # text = text[30:] if text != "you are right" and text != "no" and len(text) != 0: text_last = text print(text) t = type(text) print(t) if type(text) == str and len(text) != 0: print("recognized : " + text) if xm_speech_req.command == 1: #Answer a question if text == "what is the capital of china": print("Beijing") self.tts("Beijing") xm_speech_res.num = 1 elif text == "how many hours in a day": print("twenty four") self.tts("twenty four") xm_speech_res.num = 1 elif text == "how many season are there in one year": print("four") self.tts("four") xm_speech_res.num = 1 elif text == "how many seconds in one minute": print("sixty") self.tts("sixty") xm_speech_res.num = 1 elif text == "what is the world biggest island": print("green land") self.tts("green land") xm_speech_res.num = 1 elif text == "what is the biggest province of china": print("xin jiang") self.tts("xin jiang") xm_speech_res.num = 1 elif text == "how large is the area of china": print( "nine million and six hundred thousand saquare kilometers" ) self.tts( "nine million and six hundred thousand saquare kilometers" ) xm_speech_res.num = 1 elif text == "who was the first president of the usa": print("george washington") self.tts("george washington") xm_speech_res.num = 1 elif text == "what is china's national animal": print("panda") self.tts("panda") xm_speech_res.num = 1 elif text == "how many children did queen victoria have": print("nine children") self.tts("nine children") xm_speech_res.num = 1 elif text == "what was the former name of new york": print("new amsterdam") self.tts("new amsterdam") xm_speech_res.num = 1 elif xm_speech_req.command == 2: #GPSR if text != "you are right" and text != "no" and text != "stop here now": if len(text_last) != 0: self.tts(text_last) self.tts("am i right") if text == "you are right": if len(text_last) != 0: self.tts("OK") sen = text_last rd = RecursiveDescentParser(grammar) t = rd.parse_one(sen.split()) search(t) elif text == "stop here now": xm_speech_res.action.append('stop') xm_speech_res.num = 1 self.tts("OK") elif xm_speech_req.command == 3: #WhoIsWho if text != "you are right" and text != "no": if len(text_last) != 0: self.tts(text_last) self.tts("am i right") if text == "you are right": if len(text_last) != 0: self.tts("OK") print("text_last:" + text_last) #name if text_last.find('Tom') >= 0: xm_speech_res.name.append('Tom') xm_speech_res.num += 1 elif text_last.find('Micheal') >= 0: xm_speech_res.name.append('Micheal') xm_speech_res.num += 1 elif text_last.find('Jack') >= 0: xm_speech_res.name.append('Jack') xm_speech_res.num += 1 elif text_last.find('Kevin') >= 0: xm_speech_res.name.append('Kevin') xm_speech_res.num += 1 elif text_last.find('Rose') >= 0: xm_speech_res.name.append('Rose') xm_speech_res.num += 1 elif text_last.find('John') >= 0: xm_speech_res.name.append('John') xm_speech_res.num += 1 elif text_last.find('Mary') >= 0: xm_speech_res.name.append('Mary') xm_speech_res.num += 1 elif text_last.find('Fisher') >= 0: xm_speech_res.name.append('Fisher') xm_speech_res.num += 1 elif text_last.find('Adam') >= 0: xm_speech_res.name.append('Adam') xm_speech_res.num += 1 elif text_last.find('Daniel') >= 0: xm_speech_res.name.append('Daniel') xm_speech_res.num += 1 #object if text_last.find('ice tea') >= 0: xm_speech_res.object.append('ice tea') xm_speech_res.num += 1 elif text_last.find('safeguard') >= 0: xm_speech_res.object.append('safeguard') xm_speech_res.num += 1 elif text_last.find('napkin') >= 0: xm_speech_res.object.append('napkin') xm_speech_res.num += 1 elif text_last.find('chips') >= 0: xm_speech_res.object.append('chips') xm_speech_res.num += 1 elif text_last.find('laoganma') >= 0: xm_speech_res.object.append('laoganma') xm_speech_res.num += 1 elif text_last.find('porridge') >= 0: xm_speech_res.object.append('porridge') xm_speech_res.num += 1 elif text_last.find('milk') >= 0: xm_speech_res.object.append('milk') xm_speech_res.num += 1 elif text_last.find('water') >= 0: xm_speech_res.object.append('water') xm_speech_res.num += 1 elif text_last.find('cola') >= 0: xm_speech_res.object.append('cola') xm_speech_res.num += 1 elif text_last.find('sprite') >= 0: xm_speech_res.object.append('sprite') xm_speech_res.num += 1 elif xm_speech_req.command == 4: #SPR print(text) #ArenaQ if text == "How many bookshelf are in the living room": xm_speech_res.num = 1 self.tts("three") elif text == "In which room is the fridge": xm_speech_res.num = 1 self.tts("kitchen") elif text == "How many doors has the Arena": xm_speech_res.num = 1 self.tts("2") elif text == "In which room is the dining table": xm_speech_res.num = 1 tself.tts("diningroom") elif text == "Where is located the bed": xm_speech_res.num = 1 self.tts("bedroom") elif text == "How many fireplace are in the bedroom": xm_speech_res.num = 1 self.tts("zero") elif text == "In which room is the sofa": xm_speech_res.num = 1 self.tts("livingroom") elif text == "Where is located the fridge": xm_speech_res.num = 1 self.tts("kitchen") elif text == "Where is located the cupboard": xm_speech_res.num = 1 self.tts("diningroom") elif text == "In which room is the bookshelf": xm_speech_res.num = 1 self.tts("bedroom") #ObjectQ elif text == "how many hours in a day": xm_speech_res.num = 1 self.tts("twenty four") elif text == "how many season are there in one year": xm_speech_res.num = 1 self.tts("four") elif text == "how many seconds in one minute": xm_speech_res.num = 1 self.tts("sixty") elif text == "what is the world biggest island": xm_speech_res.num = 1 self.tts("green land") elif text == "what is the biggest province of china": xm_speech_res.num = 1 self.tts("shin junk") elif text == "how large is the area of china": xm_speech_res.num = 1 self.tts( "Nine million and six hundred thousand saquare kilometers" ) elif text == "Who was the first president of the USA": xm_speech_res.num = 1 self.tts("George Washington") elif text == "What is China's national animal": xm_speech_res.num = 1 self.tts("panda") elif text == "How many children did Queen Victoria have": xm_speech_res.num = 1 self.tts("Nine children") elif text == "What was the former name of New York": xm_speech_res.num = 1 self.tts("New Amsterdam") #PredefinedQ elif text == "How many people live in the Japan": xm_speech_res.num = 1 self.tts("A little over 80 million") elif text == "what is the capital of the united states": xm_speech_res.num = 1 self.tts("Washington DC") elif text == "what day is today": xm_speech_res.num = 1 self.tts("Saturday") elif text == "What city is the capital of the Japan": xm_speech_res.num = 1 self.tts("Tokyo") elif text == "Where does the term computer bug come from": xm_speech_res.num = 1 self.tts("From a moth trapped in a relay") elif text == "When was invented the B programming language": xm_speech_res.num = 1 self.tts("B was developed circa 1969 at Bell Labs") elif text == "Who invented the C programming language": xm_speech_res.num = 1 self.tts("Ken Thompson and Dennis Ritchie") elif text == "What is the highest point in Japan": xm_speech_res.num = 1 self.tts("The highest point in Japan is Mount Fuji") elif text == "What are the colours of the Japanese flag": xm_speech_res.num = 1 self.tts( "Japanese flag is a red circle centred over white") elif text == "Who invented the first compiler": xm_speech_res.num = 1 self.tts("Grace Brewster Murray Hopper invented it") #CrowdOperatorQ '''elif text == "number of male people sitting": xm_speech_res.num = 2 time.sleep(1) elif text == "number of female people sitting": xm_speech_res.num = 3 time.sleep(1) elif text == "number of male people standing": xm_speech_res.num = 4 time.sleep(1) elif text == "number of female people standing": xm_speech_res.num = 5 time.sleep(1) elif text == "number of people standing": xm_speech_res.num = 6 time.sleep(1) elif text == "number of people sitting": xm_speech_res.num = 7 time.sleep(1) ''' if text == 'number of male people': xm_speech_res.num = 2 time.sleep(1) if text == 'number of female people': xm_speech_res.num = 3 time.sleep(1) if text == 'number of people': xm_speech_res.num = 4 time.sleep(1) elif (xm_speech_req.command == 5): #help me carry if text != "you are right" and text != "no": if len(text_last) != 0: self.tts(text_last) self.tts("am i right") if text == "you are right": if len(text_last) != 0: if text_last.find("stop") >= 0: xm_speech_res.action.append('stop') elif text_last.find("follow") >= 0: xm_speech_res.action.append('follow') elif text_last.find("take") >= 0: xm_speech_res.action.append('take') if text_last.find("kitchen") >= 0: xm_speech_res.target.append('kitchen') elif text_last.find("livingroom") >= 0: xm_speech_res.target.append('livingroom') elif text_last.find("bedroom") >= 0: xm_speech_res.target.append('bedroom') elif text_last.find("diningroom") >= 0: xm_speech_res.target.append('diningroom') if text_last.find("bag") >= 0: xm_speech_res.object.append('bag') self.tts("OK") xm_speech_res.num = 1 print("text_last:" + text_last) elif (xm_speech_req.command == 6): #shopping if text != "you are right" and text != "no": if len(text_last) != 0: self.tts(text_last) self.tts("am i right") if text == "you are right": if len(text_last) != 0: self.tts("OK") print("text_last:" + text_last) num = 0 #follow if text_last.find('follow') >= 0: xm_speech_res.action.append('follow') num += 1 #object if text_last.find('ice tea') >= 0: xm_speech_res.object.append('ice tea') num += 1 if text_last.find('safeguard') >= 0: xm_speech_res.object.append('safeguard') num += 1 if text_last.find('napkin') >= 0: xm_speech_res.object.append('napkin') num += 1 if text_last.find('chips') >= 0: xm_speech_res.object.append('chips') num += 1 if text_last.find('laoganma') >= 0: xm_speech_res.object.append('laoganma') num += 1 if text_last.find('milk') >= 0: xm_speech_res.object.append('milk') num += 1 if text_last.find('water') >= 0: xm_speech_res.object.append('water') num += 1 if text_last.find('cola') >= 0: xm_speech_res.object.append('cola') num += 1 if text_last.find('porridge') >= 0: xm_speech_res.object.append('porridge') num += 1 if text_last.find('sprite') >= 0: xm_speech_res.object.append('sprite') num += 1 #方向 if text_last.find('right') >= 0: xm_speech_res.target.append('right') num += 1 if text_last.find('left') >= 0: xm_speech_res.target.append('left') num += 1 xm_speech_res.num = num
def callback(self, text): """this function is to process the recognized text and send the processed information to Arduino which controls some devices""" global text_last global xm_speech_req global xm_speech_res flag = 0 if len(text) != 0 : if text[28] == '=': text = text[29:] elif text[29] == '=': text = text[30:] if text != "you are right" and text != "no" and len(text) != 0: text_last = text if type(text) == str and len(text) != 0: print("recognized : " + text) if xm_speech_req.command == 1:#Answer a question if text == "what is the capital of china": tts_test = rospy.ServiceProxy('tts',xm_Speech_tts) tts_res = tts_test.call('Beijing') if tts_res.flag == 1: subprocess.call(["play","tts_sample.wav"]) else: subprocess.call(["espeak","-v","f3+en_us","-s","130","bei jing"]) xm_speech_res.num = 1 elif text == "how many hours in a day": tts_test = rospy.ServiceProxy('tts',xm_Speech_tts) tts_res = tts_test.call('twenty four') if tts_res.flag == 1: subprocess.call(["play","tts_sample.wav"]) else: subprocess.call(["espeak","-v","f3+en_us","-s","130","24"]) xm_speech_res.num = 1 elif text == "how many season are there in one year": tts_test = rospy.ServiceProxy('tts',xm_Speech_tts) tts_res = tts_test.call('four') if tts_res.flag == 1: subprocess.call(["play","tts_sample.wav"]) else: subprocess.call(["espeak","-v","f3+en_us","-s","130","4"]) xm_speech_res.num = 1 elif text == "how many seconds in one minute": tts_test = rospy.ServiceProxy('tts',xm_Speech_tts) tts_res = tts_test.call('sixty') if tts_res.flag == 1: subprocess.call(["play","tts_sample.wav"]) else: subprocess.call(["espeak","-v","f3+en_us","-s","130","60"]) xm_speech_res.num = 1 elif text == "what is the world biggest island": tts_test = rospy.ServiceProxy('tts',xm_Speech_tts) tts_res = tts_test.call('green land') if tts_res.flag == 1: subprocess.call(["play","tts_sample.wav"]) else: subprocess.call(["espeak","-v","f3+en_us","-s","130","green land"]) xm_speech_res.num = 1 elif text == "what is the biggest province of china": tts_test = rospy.ServiceProxy('tts',xm_Speech_tts) tts_res = tts_test.call('xin jiang') if tts_res.flag == 1: subprocess.call(["play","tts_sample.wav"]) else: subprocess.call(["espeak","-v","f3+en_us","-s","130","xin jiang"]) xm_speech_res.num = 1 elif text == "how large is the area of china": tts_test = rospy.ServiceProxy('tts',xm_Speech_tts) tts_res = tts_test.call('nine million and six hundred thousand saquare kilometers') if tts_res.flag == 1: subprocess.call(["play","tts_sample.wav"]) else: subprocess.call(["espeak","-v","f3+en_us","-s","130","nine million and six hundred thousand saquare kilometers"]) xm_speech_res.num = 1 elif text == "who was the first president of the usa": tts_test = rospy.ServiceProxy('tts',xm_Speech_tts) tts_res = tts_test.call('george washington') if tts_res.flag == 1: subprocess.call(["play","tts_sample.wav"]) else: subprocess.call(["espeak","-v","f3+en_us","-s","130","george washington"]) xm_speech_res.num = 1 elif text == "what is china's national animal": tts_test = rospy.ServiceProxy('tts',xm_Speech_tts) tts_res = tts_test.call('panda') if tts_res.flag == 1: subprocess.call(["play","tts_sample.wav"]) else: subprocess.call(["espeak","-v","f3+en_us","-s","130","panda"]) xm_speech_res.num = 1 elif text == "how many children did queen victoria have": tts_test = rospy.ServiceProxy('tts',xm_Speech_tts) tts_res = tts_test.call('nine children') if tts_res.flag == 1: subprocess.call(["play","tts_sample.wav"]) else: subprocess.call(["espeak","-v","f3+en_us","-s","130","nine children"]) xm_speech_res.num = 1 elif text == "what was the former name of new york": tts_test = rospy.ServiceProxy('tts',xm_Speech_tts) tts_res = tts_test.call('new amsterdam') if tts_res.flag == 1: subprocess.call(["play","tts_sample.wav"]) else: subprocess.call(["espeak","-v","f3+en_us","-s","130","new amsterdam"]) xm_speech_res.num = 1 elif xm_speech_req.command == 2:#GPSR if text != "you are right" and text != "no": if len(text_last) != 0: tts_test = rospy.ServiceProxy('tts',xm_Speech_tts) tts_res = tts_test.call(text_last) if tts_res.flag == 1: subprocess.call(["play","tts_sample.wav"]) else: subprocess.call(["espeak","-v","f3+en_us","-s","130",text_last]) tts_test = rospy.ServiceProxy('tts',xm_Speech_tts) tts_res = tts_test.call('am i right?') if tts_res.flag == 1: subprocess.call(["play","tts_sample.wav"]) else: subprocess.call(["espeak","-v","f3+en_us","-s","130","am i right?"]) if text == "you are right": if len(text_last) != 0: tts_test = rospy.ServiceProxy('tts',xm_Speech_tts) tts_res = tts_test.call('OK') if tts_res.flag == 1: subprocess.call(["play","tts_sample.wav"]) else: subprocess.call(["espeak","-v","f3+en_us","-s","130","OK"]) sen = text_last rd = RecursiveDescentParser(grammar) t = rd.parse_one(sen.split()) search(t) elif xm_speech_req.command == 3:#WhoIsWho if text != "you are right" and text != "no": if len(text_last) != 0: tts_test = rospy.ServiceProxy('tts',xm_Speech_tts) tts_res = tts_test.call(text_last) if tts_res.flag == 1: subprocess.call(["play","tts_sample.wav"]) else: subprocess.call(["espeak","-v","f3+en_us","-s","130",text_last]) tts_test = rospy.ServiceProxy('tts',xm_Speech_tts) tts_res = tts_test.call('am i right?') if tts_res.flag == 1: subprocess.call(["play","tts_sample.wav"]) else: subprocess.call(["espeak","-v","f3+en_us","-s","130","am i right?"]) if text == "you are right": if len(text_last) != 0: tts_test = rospy.ServiceProxy('tts',xm_Speech_tts) tts_res = tts_test.call('OK') if tts_res.flag == 1: subprocess.call(["play","tts_sample.wav"]) else: subprocess.call(["espeak","-v","f3+en_us","-s","130","OK"]) print("text_last:"+text_last) #name if text_last.find('Tom') >= 0: xm_speech_res.name.append('Tom') xm_speech_res.num += 1 elif text_last.find('Paul') >= 0: xm_speech_res.name.append('Paul') xm_speech_res.num += 1 elif text_last.find('Green') >= 0: xm_speech_res.name.append('Green') xm_speech_res.num += 1 elif text_last.find('Kevin') >= 0: xm_speech_res.name.append('Kevin') xm_speech_res.num += 1 elif text_last.find('Tracy') >= 0: xm_speech_res.name.append('Tracy') xm_speech_res.num += 1 elif text_last.find('John') >= 0: xm_speech_res.name.append('John') xm_speech_res.num += 1 elif text_last.find('Angel') >= 0: xm_speech_res.name.append('Angel') xm_speech_res.num += 1 elif text_last.find('Jamie') >= 0: xm_speech_res.name.append('Jamie') xm_speech_res.num += 1 elif text_last.find('Fisher') >= 0: xm_speech_res.name.append('Fisher') xm_speech_res.num += 1 elif text_last.find('Shirley') >= 0: xm_speech_res.name.append('Shirley') xm_speech_res.num += 1 elif text_last.find('Robin') >= 0: xm_speech_res.name.append('Robin') xm_speech_res.num += 1 elif text_last.find('Daniel') >= 0: xm_speech_res.name.append('Daniel') xm_speech_res.num += 1 #object if text_last.find('paper') >= 0: xm_speech_res.object.append('paper') xm_speech_res.num += 1 elif text_last.find('noodles') >= 0: xm_speech_res.object.append('noodles') xm_speech_res.num += 1 elif text_last.find('pie') >= 0: xm_speech_res.object.append('pie') xm_speech_res.num += 1 elif text_last.find('tea') >= 0: xm_speech_res.object.append('tea') xm_speech_res.num += 1 elif text_last.find('biscuit') >= 0: xm_speech_res.object.append('biscuit') xm_speech_res.num += 1 elif text_last.find('chip') >= 0: xm_speech_res.object.append('chip') xm_speech_res.num += 1 elif text_last.find('soap') >= 0: xm_speech_res.object.append('soap') xm_speech_res.num += 1 elif text_last.find('shampoo') >= 0: xm_speech_res.object.append('shampoo') xm_speech_res.num += 1 elif text_last.find('milk tea') >= 0: xm_speech_res.object.append('milk tea') xm_speech_res.num += 1 elif text_last.find('water') >= 0: xm_speech_res.object.append('water') xm_speech_res.num += 1 elif text_last.find('toothpaste') >= 0: xm_speech_res.object.append('toothpaste') xm_speech_res.num += 1 elif text_last.find('coffee') >= 0: xm_speech_res.object.append('coffee') xm_speech_res.num += 1 elif text_last.find('cola') >= 0: xm_speech_res.object.append('cola') xm_speech_res.num += 1 elif text_last.find('red bull') >= 0: xm_speech_res.object.append('red bull') xm_speech_res.num += 1