Example #1
0
def checkForWord(recognizer, audio):
    try:
        wordCheck = recognizer.recognize_google(audio)
        print(wordCheck)
        if wordCheck == "hey my":
            My = True
            
            MyMain()
        elif wordCheck == "ok my" or wordCheck=="okay my" or wordCheck=="o. k. my":
            My = True
            MyMain()
        elif wordCheck == "hey mike" or wordCheck=="hey Mike":
            My = True
            MyMain()
        elif wordCheck == "o. k. why" or wordCheck=="okay why":
            My = True
            MyMain()
        elif wordCheck == "o. k. mind" or wordCheck=="okay mind":
            My = True
            MyMain()
        elif wordCheck == "okay Mike" or wordCheck=="ok Mike" or wordCheck=="o. k. Mike" or wordCheck=="okay mike":
            My = True
            MyMain()
        elif wordCheck == "pay my":
            My = True
            MyMain()
        elif wordCheck == "hate my":
            My = True
            MyMain()
        elif wordCheck == "paymaya":
            My = True
            MyMain()
        elif wordCheck == "wake up my":
            My = True
            MyMain()
        elif wordCheck == "wake up Mike":
            My = True
            MyMain()
        elif wordCheck == "yo My" or wordCheck=="yo my" or wordCheck=="Yo My" or wordCheck=="Yo my":
            My = True
            MyMain()
        elif wordCheck == "stop":
           global stopwatch
           if stopwatch == True:
              global stopwatchTime
              stopwatch == False
              tts.say("Time: " + str(stopwatchTime) + "seconds")
              stopwatchTime = 0
              
    except sr.UnknownValueError:
        print("I cannot understand you! Try again! If I don't understand you anymore, try to power me off!")
    except sr.RequestError as e:
        print("Recognition failed; {0}".format(e))
Example #2
0
def Timer(seconds):
   global timer
   global timerTime
   timerTime = seconds
   while timer==True:
      time.sleep(1)
      timerTime = timerTime - 1
      print(timerTime)
      print(timer)
      if timerTime == 0:
         tts.say("Stop!")
         timer = False
Example #3
0
def yesOrNo(toAsk):
    with sr.Microphone() as source:
        playsound('media/beep_my.wav')
        print("I'm listening!")
        audio = r.listen(source)
    recognition = r.recognize_google(audio)
    tts.say(toAsk)
    if recognition=="yes":
        My = False
        return "yes"
    else:
        My = False
        return "no"
Example #4
0
def PickANumberGame(number, trial):  # Currently defective - still in production
   with sr.Microphone() as source:
      playsound('media/beep_my.wav')
      print("I'm listening!")
      audio = r.listen(source)
   recognition = r.recognize_google(audio)
   query = recognition
   stopwords = ['is','the','number','it']
   querywords = query.split() 
   resultwords  = [word for word in querywords if word.lower() not in stopwords]
   result = ' '.join(resultwords)
   print(result)
   numberguess = strtoint.StrToInt(result)
   print(numberguess)
   print(number)
   if query == "tell me it":
      tts.say(number)
   if trial < 4:
      if numberguess == number:
         tts.say("You guessed!")
      else:
         
         redirectPickANumber(number, trial)
   else:
      tts.say("Oooof! That was hard. Number was " + str(number))
Example #5
0
def redirectPickANumber(number, trial):
   tts.say("Try again")
   PickANumberGame(number, trial+1)
