Пример #1
0
def nlproc():
    r = sr.Recognizer()
    try:
        with sr.Microphone() as source:
            if state.state != 0:
                print("Listening .....")
            r.adjust_for_ambient_noise(source)
            audio = r.listen(source)
            if state.state != 0:
                print("Recognizing .....")
            text = r.recognize_google(audio)
            print("You said: " + text)
    # except Exception:
    #     speak("Error! Network connection lost")
    #     print("Network connection error")
    #     return "none"
    except sr.UnknownValueError as err:
        if state.state != 0:
            tts.speak("I didn't understand, what you are trying to say?")
            print("I didn't understand, what you are trying to say?")
        return "none"
    except sr.RequestError as e:
        #print("Request Failed; {0}".format(e))
        print("Problem occur while recognizing speech!")
        tts.speak("Problem occur while recognizing speech!")
        return "none"

    return text
Пример #2
0
def search_google(qu):
    # print
    qu.put("What do you want to search?")
    tts.speak("What do you want to search?")
    query = rec_vic.nlproc(qu).lower()
    g_url = "https://www.google.com/search?q="
    webbrowser.open(g_url + query)
Пример #3
0
def ip():
    try:
        ip = get('https://api.ipify.org').text
        tts.speak(f"your IP address is {ip}")
        print(f"your IP address is: {ip}")
    except Exception:
        tts.speak("Not able to find IP address")
        print("Not able to find IP address!")
Пример #4
0
def sleep_wake():
    tts.speak("sleeping now")
    state.state = 0
    print("sleeping now. zzzzzzz !")
    while True:
        query = rec_vic.nlproc().lower()
        if 'wake up' in query:
            tts.speak("Hi, i am back")
            print("Hi, I am back.")
            state.state = 1
            break
def nmSlist():
    global nmS
    nmSlst = []
    for i in nmS:
        if i not in nmSlst:
            nmSlst.append(i)
    if not nmSlst:
        pass
    else:
        print("These names are already registered:")
        tts.speak("These names are already registered:")
        print(*nmSlst,sep="\n")
Пример #6
0
def sleep_wake(qu):
    state.state = 0
    tts.speak("sleeping now")
    # print
    qu.put("Sleeping now. zzzzzzz !")
    while True:
        query = rec_vic.nlproc(qu).lower()
        if 'wake up' in query:
            # print
            qu.put("Hi, I am back.")
            tts.speak("Hi, i am back")
            state.state = 1
            break
Пример #7
0
def music():
    try:
        tts.speak("ok i am playing music")
        print("ok i am playing music .....")
        music_dir = './music'
        for lst in os.listdir(music_dir):
            if lst.endswith('.mp3'):
                music = os.listdir(music_dir)
        rnd = random.choice(music)
        os.startfile(os.path.join(music_dir,rnd))
    except Exception:
        tts.speak("Not able to play music right now")
        print("Not able to play music right now!")
Пример #8
0
def video():
    try:
        tts.speak("ok i am playing videos")
        print("ok i am playing videos .....")
        video_dir = './video'
        for lst in os.listdir(video_dir):
            if lst.endswith('.mp4'):
                videos = os.listdir(video_dir)
        rnd = random.choice(videos)
        os.startfile(os.path.join(video_dir,rnd))
    except Exception:
        tts.speak("Not able to play video right now")
        print("Not able to play video right now!")
Пример #9
0
def wolf(qu):
    try:
        # print
        qu.put("Feel free to ask any question.")
        tts.speak("feel free to ask any question.")
        # Taking input from user
        question = rec_vic.nlproc(qu).lower()
        if question == "none":
            qu.put("I apologize, I am not able to answer.")
            tts.speak("I apologize, I am not able to answer.")
            return
        # App id obtained by the above steps
        app_id = 'V56XQ4-23QA5RPPQ9'

        # Instance of wolf ram alpha
        # client class
        client = wolframalpha.Client(app_id)

        # Stores the response from
        # wolf ram alpha
        res = client.query(question)

        # Includes only text from the response
        answer = next(res.results).text
        qu.put(answer)
        tts.speak(answer)
    except Exception:
        # print
        qu.put("I apologize, I am not able to answer.")
        tts.speak("I apologize, I am not able to answer.")
