示例#1
0
def listen_command():
    # This function helps in recognizing the command present in the audio file
    record(6)
    r = sr.Recognizer()  # initiating the recognizer
    voice = sr.AudioFile('output.wav')  # reading the audio file
    with voice as source:
        r.pause_threshold = 1.5  # amount of non-speaking time before the recorded voice to consider it as phase(chunk)
        r.energy_threshold = 690  # minimum amount of energy in voice to be considered as valid voice
        r.adjust_for_ambient_noise(source)
        audio = r.record(source)
        query = "null"
    try:
        print("Recognizing...")
        query = r.recognize_google(audio, language="en")
        print("user said:" + query)

    except sr.UnknownValueError:
        print("Sorry for the inconvenience, Can you say it again sir...")
        main.speak("Sorry for the inconvenience, Can you say it again sir...")
        return "null"

    except sr.RequestError:
        main.speak(
            "Sir your not connected to internet, so i cant process your request"
        )

    return query
示例#2
0
def weather_report(query):
    query = '+'.join(query).lower()
    if 'hey' in query:
        query = query.replace('hey', "")
    if 'jarvis' in query:
        query = query.replace('jarvis', "")
    base_url = "https://www.google.com/search?q="
    headers = {
        "User-Agent":
        'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/\
537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36'
    }
    URL = base_url + query
    page = requests.get(URL, headers=headers)
    soup = BeautifulSoup(page.content, 'html.parser')
    try:
        result = {}
        result['region'] = soup.find("div", attrs={"id": "wob_loc"}).text
        result['weather_now'] = soup.find("span", attrs={"id": "wob_dc"}).text
        result['temp_now'] = soup.find("span", attrs={"id": "wob_tm"}).text
        result['precipitation'] = soup.find("span", attrs={
            "id": "wob_p\
p"
        }).text
        result['humidity'] = soup.find("span", attrs={"id": "wob_hm"}).text
        result['wind'] = soup.find("span", attrs={"id": "wob_ws"}).text
        speak(f"Currently in {result['region']} its {result['temp_now']} d\
egrees with {result['weather_now']}, precipitation is\
 {result['precipitation']}, humidity is {result['humidity']} and windspeed is\
 {result['wind']}")
    except AttributeError:
        webbrowser.get('windows-default').open(URL)
示例#3
0
def mailValidition(name, mailAddress):
    while True:
        main.speak("Is it right mail?")
        mailVerification = takeCommand()
        if mailVerification == "yes":
            askToAddMailToList(name, mailAddress)
            sendEmail(name, mailAddress)
            break
        elif mailVerification == "no":
            emailVerification(name, mailAddress)
            break
        else:
            enterCorrestOperation()
示例#4
0
def mailValidition(name, mailAddress):
    while True:
        main.speak("Is it right mail?")
        mailVerification = input("Pleas type yes or no: ")
        if mailVerification == "yes":
            askToAddMailToList(name, mailAddress)
            sendEmail(name, mailAddress)
            break
        elif mailVerification == "no":
            emailVerification(name, mailAddress)
            break
        else:
            main.enterCorrestOperation()
示例#5
0
 def talk(self, text):
     if text == "" and self.talked:
         self.chatrec.append('EVA: {}'.format(
             str("Sorry, I didn't get that. Please try again.")))
         self.chatrec.repaint()
         speak("Sorry, I didn't get that. Please try again.")
         self.talked = False
         return
     elif text == "" and not self.talked:
         return
     self.chatrec.append("You: {}".format(text))
     output = str(chatbot(text))
     self.chatrec.append('EVA: {}'.format(output))
     self.textinput.setText("")
     self.chatrec.repaint()
     speak(output)
示例#6
0
def Email():

    try:

        main.speak("To whome you want me to send message?")
        name = input("Please enter recipient name: ")
        if config["EmailAddress"][name]:
            main.speak("this name is in your email address list")
            mailAddress = config["EmailAddress"][name]
            main.speak(f"the email address of {name} is {mailAddress}")
            sendEmail(name, mailAddress)
    except Exception as e:
        main.speak("this name is not in your email address list")
        main.speak(f"What is the mail address of {name}: ")
        mailAddress = input("=> ")
        main.mailValidition(name, mailAddress)