Example #6
0
def MyMain():
    print("I'm listening!")
    with sr.Microphone() as source:
        playsound('media/beep_my.wav')
        print("I'm listening!")
        audio = r.listen(source)
    if (InternetMode==0):
        mymainr = r.recognize_sphinx(audio)
    elif (InternetMode==1):
        mymainr = r.recognize_google(audio)
    mymainr = mymainr.lower()
    print(mymainr)
    if mymainr=="how are you":
        print("I'm very good! How are you?")
        tts.say("I'm very good! How are you?")
        My = False
    elif mymainr=="do you like me":
        print("Sure! Why not?")
        tts.say("Sure! Why not?")
        My = False
    elif(mymainr=="do you like alexa" or mymainr=="do you like Alexa" or mymainr=="do you know alexa" or mymainr=="do you know Alexa" or
         mymainr=="do you like Siri" or mymainr=="do you like siri" or mymainr=="do you know siri" or mymainr=="do you know Siri" or
         mymainr=="do you like google assistant" or mymainr=="do you like Google assistant" or mymainr=="do you know google assistant" or mymainr=="do you know Google assistant"):
         
       tts.say("I pay respect to all of voice assistants. Being an voice assistant is not an easy job.")
    elif mymainr=="do you think I'm pretty":
        print("Sure you are!")
        tts.say("Sure you are!")
        My = False
    elif mymainr=="who let the dogs out" or mymainr=="who Let The Dogs Out":
        print("who, who, who, who, who")
        tts.say("who, who, who, who, who")
        My = False
    elif mymainr=="tell me a joke":
        joke = choice(jokelist)
        print(joke)
        tts.say(joke)
        My = False
    elif mymainr=="sing me a lullaby" or mymainr=="play me a lullaby":
        playsound("media/lullaby.wav")
        My = False
    elif mymainr=="sing my favorite song" or mymainr=="play my favorite song":
        playsound("media/favorite.mp3")
        My = False
    elif mymainr=="am I funny":
        tts.say("Sure you are!")
        My = False
    elif mymainr=="who created you" or mymainr=="who designeed you":
        tts.say("I was designed by MyTja Team.")
        My = False
    elif mymainr=="when were you published" or mymainr=="when were you created":
        tts.say("My first software release came out on second of May 2020")
        My = False
    elif mymainr=="how to check for updates":
        tts.say("Reboot me or say check for updates!")
        My = False
    elif mymainr=="what's your favorite drink":
        tts.say("Electricity.")
        My = False
    elif mymainr=="version":
        tts.say(version)
        My = False
    elif mymainr=="what's your favorite food" or mymainr=="what is your favorite food":
        tts.say("I like pizza.")
        My = False
    elif mymainr=="go to offline mode":
        tts.say("Going to offline mode.")
        recognitionMode(0)
        My = False
    elif mymainr=="go to online mode":
        tts.say("Going to online mode.")
        recognitionMode(1)
        My = False
    elif mymainr=="power off" or mymainr=="shutdown" or mymainr=="shut down":
        os.system("sudo poweroff")
    elif mymainr=="reboot":
        os.system("sudo reboot")
    elif mymainr=="check for updates" or mymainr=="check for system updates" or mymainr=="update" or mymainr=="update your software":
        uccheck = uc.checkForVersion("stable", version)
        for item in uccheck:
           updateAvaiable = item["update"]
           desc = item["description"]
        if (updateAvaiable=="y"):
           assembly = "There is a new release avaiable" + str(description) + "Would you like to install it"
           yn = yesOrNo(assembly)
           if (yn == "yes"):
              tts.say("Okay! Let's do it!")
              os.system("cd /home/pi/Desktop/ && ./updater")
              kill-this-process() #this kills the process of My, because this function doesn't exist
           else:
              tts.say("Okay, aborting mission")
        My = False
    elif mymainr=="higher volume" or mymainr=="louder" or mymainr=="volume up":
        os.system("cd /home/pi/Desktop/ && vol +")
        tts.say("Okay")
        My = False
    elif mymainr=="lower volume" or mymainr=="quieter" or mymainr=="volume down":
        os.system("cd /home/pi/Desktop/ && vol -")
        tts.say("Okay")
        My = False
    elif mymainr=="medium volume":
        os.system("cd /home/pi/Desktop/ && vol 50")
        tts.say("Okay")
        My = False
    elif mymainr=="minimum volume" or mymainr=="minimum":
        os.system("cd /home/pi/Desktop/ && vol 0")
        tts.say("Okay")
        My = False
    elif mymainr=="maximum volume" or mymainr=="maximum":
        os.system("cd /home/pi/Desktop/ && vol 100")
        tts.say("Okay")
        My = False
    elif mymainr=="what's the time" or mymainr=="what is the time":
       lt = time.localtime()
       lth = lt.tm_hour
       ltm = lt.tm_min
       tts.say("It's " + str(lth) + "and" + str(ltm) + "minutes.")
    elif mymainr=="what's the date":
       lt = time.localtime()
       lty = lt.tm_year
       ltmon = lt.tm_mon
       ltday = lt.tm_mday
       ltdayofweek = lt.tm_wday
       print(ltdayofweek)
       th = ""
       if (ltday=="21"):
          th = "twentyfirst"
       elif (ltday=="1"):
          th = "first"
       elif (ltday=="31"):
          th = "thirtyfirst"
       elif (ltday=="22"):
          th = "twentysecond"
       elif (ltday=="2"):
          th = "second"
       elif (ltday=="23"):
          th = "thirtythird"
       elif (ltday=="3"):
          th = "third"
       elif (ltday=="5"):
          th = "fifth"
       elif (ltday=="15"):
          th = "fifteenth"
       elif (ltday=="25"):
          th = "twentyfifth"
       elif (ltday=="30"):
          th = "thirtieth"
       elif (ltday=="20"):
          th = "twentieth"
       else:
          th = str(ltday) + "th"
          
       tts.say("It's " + daysOfTheWeek[ltdayofweek] + th + "Of" + monthsOfTheYear[ltmon-1] + str(lty))
    elif mymainr=="set the stopwatch" or mymainr=="set a stopwatch" or mymainr=="stopwatch":
       StopwatchStartup()
    elif mymainr=="stop":
       global playerOnline
       global stopwatch
       if (stopwatch==True):
          stopwatch = False
          tts.say("Time (in seconds): " + str(stopwatchTime))
       if (playerOnline==True):
          player.stop()
          playerOnline = False
    elif mymainr=="pause":
       #global playerOnline
       if (playerOnline==True):
          player.pause()
          playerOnline = False
    elif mymainr=="continue":
       #global playerOnline
       if (playerOnline==False):
          player.play()
          playerOnline = True
    elif mymainr == "pick a number":
       PickANumberGame(randint(0, 10), 1)
    elif mymainr=="countdown":
       Countdown()
    else:
        query = mymainr
        stopwords = ['what','who','is','a','at','is','he', "who's", "what's", "the", "weather", "in", "like", "plus", "minus", "divided by", "times", "+", "-", "are", "play", "set the alarm at", "set alarm at", "set an alarm at", "set stopwatch", "set the timer for", "set", "timer", "for"]
        querywords = query.split() 
        resultwords  = [word for word in querywords if word.lower() in stopwords]
        result = ' '.join(resultwords)
        print(result)
        
        if (result=="what is the weather like in" or result=="what's the weather like in"):
            resultwords  = [word for word in querywords if word.lower() not in stopwords]
            result = ' '.join(resultwords)
            print(result)
            observation = owm.weather_at_place(result)
            w = observation.get_weather()
            temperature = w.get_temperature('celsius')
            humidity = w.get_humidity()

            query = str(w)
            weatherstopwords = ["status=clouds,", "status=clear,"]
            weatherquerywords = query.split() 
            weatherresultwords  = [word for word in weatherquerywords if word.lower() in weatherstopwords]
            weather = ' '.join(weatherresultwords)
            finalweather = str(weather[7])+str(weather[8])+str(weather[9])+str(weather[10])+str(weather[11])+str(weather[12])
            print(weather)
            print(result)
            print(temperature)
            print(humidity)
            print(w)
            temp = temperature["temp"]
            print(temp)
            tts.say("Temperature in " + str(result) + "is" + str(temperature["temp"]) + "degrees celcius. There is a humidity of " + str(humidity) + "percent. It is" + str(finalweather))

        elif (result=="play" or result=="Play"):
            query = mymainr
            swords = ["play"]
            querywords = query.split()
            resultwords  = [word for word in querywords if word.lower() not in swords]
            result = ' '.join(resultwords)
            print(result)
            ytlinks = []
            textToSearch = result
            search = searchYoutube(textToSearch, offset = 1, mode = "dict", max_results = 1)
            result = search.result()["search_result"]
            for video in result:
               vid = video["link"]
            video = pafy.new(vid)
            best = video.getbest()
            playurl = best.url

            Instance = vlc.Instance()
            player = Instance.media_player_new()
            Media = Instance.media_new(playurl)
            Media.get_mrl()
            player.set_media(Media)
            playerOnline = True
            player.play()
            
               #tts.say("Please be more specific. Maybe tell me an author or something more.")
               
        elif (result=="set the alarm at" or result=="set alarm at" or result=="set an alarm at"):
           stopwords = ["o'clock", "oclock", "sharp", "set the alarm at", "set alarm at", "set an alarm at"]
           resultwords  = [word for word in querywords if word.lower() not in stopwords]
           result = ' '.join(resultwords)
           hoursstr = result[0:2]
           hoursalmostfinal = hoursstr.replace(":", "")
           minstr = result[2:4]
           finalresultm = strtoint.StrToInt(minstr)
           finalresulth = strtoint.StrToInt(hoursalmostfinal)
           
           if (len(alarm1) == 0):
              alarm1.append(finalresulth)
              alarm1.append(finalresultm)
           else:
              if (len(alarm2) == 0):
                 alarm2.append(finalresulth)
                 alarm2.append(finalresultm)
              else:
                 if (len(alarm3) == 0):
                    alarm3.append(finalresulth)
                    alarm3.append(finalresultm)
                 else:
                    tts.say("All my alarm capabilities are full.")
           
        elif result=="set the timer for" or result=="set a timer for":   # Timer
           stopwords = ["set the timer for", "set a timer for"]
           resultwords  = [word for word in querywords if word.lower() not in stopwords]
           result = ' '.join(resultwords)
           timestr = result[0:2]
           timesetstr = result[2:]
           if timesetstr=="hour" or timesetstr=="hours":
              if timestr[1] == " ":
                 timeint = strtoint.StrToInt(timestr[1])
                 timefinal = timeint * 60 * 60
                 TimerSetup(timefinal)
              else:
                 timeint = strtoint.StrToInt(timestr)
                 timefinal = timeint * 60 * 60
                 TimerSetup(timefinal)
           elif timesetstr=="minute" or timesetstr=="minutes":
              if timestr[1] == " ":
                 timeint = strtoint.StrToInt(timestr[1])
                 timefinal = timeint * 60
                 TimerSetup(timefinal)
              else:
                 timeint = strtoint.StrToInt(timestr)
                 timefinal = timeint * 60
                 TimerSetup(timefinal)
           elif timesetstr=="second" or timesetstr=="seconds":
              if timestr[1] == " ":
                 timeint = strtoint.StrToInt(timestr[1])
                 timefinal = timeint
                 TimerSetup(timefinal)
              else:
                 timeint = strtoint.StrToInt(timestr)
                 timefinal = timeint
                 TimerSetup(timefinal)
           elif timesetstr=="day" or timesetstr=="days":
              if timestr[1] == " ":
                 timeint = strtoint.StrToInt(timestr[1])
                 timefinal = timeint * 24 * 60 * 60
                 TimerSetup(timefinal)
              else:
                 timeint = strtoint.StrToInt(timestr)
                 timefinal = timeint * 24 * 60 * 60
                 TimerSetup(timefinal)

        else:
            resultwords  = [word for word in querywords if word.lower() not in stopwords]
            result = ' '.join(resultwords)
            print(result)
            
            try:
               summary = wikipedia.summary(result, sentences=1)
               filteredtext = wpfilter1.removeunwanted(summary)
               print(filteredtext)
               final = filteredtext.encode("utf8")
               print(summary)
               tts.say(str(final))
            except:
               tts.say("Sorry, but I cannot tell you that, because a bug in my code.")
Example #7
0
def StopwatchStartup():
   global stopwatch
   tts.say("5")
   time.sleep(1)
   tts.say("4")
   time.sleep(1)
   tts.say("3")
   time.sleep(1)
   tts.say("2")
   time.sleep(1)
   tts.say("1")
   time.sleep(1)
   tts.say("Start")
   stopwatch = True
   thread.start_new_thread(Stopwatch, ())
Example #8
0
def Countdown():
   tts.say("5")
   time.sleep(1)
   tts.say("4")
   time.sleep(1)
   tts.say("3")
   time.sleep(1)
   tts.say("2")
   time.sleep(1)
   tts.say("1")
   time.sleep(1)
   tts.say("Start")