Пример #10
0
def pdf_read(qu):
    try:
        book = open('PDFs\\read.pdf','rb') # enter PDF name by replacing 'read'
        pdfreader = PyPDF2.PdfFileReader(book)
        pages = pdfreader.numPages
        # print
        qu.put(f"Total pages are: {pages}")
        tts.speak(f"Total pages are: {pages}")
        # print
        qu.put("Which page I have to read?")
        tts.speak("which page i have to read?")
        qu.put("PDFPG")
        sleep(1)
        while qu.empty() == True:
            # if qu.empty == False:
            #     break
            pass
        rdpg = qu.get(0)
        # rdpg = int(input("Enter page number. "))
        rdpg = rdpg - 1
        page = pdfreader.getPage(rdpg)
        text = page.extractText()
        tts.speak(text)
    except Exception:
        # print
        qu.put("Not able to read anything!")
        tts.speak("Not able to read anything!")
Пример #11
0
def welcom():
    id = recognize.main()
    titl = ""
    if id == "" or id == "Unknown":
        gen = gender.regen()
        id = ""
        if gen == 'Male':
            titl = 'Sir'
        elif gen == 'Female':
            titl = 'Miss'
        else:
            titl = ""
    hour = int(datetime.datetime.now().hour)
    if hour >= 4 and hour < 12:
        tts.speak("Good morning " + titl + id +
                  ", i am your virtual assistant. How May I Help you?")
        print("Good morning " + titl + id +
              ", i am your virtual assistant. How May I Help you?")
    elif hour >= 12 and hour < 17:
        tts.speak("Good afternoon " + titl + id +
                  ", i am your virtual assistant. How May I Help you?")
        print("Good afternoon " + titl + id +
              ", i am your virtual assistant. How May I Help you?")
    elif hour >= 17 and hour < 21:
        tts.speak("Good evening " + titl + id +
                  ", i am your virtual assistant. How May I Help you?")
        print("Good evening " + titl + id +
              ", i am your virtual assistant. How May I Help you?")
    else:
        tts.speak("hi " + titl + id +
                  ", i am your virtual assistant. How May I Help you?")
        print("Hi " + titl + id +
              ", i am your virtual assistant. How May I Help you?")
def nmSlist(qu):
    global nmS
    nmSlst = []
    for i in nmS:
        if i not in nmSlst:
            nmSlst.append(i)
    if not nmSlst:
        pass
    else:
        qu.put("These names are already registered:")
        tts.speak("These names are already registered:")
        for i in nmSlst:
            # print(*nmSlst,sep="\n")
            qu.put(i)
            sleep(0.1)
def reg_me():
    global id,nmS
    chk_nm()
    nmSlist()
    tts.speak("Enter your name")
    while True:
        id = input('Enter your name: ').lower()
        if id == "cancel":
            return
        if id in nmS:
            tts.speak("Name already exist. Type again, or Type 'cancel' to abort.")
            print("Name already exist. Type again or Type 'cancel' to abort.")
        else:
            main()
            break
Пример #14
0
def write_note():
    tts.speak("What should i write?")
    print("What should I write?")
    note = rec_vic.nlproc().lower()
    file = open('note.txt', 'w')
    tts.speak("Should i include date and time")
    print("Should i include date and time?")
    add_time = rec_vic.nlproc().lower()
    if 'yes' in add_time or 'sure' in add_time:
        strTime = datetime.datetime.now().strftime("% H:% M:% S")
        file.write(strTime)
        file.write(" :- ")
        file.write(note)
    else:
        file.write(note)
Пример #15
0
def netck():
    url = "http://www.google.com/"
    timeout = 2
    try:
        _ = requests.get(url, timeout=timeout)
        tts.speak("Internet Connected")
        print("Internet Connected.")
        return False
    except requests.ConnectionError:
        tts.speak(
            "No internet connection. I will not be able to work properly without internet!"
        )
        print(
            "No internet connection. I will not be able to work properly without internet!"
        )
        return False
Пример #16
0
def nlproc(qu):
    r = sr.Recognizer()
    try:
        with sr.Microphone() as source:
            if state.state != 0:
                # print
                qu.put("Listening .....")
            r.adjust_for_ambient_noise(source)
            audio = r.listen(source)
            if state.state != 0:
                # print
                qu.put("Recognizing .....")
            text = r.recognize_google(audio)
            # Language detection if as hindi convert to urdu text for output
            try:
                txt_rev = ""
                if (gt.detect(text)).lang == 'hi':
                    text = gt.translate(text, dest='ur').text
                    for i in ((text).split(' ')):
                        txt_rev = i + " " + txt_rev
                    text = txt_rev
            except:
                pass
            # print
            qu.put("You said: " + text)
    # except Exception:
    #     speak("Error! Network connection lost")
    #     print("Network connection error")
    #     return "none"
    except sr.UnknownValueError as err:
        if state.state != 0:
            # print
            qu.put("I didn't understand, what you are trying to say?")
            tts.speak("I didn't understand, what you are trying to say?")
        return "none"
    except sr.RequestError as e:
        # print
        # qu.put("Request Failed; {0}".format(e))
        qu.put("Problem occur while recognizing speech!")
        tts.speak("Problem occur while recognizing speech!")
        return "none"

    return text
