top of page

W.I.C.K: My Very Own A.I

Ever since J.A.R.V.I.S first appeared in the 2008 Iron Man, I have wanted an A.I. Now...

that dream has finally come true... kinda. After stumbling around a few A.I development softwares and ultimately failing at any progress, I decided that I would make my own. Now, after about 5 days of development: W.I.C.K Mark 1!!!


import pygame
import os.path
from os import path
from googlesearch import search 
import requests
import webbrowser
#gnu text-to-speech
from gtts import gTTS
import speech_recognition as sr  
import os
import datetime
import smtplib
import math
from random import randint

#speak the words

def textToSpeech(textInput, speechName):
    myText = textInput
    myobj = gTTS(text = textInput, lang = "en", slow = False)
    myobj.save(speechName)
    os.system("mpg321 " + speechName)

#receive the words
def speechInput():
    r = sr.Recognizer()
 try:
 with sr.Microphone() as source1:
            r.adjust_for_ambient_noise(source1, duration = 0.2)
            audio1 = r.listen(source1)
            mySpeech = r.recognize_google(audio1)
            mySpeech = mySpeech.lower()
 return mySpeech
 except sr.UnknownValueError:
 return("anonymous user")

def speechInput2():
    r = sr.Recognizer()
 try:
 with sr.Microphone() as source1:
            r.adjust_for_ambient_noise(source1, duration = 0.2)
            audio1 = r.listen(source1)
            mySpeech = r.recognize_google(audio1)
            mySpeech = mySpeech.lower()
            wordsList = mySpeech.split()
 return wordsList
 except sr.UnknownValueError:
 return["anonymous user"]

def searchGoogle(searchForWhat):
 for g in search (searchForWhat, tld = "com", num = 1, stop = 1, pause = 0):
        textToSpeech("would you like me to show you the contents?", "showContents.mp3")
        yesOrNo = speechInput()
 if yesOrNo == "yes":
            link = g
            webbrowser.open_new_tab(link)
 elif yesOrNo == "no":
 print(g)
 else:
            textToSpeech("huh?", "huh.mp3")

def weather():
    link = "https://weather.com/weather/today/l/30.00,-95.64?par=google&temp=f"
    webbrowser.open_new_tab(link)

def showMeMyEmails():
    link = "https://mail.google.com/mail/u/0/?pli=1#inbox"
    webbrowser.open_new_tab(link)

def showMeMyTexts():
    link = "https://hangouts.google.com/"
    webbrowser.open_new_tab(link)

def showMeARecipe():
    link = "https://www.google.com/search?q=how+do+I+make+food&oq=how+do+I+make+food&aqs=chrome.0.0l8.7494j0j7&sourceid=chrome&ie=UTF-8"
    webbrowser.open_new_tab(link)

def sendEmails(emailSubject, emailBody, recipient):
    emailAddress = os.environ.get("GMAIL_USERNAME")
    emailPassword = os.environ.get("GMAIL_PASSWORD")
    emailList = ["william", "mom", "dad"]
    emailListWith = ["will.choi.kim@gmail.com", "woonjungchoi@gmail.com", "dolchan@gmail.com"]
 if recipient in emailList:
 try:
            recipientOf = emailListWith[emailList.index(recipient)] 
 with smtplib.SMTP("smtp.gmail.com", 587) as smtp:
                smtp.ehlo()
                smtp.starttls()
                smtp.ehlo()

                smtp.login(emailAddress, emailPassword)

                subject = emailSubject
                body = emailBody

                msg = "fSubject: {subject}\n\n{body}"

                smtp.sendmail(emailAddress, recipientOf, msg)
 except smtplib.SMTPResponseException:
            textToSpeech("I can't seem to send that email...", "cantSend.mp3")   

 else:
        textToSpeech("I can't seem to send that email...", "cantSend.mp3")

def Hello():
    textToSpeech("Hello " + userName, "hello.mp3")

def Goodbye():
    textToSpeech("Goodbye " + userName, "goodbye.mp3")

def OpenFile():
    textToSpeech("which file would you like to open?", "openFile.mp3")
    fileName = speechInput2()
 if path.exists(fileName) == True:
        file_object = open(fileName, "r")
 print(file_object.read())
 else:
        textToSpeech("I'm sorry. I can't seem to find that file...", "noFile.mp3")

def singASong():
    songNumber = randint(0, 2)
    songList = ("hey.mp3" , "bensound-ukelele.mp3" , "bensound-happyrock.mp3")
    song = songList[songNumber]
 try:
        pygame.mixer.init()
        pygame.mixer.music.load(song)
        pygame.mixer.music.play()
        textToSpeech("Music credit: https://bensound.com", "musicCredit.mp3")
 except pygame.error:
        textToSpeech("I'm sorry. Something isn't right...", "cantPlayMusic.mp3")

