def sendMessage():
    # print response if you want
    flag = False
    path = sys._MEIPASS + "\\MyContacts.json"
    with open(path, "r") as f:
        data = json.load(f)["phones"]
    print("Phones -> ", data)

    VoiceEngine.getVoice("Whom do you want to message ?")
    print("Who do you wanna msg ?")
    a2 = SpeechRecogReg().lower()
    print("You said ", a2)

    while a2 not in data:
        VoiceEngine.getVoice("Could find any contact for " + a2)
        VoiceEngine.getVoice("Boss wanna terminate process or try again ?")
        answer = SpeechRecogReg()
        if "terminate" in answer:
            flag = True
            break

    if flag == True:
        return

    VoiceEngine.getVoice("What do you want to say ?")
    print("What do you want to say ?")
    msg = SpeechRecogReg()
    print("You said ", msg)

    sender(data[a2], msg)
    eel.show_info("Message sent successfully")
    VoiceEngine.getVoice(" Message sent successfully ")
def add_contacts(base_path):
    path = base_path + "\\MyContacts.json"
    with open(path, "r") as f:
        data = json.load(f)
    phone_data = data["phones"]

    VoiceEngine.getVoice("May I know the name of contact ?")
    name = SpeechRecogReg().lower()

    if name != None:
        VoiceEngine.getVoice("What is " + name + "'s contact number?")
        try:
            number = SpeechRecogReg()
            number_as = int(number)
        except:
            print("Not a number")
            return

        entry = {name: number}
        phone_data.update(entry)
        data.update(phone_data)

        with open(path, "w") as json_file:
            json.dump(data, json_file)

        VoiceEngine.getVoice("Phone Contact added successfully !")
Beispiel #3
0
def handleResponse(response):
    if response["status"] == "ok":
        top_articles = response["articles"]
        print("Number of trending articles->", len(top_articles))
        for i in top_articles:
            print("Source: ", i["source"]["name"])
            print("headline: ", i["title"])

            eel.show_info(i["title"])
            VoiceEngine.getVoice(i["title"])
            # ask if details are required and print i["description"]
            eel.show_info(i["description"])
            VoiceEngine.getVoice(i["description"])

            # ask if in depth details are required and print i["content"]
            ask_for_details = SpeechRecogReg()
            if "get details" in ask_for_details:
                VoiceEngine.getVoice(i["content"])
            if "stop" in ask_for_details:
                break

            # return ok
    else:
        VoiceEngine.getVoice(
            "I think there is some error. Should I try again ?")
        attempt = SpeechRecogReg()
        if "Yes" in attempt or "try again" in attempt:
            return "1"
        return "0"
def add_email_Contact(base_path):
    VoiceEngine.getVoice("May I know the name of contact ?")
    name = SpeechRecogReg().lower()

    if name != None:
        VoiceEngine.getVoice("What is " + name + "'s mail id?")
        mail = SpeechRecogReg()

        VoiceEngine.getVoice("Mail Contact added successfully !")
Beispiel #5
0
def getWeatherData():
    print("speak")
    VoiceEngine.getVoice("which City you want to search")

    id1 = SpeechRecogReg()
    eel.show_info(id1)
    c = print("You said ", id1)

    # try - except block
    try:
        url = "http://api.openweathermap.org/data/2.5/weather?q={}&appid=75eeb1def22ad1b37ad95298b918695c&units=metric".format(
            id1
        )
        res = requests.get(url)
        data = res.json()
        temp = str("The temperature is:"), data["main"]["temp"], str("degree celcius")
        description = str("It is"), data["weather"][0]["description"]

        """ print('Temperature : {} degree celcius'.format(temp))
        print('Description : {}'.format(description)) """

        VoiceEngine.getVoice(temp)
        VoiceEngine.getVoice(description)
        eel.show_info(description)
    except expression as identifier:
        VoiceEngine.getVoice("No such place found")
        eel.show_info("No such place found")

    return
Beispiel #6
0
def newsFeed():
    VoiceEngine.getVoice("Sir, what would you like to hear ?")
    wish = SpeechRecogReg().lower()

    if "headlines" or "headline" in wish:
        fetchDailyNews()
    else:
        fetchQueryNews(wish)
    return
