def Integrate(optional_message = None): import CoreNLP if optional_message: sentence = optional_message print "Text input provided: '" + optional_message + "'" else: greeting_str = 'Hi ' + settings.username.capitalize() greeting_str += '! What can I help you with?' speech.speak(greeting_str, True) (success, sentence) = speech.listen() if not success: speech.speak(sentence, True) exit() # CoreNLP is weird, need to replace some stuff to make it properly recognize short sentences sentence = sentence.replace("Start", "start").replace("open", "Open").replace("Please", "").replace("please", "") # Call NLP parsing function (verb, verb_object, noun2, verb2, preposition, adjective) = CoreNLP.Parse(sentence) # Fix some more edge cases with broken sentences if not verb: verb, verb_object = CoreNLPFail(sentence) # TODO: Eventually we should probably not attach the preposition to the verb (does it actually improve accuracy?) if preposition: verb = "%s %s" % (verb, preposition) verb_object = noun2 if not assistantdb.parse(verb.lower(), verb_object.lower(), noun2.lower(), verb2.lower(), adjective.lower()): speech.speak('Sorry, I don\'t understand what you want.', True)
def run(self): say('How can I help you?') while 1: self.label.show_listening() voice_data = listen(self.label.show_processing) self.execute(voice_data, self.root) time.sleep(5)
def Integrate(optional_message=None): import CoreNLP if optional_message: sentence = optional_message print "Text input provided: '" + optional_message + "'" else: greeting_str = 'Hi ' + settings.username.capitalize() greeting_str += '! What can I help you with?' speech.speak(greeting_str, True) (success, sentence) = speech.listen() if not success: speech.speak(sentence, True) exit() # CoreNLP is weird, need to replace some stuff to make it properly recognize short sentences sentence = sentence.replace("Start", "start").replace("open", "Open").replace( "Please", "").replace("please", "") # Call NLP parsing function (verb, verb_object, noun2, verb2, preposition, adjective) = CoreNLP.Parse(sentence) # Fix some more edge cases with broken sentences if not verb: verb, verb_object = CoreNLPFail(sentence) # TODO: Eventually we should probably not attach the preposition to the verb (does it actually improve accuracy?) if preposition: verb = "%s %s" % (verb, preposition) verb_object = noun2 if not assistantdb.parse(verb.lower(), verb_object.lower(), noun2.lower(), verb2.lower(), adjective.lower()): speech.speak('Sorry, I don\'t understand what you want.', True)
def indextest(): answer = 'test' imgurl = '' question = '' if request.method == 'GET': return { 'question': question, 'answer': answer, 'imgurl': imgurl, 'state': 2 } # !state=2第一次前端判断 elif request.method == 'POST': f = request.files['upfile'] with open('audio.wav', 'wb') as audio: f.save(audio) question = listen() if '中国' or '疫情' in question: answer = '' imgurl = './img/chinese_map.png' return { 'question': question, 'answer': answer, 'imgurl': imgurl, 'state': 2 } # state=4 将返回的地址处理成图片 if '世界' and '确诊' in question: answer = '' imgurl = './img/world.png' return { 'question': question, 'answer': answer, 'imgurl': imgurl, 'state': 2 } # else: # 进行一问一答 # answer = handler.chat_main(question) # 接口1产生的answer(未return) # imgurl = '' # if answer == "这个问题知识库中暂时没有,请查看用户问答库中有没有您要问的问题": # return {'answer': answer,'imgurl':imgurl, 'state':2} # 1代表跳转接口2 # else: # 机器可以回答 # answer=answer+'\n可以解决你的问题吗?' # imgurl = '' # return {'answer': answer, 'imgurl':imgurl,'state':2} # !state=2第一次前端判断 # # 前端判断 用户输入可以或不可 可以输出感谢您的提问 不可以跳转接口2 return { 'question': question, 'answer': answer, 'imgurl': imgurl, 'state': 2 } # !state=2第一次前端判断
def recieve(): return 'yes' x = random.randint(0, 1) if (x == 0): return 'no' else: return 'yes' time.sleep(5) tts('Hello') #play() time.sleep(2) data = listen() time.sleep(2) return data
def openTab(): '''Opens tab when whole hand visible''' import webbrowser import speech print('Open') website = speech.listen().strip().split(' ') url = '' if(('Google' in website[0] or 'google' in website[0]) and len(website)>1): url += 'https://www.google.com/search?q=' for words in range(1,len(website)): url += website[words] url += ' ' elif(len(website)>1): for words in website: url += website else: url += 'https://www.' + website[0] + '.com' print('link is:',url) webbrowser.open_new_tab(url)
def location(root): say('What place do you want to find?') search = listen() url = 'https://google.nl/maps/place/' + search + '/&' webbrowser.get().open(url) return 'I think this is the place.'
def search(root): say('What do you want me to look up?') search = listen() url = 'https://google.com/search?q=' + search webbrowser.get().open(url) return f'This is what I found on {search}.'