def callMeStupid():
    textToSpeech("You're stupid...", "stupid.mp3")

def callMeSmart():
    textToSpeech("You're smart...", "smart.mp3")

def getTime():
    dateAndTime = datetime.datetime.now()
    textToSpeech("The current date and time is " + str(dateAndTime), "dateAndTime.mp3")

def tellAStory():
    storyNumber = randint(0, 2)

    storiesList = ["Once upon a time, there were three little pigs. These pigs were very happy, and one day set off to build a life of their own. However, each and every one of them was eaten by the wolf. THE END." , 
 "Once upon a time, Maguna went to sleep. The End." , 
 "Once upon a time, there lived an old witch at the end of a forest. The End."]

    story = storiesList[storyNumber]
    textToSpeech(str(story), "story.mp3")

def tellAJoke():
    jokeNumber = randint(0, 2)

    jokesList = ["What do you call a fish with no eye? ............... a fsh!",
 "What building in New York has the most stories? ................ the library!",
 "What is the worst dad joke you've ever heard? ................. this one!"]
 
    joke = jokesList[jokeNumber]
    textToSpeech(str(joke), "joke.mp3")    
 
def whatCanIDoForYou():
    keepListen = True
 while keepListen == True:
        inpUt = speechInput2()
 if "wick" in inpUt:
            runProgram = True
 while runProgram == True:
                textToSpeech("how can I help you?", "help.mp3")
                inpUt = speechInput2()
 if "file" in inpUt:
                    OpenFile()
 elif "hello" in inpUt or "hi" in inpUt or "hiya" in inpUt:
                    Hello()
 elif "song" in inpUt or "music" in inpUt or "sing" in inpUt:
                    singASong()
 elif "goodbye" in inpUt or "never" in inpUt or "end" in inpUt or "stop" in inpUt:
                    Goodbye()
                    runProgram = False
 elif "stupid" in inpUt:
                    callMeStupid()
 elif "smart" in inpUt:
                    callMeSmart()
 elif "search" in inpUt or "web" in inpUt:
                    textToSpeech("what would you like me to search?", "search.mp3")
                    searchTopic = speechInput()
                    searchGoogle(searchTopic)
 elif "today" in inpUt or "date" in inpUt or "time" in inpUt:
                    getTime()
 elif "send" and "email" in inpUt:
                    textToSpeech("who is the recipient?", "whatIsAddress.mp3")
                    recipient1 = speechInput()
                    textToSpeech("what would you like to send?", "sendWhat.mp3")
                    body1 = speechInput()
                    textToSpeech("what is the subject?", "subjectWhat.mp3")
                    subject1 = speechInput()
                    sendEmails(str(subject1), str(body1), str(recipient1))
 elif "text" in inpUt and "send" not in inpUt or "texts" in inpUt and "send" not in inpUt:
                    showMeMyTexts()
 elif "email" in inpUt and "send" not in inpUt or "emails" in inpUt and "send" not in inpUt:
                    showMeMyEmails()
 elif "story" in inpUt or "book" in inpUt:
                    tellAStory()
 elif "food" in inpUt or "recipe" in inpUt:
                    showMeARecipe()
 elif "joke" in inpUt:
                    tellAJoke()
 elif "weather" in inpUt:
                    weather()
 else:
                    textToSpeech("I'm sorry. I can't do that...", "sorry.mp3")
 elif "emergency" and "kill" in inpUt:
            keepListen = False


#run the code

textToSpeech("What should I call you sir or miss? Say nothing to stay anonymous", "callMe.mp3")
userName = speechInput()

Hello()

whatCanIDoForYou()                                                                            

While this may initially seem long, it actually isn't... for its capabilities. In this 223 line program (still relatively short), I have created an assistant that can search the internet, tell a few dad jokes, and tell some weird stories, usually consisting of only "Once upon a time" and "The End." Oh! Right! It can also tell you the weather, send an email, check your texts and emails, tell you the time to the exact 0.00001 second (literally), and call you smart... and stupid...:)


To run this code, you also need

pip install pygame 

or

sudo pip install pygame

also,


pip install googlesearch

or

sudo pip install googlesearch

as well as


pip install webbrowser

or

sudo pip install webbrowser

also,


pip install gtts

or

sudo pip install gtts

and


pip install speech_recognition

or

sudo pip install speech_recognition

That should be it!





 
 
 

Recent Posts

See All
The Effects of Social Media

The Ones Who Paved the Way (A Brief History) The Predecessors CompuServe This is CompuServe. It was the predecessor to the Internet. A...

 
 
 
The Asian-American Experience

Trade When the Mayflower docked at Cape Cod in November of 1620, European-Asian relations were strong. Due to a surge of Eurasian trade...

 
 
 

Comments


Post: Blog2_Post

©2020 by SparkBlog

bottom of page