def main():
    lastSeen = datetime.now()
    commands = [
        "search google",
        "search youtube",
        "email",
        "message",
        "play music",
        "turn light on",
    ]

    t = threading.Thread(target=detector.detector)
    t.setDaemon(True)
    t.start()

    VoiceEngine()
    ActionDecider()

    eel.start_listening()
    VoiceEngine.getVoice("Welcome home")
    print("We are here")
    while helper.global_status_main == True:
        # print("code reached below point x 1")
        textForm = SpeechRecogInit()
        # print("code reached below point")
        if "Friday" in textForm:
            # eel.stop_listening()

            eel.show_info("Hi Boss How can I help You?")
            VoiceEngine.getVoice("Hi Boss! How can I help you ?")
            textForm = SpeechRecogReg()

            if textForm != "Invalid":
                value = ActionDecider.decideTakeAction(textForm)
                if value == 1:
                    break

        currentTime = datetime.now()

        if (currentTime - lastSeen).seconds > 20:
            if detector.active_event_list != []:
                print("Events found = ", detector.active_event_list)

                while detector.active_event_list != []:
                    event = detector.active_event_list.pop()
                    print("Event conclude = ", detector.active_event_list)
                    eel.show_info(event)
                    VoiceEngine.getVoice(event)

        # eel.sleep(0.05)
        # eel.sleep(1)
        eel.sleep(0.05)
    res = t.join()
    return
def lightSystemCall(textForm):
    number = textForm[textForm.index("number") + 7:textForm.index("number") +
                      8]
    status = textForm[textForm.index("number") + 9:]

    path = Path(__file__).parent / "appliances.json"
    with path.open() as f:
        data = json.load(f)

    print("In the [Light Module]")

    while data["light " + number] is None:
        key = data["light " + number]
        print(key)
        VoiceEngine.getVoice(
            "I am sorry, could you please say that again or you wanna exit?")
        textForm = SpeechRecogReg()

        if "exit" in textForm:
            return
        number = textForm[textForm.index("number") +
                          7:textForm.index("number") + 8]
        status = textForm[textForm.index("number") + 9:]
    try:
        if "on" in status:
            url = data["light " + number] + number + "/0"
            # wb.get().open_new(url)
            response = req.get(url)
            VoiceEngine.getVoice("Light Turned On")
            print("It is now on : ", url)
        elif "of" or "off" in status:
            url = data["light " + number] + number + "/1"
            # wb.get().open_new(data["light " + number] + number + "/1")
            resonse = req.get(url)
            VoiceEngine.getVoice("Light Turned Off")
            print("It is now off:", url)
    except:
        VoiceEngine.getVoice(
            "Uh! I am facing some network problem. Why don't Try again later?")
    return
def play():
    bundle_dir = sys._MEIPASS
    path = bundle_dir + "\\user-settings.json"

    with open(path, "r") as f:
        data = json.load(f)["music-library-path"]

    eel.show_info("Which song do you wanna play ?")
    VoiceEngine.getVoice("Which song do you wanna play ?")

    filename = SpeechRecogReg()

    eel.show_info("You said ", filename)
    VoiceEngine.getVoice("Playing " + filename)

    # x = input("Enter song name ")
    s = vlc.MediaPlayer(data + filename + ".mp3")
    s.play()
    s.audio_set_volume(35)
    stopper = SpeechRecogReg()
    while "terminate" not in stopper:
        print("Listening ")
        eel.show_info("Listening")
        stopper = SpeechRecogReg()

        if "volume up" in stopper:
            s.audio_set_volume(50)
        if "pause" in stopper:
            s.audio_set_mute(True)
        if "continue" in stopper:
            s.audio_set_mute(False)
        if "volume down" in stopper:
            s.audio_set_volume(35)
        print("You said ", stopper)

    s.stop()

    return "session ended"
def configuration():
    base_path = get_path()

    VoiceEngine.getVoice("Which setting do you want to configure?")
    choice_answer = SpeechRecogReg()

    if "email" or "mail" in choice_answer:
        add_contacts(base_path)
    elif "phone" in choice_answer:
        add_email_Contact(base_path)
    elif "music" or "library" in choice_answer:
        change_music_library(base_path)
    elif "user" or "name" in choice_answer:
        change_user_name(base_path)
Beispiel #11
0
def youTubeSearcher():
    url = "https://www.youtube.com/results?search_query="
    print("what to search on youtube ?")

    audio2345 = SpeechRecogReg()
    print("You searched ", audio2345)

    try:
        get = audio2345
        get.replace(" ", "+")
        print("Search String ", get)
        wb.get().open_new(playOnYoutube(get))
    except Exception as e:
        print("failed".format(e))
