def voicecontrol (): if not ispaused: listening.recognition(stop, 'stop', False) else: listening.recognition(start, 'start', False)
def recognize_search(): # playsound = searchsound.play() # playsound.wait_done() print ('listening for phrase') with mic as source: audio = r.listen(source) response = { "success": True, "error": None, "text": None } try: response["text"] = r.recognize_google(audio) except sr.RequestError: response["success"] = False response["error"] = "unavailable" except sr.UnknownValueError: response["error"] = "unknown" if response['text']: phrase = response['text'].replace(" ", "_") print ('phrase: ' + phrase) if __name__ == "__main__": while (1): print ('listening for keyword projector') listening.recognition(recognize_search, 'projector')
def listen(function, keyword): print('listening for' + keyword) listening.recognition(function, keyword, True)
def playvideo(video_file): if raspi: # os.system('pkill chromium-browser') # video_cmd = 'chromium-browser --app=' + video_file + ' &' os.system('pkill omxplayer') video_cmd = 'omxplayer --loop ' + video_file + ' &' os.system(video_cmd) time.sleep(1) else: webbrowser.open(video_file) # Open CV imshow is throwing error when called not on the main thread. Trying omxplayer and chromium instead # cap = cv2.VideoCapture(video_file) # # while(cap.isOpened()): # ret, frame = cap.read() # # cv2.imshow('Lab Vibes',frame) # if cv2.waitKey(1) & 0xFF == ord('q'): # break # # cap.release() # cv2.destroyAllWindows() if __name__ == "__main__": while (1): print('listening for keyword projector') listening.recognition(recognize_phrase, 'bob')
import numpy as np import listening # import connect channel = connect.join() def heardfunction(): print('you said no') while (1): print('Do you want to purchase more of my goods?') # recognition takes a function that is called when keyword is head, the keyword, and if it should keep listening for the keyword moreGoods = listening.recognition(heardfunction, 'no', False) if moreGoods: # load image cap = cv2.VideoCapture('vid/wagon.avi', 0) while (cap.isOpened()): # read ret, img = cap.read() if ret: # resize img for transform img = cv2.resize(img, (16, 24), interpolation=cv2.INTER_NEAREST)
audio = r.listen(source) response = { "success": True, "error": None, "text": None } try: response["text"] = r.recognize_google(audio) except sr.RequestError: response["success"] = False response["error"] = "unavailable" except sr.UnknownValueError: response["error"] = "unknown" if response['text']: print ('search term: ' + response['text']) synonyms = [] for syn in wordnet.synsets(response['text']): for l in syn.lemmas(): synonyms.append(l.name()) print('synsets: ' + str(set(synonyms))) while (1): print ('listening for keyword') listening.recognition(recognize, 'search', False)