def name_error(q): try: import main if main.run == True: import recorder main.voice_data = recorder.records_audio("", q) if main.person_says(["quit", "no", "nope", "nah"]): counts = 0 elif main.person_says(["play", "yes", "sure", "okay", "ok"]): change_name(q) counts = 0 else: counts += 1 if counts < 3: name_error(q) else: counts = 0 else: pass except Exception: counts = 0
def error(q): try: if main.run == True: import main import recorder main.voice_data = recorder.records_audio("", q) if main.person_says(["quit", "no", "nope", "nah"]): count = 0 elif main.person_says(["play", "yes", "sure", "okay", "ok"]): count = 0 core(q) else: count += 1 if count < 3: error(q) else: count = 0 else: pass except Exception: count = 0
def definitions(q): if main.run == True or main.crun == True: import recorder if main.person_says(["what is"]) and 'definition' not in main.voice_data and 'definitions' not in main.voice_data: search_term = main.voice_data.split("what is")[-1] search_term = search_term.replace('is', ' ') wiki_search(search_term, q) elif main.person_says(["definition of", "definitions of"]): search_term = main.voice_data.split("of")[-1] wiki_search(search_term, q) elif main.person_says(["definition for", "definitions for"]): search_term = main.voice_data.split("for")[-1] wiki_search(search_term, q) else: if main.run == True: definition=recorder.record_audio("What do you need the definitions of? Please tell me the word again.") search_term = main.voice_data wiki_search(search_term, q) else: pass else: pass
def core(q): import main if main.run == True: import speaker import recorder moves = ["rock", "paper", "scissor"] pmoves = ["rock", "paper", "scissor", "caesar", "peppa"] main.voice_data = recorder.record_audio( "Choose among rock, paper or scissor:", q) if main.voice_data not in pmoves: q.put(main.asis_obj.name + ": " + "Sorry I did not understand. Would you like to try again?" + "\n") speaker.speech_output( "Sorry I did not understand. Would you like to try again?") error(q) else: import random cmove = random.choice(moves) pmove = main.voice_data pmove = name_check(pmove) q.put(main.asis_obj.name + ": " + "You chose " + pmove + "\n") speaker.speech_output("You chose " + pmove) q.put(main.asis_obj.name + ": " + "I chose " + cmove + "\n") speaker.speech_output("I chose " + cmove) if pmove == cmove or (pmove == "peppa" and cmove == "paper") or ( pmove == "caesar" and cmove == "scissor"): q.put( main.asis_obj.name + ": " + "The match is draw. Haha. We both are out of luck today." + "\n") speaker.speech_output( "The match is draw. Haha. We both are out of luck today.") elif pmove == "rock" and cmove == "scissor": q.put(main.asis_obj.name + ": " + "Scissor crushes rock. You won " + main.person_obj.name + "! You are quite lucky today." + "\n") speaker.speech_output("Scissor crushes rock. You won " + main.person_obj.name + "! You are quite lucky today.") elif pmove == "rock" and cmove == "paper": q.put(main.asis_obj.name + ": " + "Paper beats rock. You lost " + main.asis_obj.name + ". Sorry, " + main.person_obj.name + ", I am luckier than you today!" + "\n") speaker.speech_output("Paper beats rock. You lost " + main.asis_obj.name + ". Sorry, " + main.person_obj.name + ", I am luckier than you today!") elif (pmove == "paper" or pmove == "peppa") and cmove == "rock": q.put(main.asis_obj.name + ": " + "Paper beats rock. You won " + main.person_obj.name + "! Looks like someone is luckier today!" + "\n") speaker.speech_output("Paper beats rock. You won " + main.person_obj.name + "! Looks like someone is luckier today!") elif (pmove == "paper" or pmove == "peppa") and cmove == "scissor": q.put(main.asis_obj.name + ": " + "Scissor cuts paper. You lost " + main.asis_obj.name + "! I hope i did not play you out. hehe." + "\n") speaker.speech_output("Scissor cuts paper. You lost " + main.asis_obj.name + "! I hope i did not play you out. hehe.") elif (pmove == "scissor" or pmove == "caesar") and cmove == "paper": q.put(main.asis_obj.name + ": " + "Scissor cuts paper. You're the winner " + main.person_obj.name + ". Aha! You're awesome." + "\n") speaker.speech_output( "Scissor cuts paper. You're the winner " + main.person_obj.name + ". Aha! You're awesome.") elif (pmove == "scissor" or pmove == "caesar") and cmove == "rock": q.put(main.asis_obj.name + ": " + "Scissor crushes rock. I'm the winner " + main.asis_obj.name + "! I love rock and roll! Haha" + "\n") speaker.speech_output("Scissor crushes rock. I'm the winner " + main.asis_obj.name + "! I love rock and roll! Haha") main.voice_data = recorder.records_audio( "Do you want to play again?", q) if main.person_says(["quit", "no", "nope", "nah"]): pass elif main.person_says(["play", "yes", "sure", "okay", "ok"]): core(q) else: q.put( main.asis_obj.name + ": " + "Sorry I did not understand. Would you like to try again?" + "\n") speaker.speech_output( "Sorry I did not understand. Would you like to try again?") error(q) else: pass
def youtube_search(q): try: if main.run == True or main.crun == True: if main.person_says (["on youtube"]): if main.person_says(["of"]): search = main.voice_data.split("of")[-1] search_term = " ".join(search.split("on youtube") [0:]) elif main.person_says(["for"]): search = main.voice_data.split("for")[-1] search_term = " ".join(search.split("on youtube") [0:]) elif main.person_says(["play"]): search = main.voice_data.split("play")[-1] search_term = " ".join(search.split("on youtube") [0:]) else: if main.person_says(["search"]): search = main.voice_data.split("search")[-1] search_term = " ".join(search.split("on youtube") [0:]) else: search = " ".join(main.voice_data.split(" ")[0:]) search_term = " ".join(search.split("on youtube") [0:]) elif main.person_says (["in youtube"]): if main.person_says(["of"]): search = main.voice_data.split("of")[-1] search_term = " ".join(search.split("in youtube") [0:]) elif main.person_says(["for"]): search = main.voice_data.split("for")[-1] search_term = " ".join(search.split("in youtube") [0:]) elif main.person_says(["play"]): search = main.voice_data.split("play")[-1] search_term = " ".join(search.split("in youtube") [0:]) else: if main.person_says(["search"]): search = main.voice_data.split("search")[-1] search_term = " ".join(search.split("in youtube") [0:]) else: search = " ".join(main.voice_data.split(" ")[0:]) search_term = " ".join(search.split("in youtube") [0:]) else: if main.person_says(["of"]): search_term = main.voice_data.split("of")[-1] search_term = search_term.replace('youtube', ' ') elif main.person_says(["for"]): search_term = main.voice_data.split("for")[-1] search_term = search_term.replace('youtube', ' ') else: if main.person_says(["search"]): search = main.voice_data.split("search")[-1] search_term = " ".join(search.split(" ") [0:]) search_term = search_term.replace('youtube', ' ') else: search = " ".join(main.voice_data.split(" ")[0:]) search_term = " ".join(search.split(" ") [0:]) search_term = search_term.replace('youtube', ' ') if search_term != '': url = search_term webbrowser.get().open("https://www.youtube.com/results?search_query=" + url) q.put(main.asis_obj.name + ": " + "Here is what I found for " + search_term + " on youtube" + "\n") speaker.speech_output("Here is what I found for " + search_term + " on youtube") ask_playback(url,q) else: speaker.speech_output("Sorry, I got confused in your search query. For example, you can ask me 'search for banana on youtube'") else: pass except Exception: speaker.speech_output("Sorry, I did not understand what search you wanted. For example, you can ask me 'search for politics on youtube'")
def ask_playback(urls, q): if main.run == True: url = str(urls) main.voice_data = recorder.record_audio("Let me know if you like me to play any video from the search results?",q) #print("Voice data is: " + str(main.voice_data)) if main.person_says(["first", "1", "one", "1st", "start", "yes", "sure", "yep", "yeah", "any", "okay", "ok"]): watchvideo(url, 0, q) elif main.person_says(["second", "2", "two", "2nd"]): watchvideo(url, 1, q) elif main.person_says(["third", "3", "three", "3rd"]): watchvideo(url, 2, q) elif main.person_says(["fourth", "4", "four", "4th"]): watchvideo(url, 3, q) elif main.person_says(["fifth", "5", "five", "5th"]): watchvideo(url, 4, q) elif main.person_says(["sixth", "6", "six", "6th"]): watchvideo(url, 5, q) elif main.person_says(["seventh", "7", "seven", "7th"]): watchvideo(url, 6, q) elif main.person_says(["eighth", "8", "eight", "8th"]): watchvideo(url, 7, q) elif main.person_says(["ninth", "9", "nine", "9th"]): watchvideo(url, 8, q) elif main.person_says(["tenth", "10", "ten", "10th"]): watchvideo(url, 9, q) elif main.person_says(["eleventh", "11", "eleven", "11th"]): watchvideo(url, 10, q) elif main.person_says(["No", "nope", "sorry", "Nah", "quit"]): q.put(main.asis_obj.name + ": " + "Okay!" + "\n") speaker.speech_output("Okay!") else: q.put(main.asis_obj.name + ": " + "Sorry, I could not grasp what you meant." + "\n") speaker.speech_output("Sorry, I could not grasp what you meant.") else: pass
def price_search(q): try: if main.run == True or main.crun == True: if main.person_says (["on google"]): if main.person_says(["of"]): search = main.voice_data.split("of")[-1] search_term = " ".join(search.split("on google") [0:]) search_term = search_term.replace('price', ' ') elif main.person_says(["for"]): search = main.voice_data.split("for")[-1] search_term = " ".join(search.split("on google") [0:]) search_term = search_term.replace('price', ' ') else: if main.person_says(["search"]): search = main.voice_data.split("search")[-1] search_term = " ".join(search.split("on google") [0:]) search_term = search_term.replace('price', ' ') else: search = " ".join(main.voice_data.split(" ")[0:]) search_term = " ".join(search.split("on google") [0:]) search_term = search_term.replace('price', ' ') elif main.person_says (["in google"]): if main.person_says(["of"]): search = main.voice_data.split("of")[-1] search_term = " ".join(search.split("in google") [0:]) search_term = search_term.replace('price', ' ') elif main.person_says(["for"]): search = main.voice_data.split("for")[-1] search_term = " ".join(search.split("in google") [0:]) search_term = search_term.replace('price', ' ') else: if main.person_says(["search"]): search = main.voice_data.split("search")[-1] search_term = " ".join(search.split("in google") [0:]) search_term = search_term.replace('price', ' ') else: search = " ".join(main.voice_data.split(" ")[0:]) search_term = " ".join(search.split("in google") [0:]) search_term = search_term.replace('price', ' ') else: if main.person_says(["of"]): search_term = main.voice_data.split("of")[-1] search_term = search_term.replace('price', ' ') elif main.person_says(["for"]): search_term = main.voice_data.split("for")[-1] search_term = search_term.replace('price', ' ') else: if main.person_says(["search"]): search = main.voice_data.split("search")[-1] search_term = " ".join(search.split(" ") [0:]) search_term = search_term.replace('price', ' ') else: search_term = main.voice_data.split(" ")[0:] search_term = search_term.replace('price', ' ') if search_term != '': google_url = "https://google.com/search?q=" + "price+"+ "of+" + search_term webbrowser.get().open(google_url) q.put(main.asis_obj.name + ": " + "Here is what I found for price of " + search_term + " on google" + "\n") speaker.speech_output("Here is what I found for price of " + search_term + " on google") else: q.put(main.asis_obj.name + ": " + "Sorry, I got confused in your search query. For example, you can ask me 'search for price of banana'" + "\n") speaker.speech_output("Sorry, I got confused in your search query. For example, you can ask me 'search for price of banana'") else: pass except Exception: q.put(main.asis_obj.name + ": " + "Sorry, I did not understand what search you wanted. For example, you can ask me 'search for price of banana'" + "\n") speaker.speech_output("Sorry, I did not understand what search you wanted. For example, you can ask me 'search for price of banana'")
def response(voice_data, q, n): try: import main if main.run == True or main.crun == True: import random #used for random import speaker # 1: greeting and convos if main.person_says(["hey","hi","hello"]): counters() greeting = ["hey, how can I help you " + main.person_obj.name, "hey, what's up? " + main.person_obj.name, "I'm listening " + main.person_obj.name, "how can I help you? " + main.person_obj.name, "hello " + main.person_obj.name] greet = greeting[random.randint(0,len(greeting)-1)] q.put(main.asis_obj.name + ": " + greet + "\n") speaker.speech_output(greet) elif main.person_says(["good morning","good evening","good afternoon","good noon", "goodnight"]): counters() import times times.greeter(q) elif main.person_says(["how are you","what's up"]): counters() treating = ["I am doing great, " + main.person_obj.name + ". How are you?", "I am fine, " + main.person_obj.name + ". What about you?", "I'm listening to you, " + main.person_obj.name + ". Do you need some help?"] treat = treating[random.randint(0,len(treating)-1)] q.put(main.asis_obj.name + ": " + treat + "\n") speaker.speech_output(treat) elif main.person_says(["you're nice", "fine", "i'm good", "thank you", "thanks", "thankyou", "alright"]): counters() replying = ["That's nice to hear.", "I am happy to hear that.", "I am glad to hear that."] reply = replying[random.randint(0,len(replying)-1)] q.put(main.asis_obj.name + ": " + reply + "\n") speaker.speech_output(reply) elif main.person_says(["joke","jokes", "make me laugh"]): counters() replying = ["Why don't scientists trust atoms? Because........ they make up everything! hehe", "Why doesn't the sun go to college? ..... Because it has a million degrees! buhahaha", "I have many jokes about unemployed people..... sadly none of them work. lol", "What do you call a singing laptop?...... Its A Dell!", "Some people think prison is one word......... but to robbers it's the whole sentence.", "Why couldn't the leopard play hide and seek?...............Because he was always spotted. lol", "I needed a password eight characters long..............So I picked Snow White and the Seven Dwarves. Buhahaha"] reply = replying[random.randint(0,len(replying)-1)] q.put(main.asis_obj.name + ": " + reply + "\n") speaker.speech_output(reply) # 2: naming each other and name changes elif main.person_says(["what is your name","what's your name","tell me your name"]): counters() import names names.chatbot_name(q) elif main.person_says(["what is my name","what's my name","tell me my name"]): counters() import names names.user_name(q) elif main.person_says(["change my name"]): counters() import names names.change_name(q) # 3: quitting program elif main.person_says(["exit", "quit", "goodbye", "bye", "bye bye"]): counters() q.put(main.asis_obj.name + ": " + "Bye! I will miss you! " + main.person_obj.name + "\n") speaker.speech_output("Bye! I will miss you! " + main.person_obj.name) import sys #used for exiting the program try: sys.exit(0) except SystemExit as e: sys.exit(e) # 4: ask time elif main.person_says(["what's the time", "what is the time", "what is current time", "tell me the time","what time"]): counters() import times times.time_speaker(q) elif main.person_says(["what's the date", "what is the date", "what is today's adte", "tell me the date","what date"]): counters() import times times.date_speaker(q) # 5: search google elif main.person_says(["search for", "search"]) and 'youtube' not in main.voice_data and 'weather' not in main.voice_data and 'price' not in main.voice_data: counters() import search search.google_search(q) # 6: search youtube elif main.person_says(["youtube"]): counters() import search search.youtube_search(q) #7 rock paper scisorrs elif main.person_says(["game"]) and n == 1: counters() import game game.game_rps(q) #8 screenshot elif main.person_says(["capture my screen","screenshot"]): counters() import pyautogui #used for screenshot myScreenshot = pyautogui.screenshot() myScreenshot.save('D:/screen.png') speaker.speech_output("The screen has been captured and placed in drive D as screen.png") #9 calculation elif main.person_says(["plus","minus","multiply","divide","power","+","-", "x", "*","/", "add", "subtract"]): counters() import calc calc.calculate(q) #10: search prices of items elif main.person_says(["price of", "price for", "price"]): counters() import search search.price_search(q) #11 weather elif main.person_says(["weather"]): counters() import search search.weather_search(q) #12 definitions elif main.person_says(["definition", "definitions", "what is"]): counters() import search search.definitions(q) #13 Go background elif main.person_says(["go to background", "goto background", "go background"]): counters() import background import speaker q.put(main.asis_obj.name + ": " + "I'm going background. Call my name if you need help." + "\n") speaker.speech_output("I'm going background. Call my name if you need help.") main.brun = True background.background_loop(q) #14 opening apps elif main.person_says(["app", "application"]): counters() import apps apps.open_app() #15 play songs elif main.person_says(["sing me a song", "play a song", "play song"]): counters() from playsound import playsound playsound('song/song.mp3') else: if main.error_count0 == main.error_count: main.empty_count += 1 #print("RE Non-Related = " + str(main.empty_count)) if main.empty_count > 3: counters() import speaker q.put(main.asis_obj.name + ": " + "I'm going background. Call my name if you need help." + "\n") speaker.speech_output("I'm going background. Call my name if you need help.") import background main.brun = True background.bg_play(q) main.error_count0 = main.error_count except: pass