Пример #17
0
def wiki():
    try:
        tts.speak("What do you want to search?")
        print("What do you want to search?")
        query = rec_vic.nlproc().lower()
        tts.speak("searching .....")
        print("searching .....")
        results = wikipedia.summary(query, sentences=2)
        tts.speak("According to wikipedia .....")
        tts.speak(results)
    except Exception as err:
        print(err)
def reg_me(qu):
    global id,nmS
    chk_nm()
    nmSlist(qu)
    qu.put("Enter your name:")
    tts.speak("Enter your name.")
    while True:
        qu.put("REG1PER2")
        sleep(1)
        while qu.empty() == True:
            pass
        #print >>> Input
        id = qu.get(0)
        if id == None:
            tts.speak("Canceled.")
            return
        elif id == "":
            pass
        elif id in nmS:
            # print
            qu.put("Name already exist. Type again.")
            tts.speak("Name already exist. Type again.")
        else:
            break
    main(qu)
Пример #19
0
def pdf_read():
    try:
        book = open('PDFs\\read.pdf',
                    'rb')  # enter PDF name by replacing 'read'
        pdfreader = PyPDF2.PdfFileReader(book)
        pages = pdfreader.numPages
        tts.speak(f"Total pages are: {pages}")
        print(f"Total pages are: {pages}")
        tts.speak("which page i have to read?")
        print("Which page I have to read?")
        rdpg = int(input("Enter page number. "))
        rdpg = rdpg - 1
        page = pdfreader.getPage(rdpg)
        text = page.extractText()
        tts.speak(text)
    except Exception:
        tts.speak("Not able to read anything!")
        print("Not able to read anything!")
Пример #20
0
def open_note():
    try:
        # spath="notepad.exe"
        # os.startfile(spath)
        tts.speak("Showing Notes")
        print("Showing Notes .....")
        file = open("note.txt", "r")
        print(file.read())
        tts.speak(file.read(6))
    except Exception:
        tts.speak("File not found")
        print("File not found!")
Пример #21
0
def open_github():
    webbrowser.open("https://www.github.com")
    tts.speak("opening github") 
    print("opening github .....")  
Пример #22
0
def chat(query):
    if 'none' not in query:
        res = chatbot.get_response(query)
        print(res)
        tts.speak(res)
Пример #23
0
def open_flipkart():
    webbrowser.open("https://www.flipkart.com")
    tts.speak("opening flipkart")   
    print("opening flipkart .....")   
Пример #24
0
def open_youtube(qu):
    # print
    qu.put("opening youtube .....")
    tts.speak("opening youtube")
    webbrowser.open("www.youtube.com")
Пример #25
0
def open_ebay():
    webbrowser.open("https://www.ebay.com")
    tts.speak("opening ebay")
    print("opening ebay .....")
Пример #26
0
def youtube(qu):
    # print
    qu.put("What do you want to play?")
    tts.speak("What do you want to play?")
    query = rec_vic.nlproc(qu).lower()
    playonyt(query)
Пример #27
0
def close_chrome():
    tts.speak("closing chrome")
    print("closing chrome .....")
    os.system("TASKKILL /F /IM chrome.exe")
Пример #28
0
def open_facebook():
    webbrowser.open("https://www.facebook.com")
    tts.speak("opening facebook")  
    print("opening facebook .....")      
Пример #29
0
def chat(query, qu):
    if 'none' not in query:
        res = str(chatbot.get_response(query))
        # print
        qu.put(res)
        tts.speak(res)