示例#7
0
def Email():

    try:

        main.speak("To whome you want me to send message?")
        name = takeCommand()
        if config["EmailAddress"][name]:
            main.speak("this name is in your email address list")
            mailAddress = config["EmailAddress"][name]
            main.speak(f"the email address of {name} is {mailAddress}")
            sendEmail(name, mailAddress)
    except Exception as e:
        main.speak("this name is not in your email address list")
        main.speak(f"What is the mail address of {name}: ")
        mailAddress = takeCommand()
        mailAddress = mailAddress.replace(" ", "")
        main.mailValidition(name, mailAddress)

###################################### Send Email ends here #################################
示例#8
0
def sendEmail(name, mailAddress):
    try:
        main.speak("please type a message: ")
        message = input("=> ")
        main.setupSMTPServer(mailAddress, message)
        main.speak(
            f"Your message has been send to {name} with email address {mailAddress}."
        )
    except Exception as e:
        print(e)
        main.speak("Sorry I am not abel to send email this time...")
示例#9
0
def sendEmail(name, mailAddress):
    try:
        main.speak("Ok,what's the message")
        message = takeCommand()
        main.setupSMTPServer(mailAddress, message)
        main.speak(
            f"Your message has been send to {name} with email address {mailAddress}."
        )
    except Exception as e:
        print(e)
        main.speak("Sorry I am not abel to send email this time...")
示例#10
0
def askToAddMailToList(name, mailAddress):
    while True:
        main.speak(
            f"Do you want me to add {name} Email address to your Email address list?"
        )
        addToList = takeCommand()
        if addToList == "yes":
            main.speak("Ok")
            main.addToMailList(name, mailAddress)
            break

        elif addToList == "no":
            main.speak("Ok sir as your wish.")
            break
        else:
            enterCorrestOperation()
示例#11
0
def askToAddMailToList(name, mailAddress):
    while True:
        main.speak(
            f"Do you want me to add {name} Email address to your Email address list?"
        )
        addToList = input("please type yes or no:")
        if addToList == "yes":
            main.speak("Ok")
            main.addToMailList(name, mailAddress)
            break

        elif addToList == "no":
            main.speak("Ok sir as your wish.")
            break
        else:
            main.enterCorrestOperation()
