|
| 1 | +from functions import savenote, speak, add, sub, mul, div, search_wiki, exit1, remind, playVideo, history |
| 2 | +from functions import wish, sendEmail, call, WinCalc, WinNotepad, recognize, saveTasks, search, openweb |
| 3 | +import datetime |
| 4 | +import tkinter as tk |
| 5 | +from tkinter import * |
| 6 | +from functions import playmusic |
| 7 | +import sqlite3 |
| 8 | + |
| 9 | + |
| 10 | +def button_function(): |
| 11 | + # speak("Hey ! {}, How may I help you?".format(ownerName)) |
| 12 | + query = recognize().lower() |
| 13 | + print(query) |
| 14 | + db = sqlite3.connect("{}.db".format(ownerName)) |
| 15 | + db.execute("CREATE TABLE IF NOT EXISTS history(user, command)") |
| 16 | + c = db.cursor() |
| 17 | + c.execute("INSERT INTO history(user, command) VALUES('{}', '{}')".format(ownerName, query)) |
| 18 | + db.commit() |
| 19 | + c.close() |
| 20 | + db.close() |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + if 'created' in query: |
| 25 | + speak("I was made by Tejas and Vedank.") |
| 26 | + |
| 27 | + elif 'owns' in query: |
| 28 | + speak("I am currently being owned by {}".format(ownerName)) |
| 29 | + |
| 30 | + elif 'exit' in query: |
| 31 | + mainWindow.destroy() |
| 32 | + exit1() |
| 33 | + elif 'quit' in query: |
| 34 | + mainWindow.destroy() |
| 35 | + exit1() |
| 36 | + |
| 37 | + elif 'plus' in query: |
| 38 | + add(query) |
| 39 | + elif 'add' in query: |
| 40 | + add(query) |
| 41 | + elif '+' in query: |
| 42 | + add(query) |
| 43 | + |
| 44 | + elif 'minus' in query: |
| 45 | + sub(query) |
| 46 | + elif 'subtract' in query: |
| 47 | + sub(query) |
| 48 | + elif '-' in query: |
| 49 | + sub(query) |
| 50 | + |
| 51 | + elif 'multiplied by' in query: |
| 52 | + mul(query) |
| 53 | + elif 'times' in query: |
| 54 | + mul(query) |
| 55 | + elif ' x ' in query: |
| 56 | + mul(query) |
| 57 | + elif ' into ' in query: |
| 58 | + mul(query) |
| 59 | + |
| 60 | + elif 'divided by' in query: |
| 61 | + div(query) |
| 62 | + elif '/' in query: |
| 63 | + div(query) |
| 64 | + |
| 65 | + elif 'the time' in query: |
| 66 | + strTime = datetime.datetime.now().strftime("%H:%M:%S") |
| 67 | + speak("The time is {}.".format(strTime)) |
| 68 | + elif 'time is it' in query: |
| 69 | + strTime = datetime.datetime.now().strftime("%H:%M:%S") |
| 70 | + speak("The time is {}.".format(strTime)) |
| 71 | + |
| 72 | + elif 'email' in query: |
| 73 | + try: |
| 74 | + speak("What is the receiver's email address?") |
| 75 | + # to = recognize() |
| 76 | + # newTo = to.replace(" ", "") |
| 77 | + # print(newTo) |
| 78 | + newTo = "tmandre3@gmail.com" |
| 79 | + speak("What should i say ?") |
| 80 | + content = recognize() |
| 81 | + message = (content + "\n\n\nThis email has been sent by {}'s virtual assistant.".format(ownerName)) |
| 82 | + sendEmail(newTo, message) |
| 83 | + speak("Email has been sent.") |
| 84 | + except Exception: |
| 85 | + speak("I'm sorry, failed to send the email.") |
| 86 | + |
| 87 | + elif 'who is' in query: |
| 88 | + search_wiki(query) |
| 89 | + |
| 90 | + elif 'call' in query: |
| 91 | + # new = [int(i) for i in query.split() if i.isdigit()] |
| 92 | + # call(new[0]) |
| 93 | + # speak("calling" + str(new[0])) |
| 94 | + speak("Calling Tejas.") |
| 95 | + call('9021343679') |
| 96 | + |
| 97 | + elif query == "take a note": |
| 98 | + speak("What should i note ?") |
| 99 | + text = recognize() |
| 100 | + speak("What is the title of the note ?") |
| 101 | + title = recognize() |
| 102 | + speak("Your note will be saved in a minute") |
| 103 | + savenote(text, title) |
| 104 | + |
| 105 | + elif "play" in query: |
| 106 | + query = query.replace("play", "") |
| 107 | + playmusic(query) |
| 108 | + elif query == "play music": |
| 109 | + speak("Let me know the name of the song you want to play") |
| 110 | + song = recognize() |
| 111 | + playmusic(song) |
| 112 | + |
| 113 | + elif "calculator" in query: |
| 114 | + WinCalc() |
| 115 | + |
| 116 | + elif "notepad" in query: |
| 117 | + WinNotepad() |
| 118 | + |
| 119 | + elif "remind me" in query or "add a task" in query: |
| 120 | + newq = query.replace("remind me to", "") |
| 121 | + saveTasks(newq) |
| 122 | + |
| 123 | + elif "reminders" in query: |
| 124 | + remind() |
| 125 | + |
| 126 | + elif "on youtube" in query: |
| 127 | + newq = query.replace("play", "") |
| 128 | + newq1 = newq.replace("on youtube", "") |
| 129 | + playVideo(newq1) |
| 130 | + |
| 131 | + elif "go to" in query: |
| 132 | + newq = query.replace("go to", "") |
| 133 | + new1 = newq.replace("dot com", "") |
| 134 | + openweb(new1) |
| 135 | + |
| 136 | + elif "history" in query: |
| 137 | + history(ownerName) |
| 138 | + |
| 139 | + else: |
| 140 | + browser = search(query) |
| 141 | + |
| 142 | + |
| 143 | + |
| 144 | +def voice(): |
| 145 | + |
| 146 | + speak("Hey! I am Lisa. I can help you with various tasks. Before that, I'd like to know your name." |
| 147 | + " What is your name?") |
| 148 | + |
| 149 | + global ownerName |
| 150 | + ownerName1 = recognize() |
| 151 | + ownerName = ownerName1.replace("my name is ", "") |
| 152 | + wishme = wish() |
| 153 | + speak("{} {}. Click the microphone button if you need any help.".format(wishme, ownerName)) |
| 154 | + introtext = "Hey! {} I am Lisa. Click the\nmicrophone" \ |
| 155 | + " button if you need\nany assistance.".format(ownerName) |
| 156 | + global db |
| 157 | + |
| 158 | + global mainWindow |
| 159 | + mainWindow = tk.Tk() |
| 160 | + mainWindow.title("LISA - virtual assistant.") |
| 161 | + mainWindow.geometry("305x417+500+200") |
| 162 | + mainWindow.iconbitmap("Mic_icon.ico") |
| 163 | + mainWindow.resizable(False, False) |
| 164 | + |
| 165 | + lisaLabel = tk.Label(mainWindow, text=introtext, font=("Comic Sans MS", 14), relief="solid", bg="black", |
| 166 | + fg="yellow", padx=18) |
| 167 | + lisaLabel.place(x=0, y=0) |
| 168 | + |
| 169 | + buttonImagePath = PhotoImage(file="1.png") |
| 170 | + micButton = tk.Button(mainWindow, height=300, width=300, command=button_function, image=buttonImagePath, bg='black') |
| 171 | + micButton.place(x=0, y=80) |
| 172 | + |
| 173 | + exitButton = tk.Button(mainWindow, text="EXIT", fg="yellow", bg="black", command=exit1, height=1, |
| 174 | + width=27, font=("Arial", 14)) |
| 175 | + exitButton.place(y=385, x=0) |
| 176 | + |
| 177 | + mainWindow.mainloop() |
0 commit comments