Пример #30
0
def tsklst(query):
    if "wikipedia" in query:
        wiki.wiki()
    elif 'open youtube' in query:
        youtube.open_youtube()
    elif 'youtube' in query or "open video online" in query:
        youtube.youtube()
    elif 'open github' in query:
        open_browser.open_github()
    elif 'open facebook' in query:
        open_browser.open_facebook()
    elif 'login facebook' in query:
        fbot.fb_login()
    elif 'open instagram' in query:
        open_browser.open_instagram()
    elif 'open google' in query:
        google.open_google()
    elif 'search google' in query:
        google.search_google()
    elif 'open yahoo' in query:
        open_browser.open_yahoo()
    elif 'open gmail' in query:
        open_browser.open_gmail()
    elif 'open snapdeal' in query:
        open_browser.open_snapdeal()
    elif 'open amazon' in query or 'shop online' in query:
        open_browser.open_amazon()
    elif 'open flipkart' in query:
        open_browser.open_flipkart()
    elif 'open ebay' in query:
        open_browser.open_ebay()
    elif 'close chrome' in query:
        open_browser.close_chrome()
    elif 'music from pc' in query or "music" in query or "play music" in query:
        play_av.music()
    elif 'video from pc' in query or "video" in query or "play video" in query:
        play_av.video()
    elif "write note" in query:
        notepad.write_note()
    elif 'show note' in query:
        notepad.open_note()
    elif 'close note' in query:
        notepad.close_note()
    elif 'read pdf' in query:
        rd_pdf.pdf_read()
    elif 'ip address' in query:
        ip.ip()
    elif 'joke' in query:
        jok = (pyjokes.get_joke())
        print(jok)
        tts.speak(pyjokes.get_joke())
    elif 'send email' in query or 'email' in query:
        try:
            tts.speak("what should I type?")
            print("What should I type?")
            query = rec_vic.nlproc().lower()
            to = "*****@*****.**"
            memail.sendEmail(to, query)
            tts.speak("Email has been sent!")
            print("Email has been sent!")
        except Exception as err:
            print(err)
            tts.speak("I am afraid I can't do this.")
    elif 'switch window' in query:
        sys.switch_window()
    elif "shutdown system" in query:
        sys.shutdown_system()
    elif "cancel shutdown" in query:
        sys.abort_shutdown_system()
    elif "restart system" in query:
        sys.restart_system()
    elif "sleep system" in query:
        sys.sleep_system()
    elif "hibernate" in query:
        sys.hibernate()
    elif "log off" in query:
        sys.log_off()
    elif 'time' in query or 'what time is it?' in query:
        sys.tell_time()
    elif 'date' in query or 'what date today?' in query:
        sys.tell_date()
    elif 'exit' in query or 'abort' in query or 'stop' in query or 'bye' in query or 'quit' in query or 'good bye' in query:
        ex_exit = ['good bye', 'ok', 'see you later']
        ans_q = random.choice(ex_exit)
        tts.speak(ans_q)
        print(ans_q)
        exit()
    elif 'sleep' in query:
        sleep_wake.sleep_wake()
    elif "what's up" in query or 'how are you' in query:
        stMsgs = [
            'Just doing my thing!', 'I am fine!', 'Nice!',
            'I am nice and full of energy', 'i am ok !'
        ]
        ans_q = random.choice(stMsgs)
        tts.speak(ans_q)
        print(ans_q)
        tts.speak("Tell me about you!")
        how_are_you = rec_vic.nlproc().lower()
        if 'fine' in how_are_you or 'happy' in how_are_you or 'ok' in how_are_you:
            tts.speak("Good!")
            print("Good!")
        elif 'not good' in how_are_you or 'sad' in how_are_you or 'upset' in how_are_you:
            tts.speak("oh sorry")
            print("Oh, sorry!")
    elif "who are you" in query or "about you" in query or "your details" in query:
        tts.speak("I am your virtual assistant. A I based computer program.")
        print("I am your virtual assistant. AI based computer program.")
    elif "hello" in query or "hello assistant" in query:
        id = recognize.main()
        titl = ""
        if id == "" or id == "Unknown":
            gen = gender.regen()
            id = ""
            if gen == 'Male':
                titl = 'Sir'
            elif gen == 'Female':
                titl = 'Miss'
            else:
                titl = ""
        tts.speak("Hello! " + titl + id + " How May I Help you?")
        print("Hello! " + titl + id + " How May I Help you?")
    elif "your name" in query or "sweat name" in query:
        tts.speak("Call me whatever you want. I have no name.")
        print("Call me whatever you want. I have no name.")
    elif "answer me" in query:
        wolf.wolf()
    elif "recognize me" in query or "recognize" in query or "recognise me" in query or "recognise" in query or "do you know me" in query or "you know me" in query or "know me" in query:
        tts.speak("Let see, who you are?")
        print("Let see, who you are?")
        id = recognize.main()
        if id == "" or id == "Unknown":
            tts.speak("I don't know you.")
            print("I don't know you.")
        else:
            tts.speak("I know you. Your name is " + id)
            print("I know you. Your name is " + id)
    elif "register identity" in query or "register face" in query or "identity" in query or "register me" in query:
        tts.speak("Face registration in progress.")
        print("Face registration in progress .....")
        create_dataset.reg_me()
        tts.speak("Process complete.")
        print("Process complete.")
    elif "add face data" in query or "face data" in query:
        tts.speak("Face data entry in progress.")
        print("Face data entry in progress .....")
        create_dataset.add_face()
        tts.speak("Process complete.")
        print("Process complete.")
    else:
        chatbot.chat(query)