示例#12
0
def open_additional(query, query1):
    base_URL = "https://www.google.com/search?q="
    query2 = ('+'.join(query)).lower()
    speak("Searching for webpage")
    headers = {"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/\
537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36'}
    URL = base_URL + query2
    page = requests.get(URL, headers=headers)
    soup = BeautifulSoup(page.content, 'html.parser')
    results = soup.find_all("div", class_="g")
    for i in results:
        try:
            j = i.find("div", class_='r')
            site = j.find("a")['href']
            domain = urlparse(site).netloc
            if query1 in domain.lower():
                speak("Opening webpage")
                webbrowser.get('windows-default').open(site)
                exit()
        except AttributeError:
            pass
    speak("No results found sir")
    speak("Opening related search results in new tab")
    webbrowser.get('windows-default').open(URL)
示例#13
0
def enterCorrestOperation():
    main.speak("Please enter yes or no.")
示例#14
0
import wikipedia
import sys
from main import speak

query = ' '.join(sys.argv[1:])
print(query)
speak("Searching wikipedia")
results = wikipedia.summary(query, sentences=2)
speak(f"According to wikipedia...{results}")
示例#15
0
def dec_vol_to(n):
    speak("I  can't decrease volume yet, maybe you can teach me")
示例#16
0
def inc_vol():
    speak("I can't increase volume yet, maybe you can teach me")
示例#17
0
def sys_unmute():
    keyboard.press(Key.media_volume_mute)
    keyboard.release(Key.media_volume_mute)
    speak("System is unmuted")
示例#18
0
def get_volume():
    print(volume.GetMasterVolumeLevel())
    volLevel = convert(volume.GetMasterVolumeLevel())
    speak(f"Volume level is {volLevel} percent")
示例#19
0
def set_volume(n):
    if type(n) == int:
        volume.SetMasterVolumeLevel(n, None)
        speak(f"Volume is set to {n}")
    else:
        speak("Set volume attribute should be a number")
示例#20
0
def cmds():
    while True:

        query = main.takeCommand().lower()

        if "lumos" in query:
            query.replace("lumos", "")

            if 'wikipedia' in query:
                main.speak('Searching Wikipedia...')
                query = query.replace("wikipedia", "")
                results = wikipedia.summary(query, sentences=3)
                main.speak("According to Wikipedia")
                print(results)
                main.speak(results)

            elif 'open youtube' in query:
                main.speak("Here you go to Youtube\n")
                webbrowser.get('chrome').open("youtube.com")

            elif 'open google' in query:
                main.speak("Here you go to Google\n")
                codePath = r"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
                os.startfile(codePath)

            elif 'open discord' in query:
                main.speak("Here you go to discord\n")
                codePath = r"C:\\Users\\Username\\AppData\\Local\\Discord\\Update.exe"
                os.startfile(codePath)

            elif 'open spotify' in query:
                main.speak("Here you go to spotify\n")
                codePath = r"C:\\Users\\Username\\AppData\\Roaming\\Spotify\\spotify.exe"
                os.startfile(codePath)

            elif 'open stackoverflow' in query:
                main.speak("Here you go to Stack Over flow.Happy coding")
                webbrowser.get('chrome').open("stackoverflow.com")

            elif 'how are you' in query:
                main.speak("I am fine, Thank you")
                main.speak("How are you")

            elif 'fine' in query or "good" in query:
                main.speak("It's good to know that your fine")

            elif "change my name to" in query:
                query = query.replace("change my name to", "")
                assname = query
                main.speak('okay')

            elif "change name" in query:
                main.speak("What would you like to call me")
                assname = takeCommand()
                main.speak("Thanks for naming me")

            elif "what's your name" in query or "What is your name" in query:
                main.speak("My friends call me")
                speak(assname)
                print("My friends call me", assname)

            elif 'exit' in query:
                main.speak("Thanks for giving me your time")
                exit()

            elif "who made you" in query or "who created you" in query:
                main.speak("I have been created by Astroclad.")

            elif 'joke' in query:
                main.speak(pyjokes.get_joke())

            elif 'search' in query or 'play' in query:

                query = query.replace("search", "")
                query = query.replace("play", "")
                webbrowser.open(query)

            elif "who am i" in query:
                main.speak("If you talk then definately your human.")

            elif "why you came to world" in query:
                main.speak("Thanks to Astroclad. further It's a secret")

            elif 'is love' in query:
                main.speak("It is 7th sense that destroy all other senses")

            elif "who are you" in query:
                main.speak("I am your virtual assistant created by Astroclad")

            elif 'reason for you' in query:
                main.speak("I was created as a Minor project by Astroclad")

            elif 'shutdown system' in query:
                main.speak(
                    "Hold On a Sec ! Your system is on its way to shut down")
                subprocess.call('shutdown / p /f')

            elif 'empty recycle bin' in query:
                winshell.recycle_bin().empty(confirm=False,
                                             show_progress=False,
                                             sound=True)
                main.speak("Recycle Bin Emptied")

            elif "don't listen" in query or "stop listening" in query:
                main.speak(
                    "for how much time you want to stop lumos from listening commands"
                )
                a = int(takeCommand())
                time.sleep(a)
                print(a)

            elif "where is" in query:
                query = query.replace("where is", "")
                location = query
                main.speak("User asked to Locate")
                main.speak(location)
                webbrowser.open("https://www.google.nl / maps / place/" +
                                location + "")

            elif "restart" in query:
                subprocess.call(["shutdown", "/r"])

            elif "hibernate" in query or "sleep" in query:
                main.speak("Hibernating")
                subprocess.call("shutdown / h")

            elif "log off" in query or "sign out" in query:
                main.speak(
                    "Make sure all the application are closed before sign-out")
                time.sleep(5)
                subprocess.call(["shutdown", "/l"])

            elif "write a note" in query:
                main.speak("What should i write")
                note = takeCommand()
                file = open('lumosNotes.txt', 'w')
                main.speak("Should i include date and time")
                snfm = takeCommand()
                if 'yes' in snfm or 'sure' in snfm:
                    strTime = datetime.datetime.now().strftime("% H:% M:% S")
                    file.write(strTime)
                    file.write(" :- ")
                    file.write(note)
                else:
                    file.write(note)

            elif "show note" in query:
                main.speak("Showing Notes")
                file = open("lumosNotes.txt", "r")
                print(file.read())
                main.speak(file.read(6))

            elif "wikipedia" in query:
                webbrowser.get('chrome').open("wikipedia.com")

            elif "Good Morning" in query:
                main.speak("A warm" + query)
                main.speak("How are you ")
                main.speak(assname)

            # most asked question from google Assistant
            elif "how are you" in query:
                main.speak("I'm fine, glad you asked me that")

            elif "what is" or "who is" in query:
                main.speak('thinking')
                if "lumos" in query:
                    query = query.replace("lumos", "")
                    print(query)

                client = wolframalpha.Client("UK8JT2-ATP7JRHVYR")
                res = client.query(str(query))

                try:
                    print(next(res.results).text)
                    main.speak(next(res.results).text)
                except Exception:
                    print("No results")
                    main.speak("Im sorry, i dont know that one")
示例#21
0
文件: menu.py 项目: oaulakh/Mutter
def check():
    main.speak("How i can help You, Sir.")
    choice = main.recognize()
    if choice == "menu":
        print ("you are pass")
示例#22
0
def emailVerification(name, mailAddress):
    main.speak(f"Please type the mail address of {name} again:")
    mailAddress = input("=> ")
    main.mailValidition(name, mailAddress)
示例#23
0
def open_web(name, url):
    speak(f"Opening {name}")
    webbrowser.get('windows-default').open(url)
示例#24
0
def open_app(name, Dir):
    speak(f"Opening {name}")
    os.startfile(Dir)
示例#25
0
def emailVerification(name, mailAddress):
    main.speak(f"Please say the mail address of {name} again:")
    mailAddress = takeCommand()
    mailAddress = mailAddress.replace(" ", "")
    main.mailValidition(name, mailAddress)
示例#26
0
def wikipedia_query_handler():
    main.speak("Sir what do you want to search in wikipedia...")
    flag = 1
    try:
        while flag:
            search_request = recognize_voice.listen_command().lower()

            if "cancel" not in search_request and "null" not in search_request:
                # this blocks executes when a user tries to search about some information details in wikipedia
                search_result = wikipedia.summary(search_request, sentences=2)
                main.speak("According to wikipedia")
                main.speak(search_result)
                time.sleep(4)
                main.speak("Do you want to search anything else in wikipedia?")
                response = recognize_voice.listen_command().lower()
                if "no" in response:
                    # to terminate the loop from being asked to user to search any else in wikipedia
                    flag = 0
                else:
                    main.speak(
                        "Sir what do you want to search in wikipedia...")

            elif "cancel" in search_request:
                # this block executes when a user request to open wikipedia but denies to search in wikipedia
                flag = 0
                main.speak("As you wish sir")

            elif "null" in search_request:
                # this block executes when a user didn't provide any command after requesting maggi to open wikipedia
                pass

            else:
                # this blocks executes when no result were found for the given command
                raise NoResultFoundError(search_request)

    except wikipedia.exceptions.PageError as e:
        main.speak("No result were found in wikipedia sir...")
        main.speak("sir you want me to search your request in google")
        sub_query = recognize_voice.listen_command().lower()
        while True:
            if "yes" in sub_query or "sure" in sub_query:
                # this block executes when the user wish to search his request in google
                webbrowser.open("https://google.com/search?q=" + str(e))
                break
            else:
                main.speak(
                    "Sir do you want me to search your request in google?")
                sub_query = recognize_voice.listen_command().lower()
    return
示例#27
0
def activate_maggi(kernel):
    toggle = 0
    flag = 1
    while flag:
        if toggle == 0:
            main.speak("how can i help you")
        query = recognize_voice.listen_main_command().lower()

        if "don't" not in query and "no " not in query:
            print(query)

            if "wikipedia" in query:
                # this block executes when query related to wikipedia encounters
                wikipedia_related_queries.wikipedia_query_handler()
                request_for_assistance(toggle)

            elif "open youtube" in query:
                # this block executes when query related to youtube encounters
                youtube_related_queries.youtube_query_handler()
                request_for_assistance(toggle)

            elif "play music" in query:
                music_dir = "D:\\PERSONAL\\SONGS\\1 - Nenokkadine (2013)"
                files = os.listdir(music_dir)
                print(files)
                main.speak("Playing music")
                os.startfile(os.path.join(music_dir, files[1]))
                request_for_assistance(toggle)

            elif "detect text" in query:
                image_to_text.image_to_speech()

            elif "detect object" in query:
                object_detector.object_detector()

            elif "exit" in query or "terminate" in query:
                main.speak("Are you sure about it sir")
                sub_query = recognize_voice.listen_command().lower()
                flag = 1
                while flag:
                    if "yes" in sub_query or "sure" in sub_query:
                        main.speak("Executing termination protocol")
                        exit(0)
                    else:
                        toggle = 1
                        sub_query = recognize_voice.listen_command().lower()

            else:
                # kernel now ready for use
                if query not in "null":
                    query = query.upper()
                    maggi_speech = kernel.respond(query)
                    print("MAGGI: " + maggi_speech)
                    main.speak(maggi_speech)
                    toggle = 1

        else:
            main.speak(
                "Sir if u need any help you can call me by just saying, Hey Maggi"
            )
            flag = 0
示例#28
0
def request_for_assistance(toggle):
    toggle = 1
    time.sleep(3)
    main.speak("Do you need any other help sir")
示例#29
0
def youtube_query_handler():
    main.speak("Sir what do u want to watch in youtube")
    flag = 1
    while flag:
        search_request = recognize_voice.listen_command().lower()

        if "cancel" not in search_request and "null" not in search_request and "no" not in search_request:
            # this blocks executes when a user tries to search about some information details in wikipedia
            main.speak("Opening youtube and searching for your request")
            search_request = search_request.replace(' ', '+')
            url = url_finder(search_request)
            webbrowser.open("https://www.youtube.com/" + url)
            time.sleep(4)
            main.speak("This is what i found in youtube sir")
            time.sleep(2)
            flag1 = 1
            main.speak("Do you want to download this video sir?")
            while flag1:
                response = recognize_voice.listen_command().lower()

                if "no" in response:
                    # to terminate the loop from being asked to user to search anything else in youtube
                    flag1 = 0
                    flag = 0
                elif "yes" in response or "sure" in response or "download" in response:
                    main.speak("Initializing download")
                    # main.speak("Sir download has started, u can redirect to the download folder by clicking on the given link")
                    pop_up_window.pop_up_msg("YouTube download window",
                                             "download has started", "sss")
                    print("https://www.youtube.com/" + url)
                    y = YouTube("https://www.youtube.com/" +
                                url).streams.first().download("E:\\movies")
                    flag1 = 0
                    flag = 0
                else:
                    pass

        elif "cancel" in search_request or "no" in search_request:
            # this block executes when a user request to open youtube but denies to search in youtube
            flag = 0
            main.speak("As you wish sir")

        elif "null" in search_request:
            # this block executes when a user didn't provide any command after requesting maggi to open youtube
            pass
示例#30
0
 def test_speak(self):
     INP = EXP = 'OK'
     OUT = speak(INP)
     assert OUT == EXP, 'It must speak exactly what I asked'