Beispiel #12
0
def mailer():
    path = sys._MEIPASS + "\\user-settings.json"
    print("path->", path)

    user_emailId = "*****@*****.**"
    user_password = "******"

    with open(path) as f:
        data = json.load(f)
        user_emailId = data["emailId"]
        user_password = data["password"]

    print(user_emailId, user_password)

    print("[send mail]")
    id1 = SpeechRecogReg().lower()
    print("You said ", id1)

    if "mail" in id1:
        VoiceEngine.getVoice("Whom do you want to mail ?")
        print("Whom do you want to mail ? ")
        id1 = SpeechRecogReg()
        print("you said ", id1)
        l = []

        with open(sys._MEIPASS + "\\MyContacts.json", "r") as f:
            data = json.load(f)["emails"]

        for i in id1.split(" and "):
            if data[i.lower()] != None:
                l.append(data[i.lower()])
            else:
                VoiceEngine.getVoice("Could not find email for ", i)

        VoiceEngine.getVoice("What's the message boss ?")
        message = SpeechRecogReg()

        s = smtplib.SMTP("smtp.gmail.com", 587)
        s.starttls()
        VoiceEngine.getVoice("Sending email, give me some time")
        eel.show_info("Sending . . .")
        print("Sending . . .")
        try:
            for recipientEmailId in l:
                s.login(user_emailId, user_password)
                s.sendmail(user_emailId, recipientEmailId, message)
                VoiceEngine.getVoice("Sent to " + recipientEmailId)
                print("Sent to ", recipientEmailId)
        except:
            print("exception occurred")
            VoiceEngine.getVoice(
                "Boss, I am facing some issues. Why don't we try again later?"
            )

        s.quit()
        VoiceEngine.getVoice("Done Task")
        print("Done task")
Beispiel #13
0
def googleSearcher():
    url = "https://www.google.com/search?q="
    print("search ")
    audio2345 = SpeechRecogReg()
    print("You searched ", audio2345)
    try:
        get = audio2345  # .replace(" ","+")
        print("Search String = ", get)
        # wb.get().open_new(get)
        answer = getGoogleAnswer(get)
        print("Answer is " + answer)
        eel.show_info(answer)
        VoiceEngine.getVoice(answer)
    except Exception as e:
        print("failed".format(e))
    def decideTakeAction(textForm):
        print("You said", textForm)
        if "Google" in textForm:
            VoiceEngine.getVoice("I understand you want to Search Google")
            googleSearcher()
        elif "date" in textForm:
            VoiceEngine.getVoice("I understand you want to know date and time")
            VoiceEngine.getVoice("The date and time is")
            timedate()
        elif "YouTube" in textForm:
            VoiceEngine.getVoice("I understand you want to search youtube")
            youTubeSearcher()
        elif "download music" in textForm:
            VoiceEngine.getVoice(
                "I understand you want to download music. Let me process . . ."
            )
            VoiceEngine.getVoice("Which song you wanna download ?")
            search_string = SpeechRecogReg()
            print("Your search string is ", search_string)
            eel.show_info("Your search string is ", search_string)
            search_url = playOnYoutube(search_string)
            ydl = YouTubeDownloader(search_string)
            print("object created")
            ydl.download(search_url)
            VoiceEngine.getVoice("downloading file. . .please wait !")
            # del ydl

        elif "email" in textForm:
            VoiceEngine.getVoice("I understand you want to send an Email")
            mailer()
            # Calls Email
        elif "text" in textForm:
            VoiceEngine.getVoice("I understand you want to send text Messages")
            sendMessage()
            # Calls PhoneText
        elif "reset security system" in textForm:
            VoiceEngine.getVoice(
                "I understand you want to reset the Security System")
            # Call Reset Security System
        elif "light" in textForm:
            VoiceEngine.getVoice(
                "I understand you want to turn the lights off")
            lightSystemCall(textForm)
            # Call a simple web api
        elif "kill yourself" in textForm:
            VoiceEngine.getVoice("Alight I am gonna rest now! Bye Bye")
            return 1
        elif "play music" in textForm:
            VoiceEngine.getVoice("Which song maester?")
            # play()
        elif "weather" in textForm:
            VoiceEngine.getVoice("Yo Boss Gimme a second")
            getWeatherData()
        elif "news" in textForm:
            newsFeed()
        else:
            VoiceEngine.getVoice(
                "I am sorry I cannot do that ! But you can teach me how")

        eel.stop_listening()
        return