Ejemplo n.º 1
0
def main():
    while 1:
        data = Microphone_engine()
        exit_flag = 0
        if data!="" and data!="error":
            if "bye" in data:
                Speaking_engine("Bye, Have a great day!")
                break
            if "helen"==data or "Helen"== data:
                Speaking_engine("Yes right! That's my name. Tell me how may I help you?")
            else:
                helen(data)
                time.sleep(5)
                Speaking_engine("Do you have any other commands?")
                for j in range(5):
                    confirm = Microphone_engine()
                    if "error" not in confirm and "yes" not in confirm:
                        exit_flag=1
                        break
                    elif "yes" in confirm:
                        exit_flag=0
                        break
                if exit_flag == 1:
                    Speaking_engine("Okay then. My work here is done. Have a good day!")
                    break
                else:
                    Speaking_engine("Great!What can I do for you next?")
Ejemplo n.º 2
0
def open_application(input):

    if "chrome" in input:
        Speaking_engine("Google Chrome")
        os.startfile(
            'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe')
        return

    elif "firefox" in input or "mozilla" in input:
        Speaking_engine("Opening Mozilla Firefox")
        os.startfile('C:\Program Files\Mozilla Firefox\\firefox.exe')
        return

    elif "word" in input:
        Speaking_engine("Opening Microsoft Word")
        os.startfile(
            'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office 2013\\Word 2013.lnk'
        )
        return

    elif "excel" in input:
        Speaking_engine("Opening Microsoft Excel")
        os.startfile(
            'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office 2013\\Excel 2013.lnk'
        )
        return

    else:

        Speaking_engine("Application not available")
        return
Ejemplo n.º 3
0
def greetMe():
        time.sleep(2)
        currentH = int(datetime.datetime.now().hour)
        if currentH >= 0 and currentH < 12:
            Speaking_engine('Good Morning! Boss What can I do for you today?')

        if currentH >= 12 and currentH < 18:
            Speaking_engine('Good Afternoon! Boss What can I do for you today?')

        if currentH >= 18 and currentH !=0:
                Speaking_engine('Good Evening!Boss What can I do for you today?')
Ejemplo n.º 4
0
def search_web(input):

    driver = webdriver.Firefox()
    driver.implicitly_wait(1)
    driver.maximize_window()

    if 'youtube' in input.lower():

        Speaking_engine("Opening in youtube")
        indx = input.lower().split().index('youtube')
        query = input.split()[indx + 1:]
        driver.get("http://www.youtube.com/results?search_query =" +
                   '+'.join(query))
        return

    elif 'wikipedia' in input.lower():

        Speaking_engine("Opening Wikipedia")
        indx = input.lower().split().index('wikipedia')
        query = input.split()[indx + 1:]
        driver.get("https://en.wikipedia.org/wiki/" + '_'.join(query))
        return

    else:

        if 'google' in input:

            indx = input.lower().split().index('google')
            query = input.split()[indx + 1:]
            driver.get("https://www.google.com/search?q =" + '+'.join(query))

        elif 'search' in input:

            indx = input.lower().split().index('google')
            query = input.split()[indx + 1:]
            driver.get("https://www.google.com/search?q =" + '+'.join(query))

        else:

            driver.get("https://www.google.com/search?q =" +
                       '+'.join(input.split()))

        return
Ejemplo n.º 5
0
def game():
     # set the list of words, maxnumber of guesses, and prompt limit
    WORDS = ["apple", "banana", "orange", "mango", "lemon"]
    NUM_GUESSES = 3
    PROMPT_LIMIT = 5

    
    # get a random word from the list
    word = random.choice(WORDS)

    # format the instructions string
    instructions = (
        "I'm thinking of one of these words:\n"
        "{words}\n"
        "You have {n} tries to guess which one.\n"
    ).format(words=', '.join(WORDS), n=NUM_GUESSES)

    # show instructions and wait 3 seconds before starting the game
    Speaking_engine(instructions)
    #time.sleep(3)

    for i in range(NUM_GUESSES):
        # get the guess from the user
        # if a transcription is returned, break out of the loop and
        #     continue
        # if no transcription returned and API request failed, break
        #     loop and continue
        # if API request succeeded but no transcription was returned,
        #     re-prompt the user to say their guess again. Do this up
        #     to PROMPT_LIMIT times
        for j in range(PROMPT_LIMIT):
            st = 'Guess {}. Speak!'.format(i+1)
            Speaking_engine(st)
    
            guess = hear()
            if guess!="error":
                Speaking_engine("You said: {}".format(guess))
                # determine if guess is correct and if any attempts remain
                guess_is_correct = guess.lower() == word.lower()
                user_has_more_attempts = i < NUM_GUESSES - 1
                break
            else:
                Speaking_engine("Let's hear it again.")

        # determine if the user has won the game
        # if not, repeat the loop if user has more attempts
        # if no attempts left, the user loses the game
        if guess_is_correct:
            st = "Correct! You win!"+ word
            Speaking_engine(st)
            break
        elif user_has_more_attempts:
            Speaking_engine("Incorrect. Try again.")
        else:
            st = "Sorry, you lose! I was thinking of '"+word+"'"
            Speaking_engine(st)
            break
Ejemplo n.º 6
0
def calculation(input):

    indx = input.lower().split.index('calculate')

    query = input.split()[indx + 1:]

    res = client.query(' '.join(query))

    answer = next(res.results).text

    Speaking_engine("The answer is " + answer)
Ejemplo n.º 7
0
def email():

    Speaking_engine('Who is the recipient? ')
    recipient = Microphone_engine()

    if 'mail' in recipient:
        try:
            Speaking_engine('What should I say? ')
            content = Microphone_engine

            server = smtplib.SMTP('smtp.gmail.com', 587)
            server.ehlo()
            server.starttls()
            server.login("harshitsharma34", 'mjolnir@qseft')
            server.sendmail('harshitsharma34', recipient, content)
            server.close()
            Speaking_engine('Email sent!')

        except:
            Speaking_engine(
                'Sorry Sir! I am unable to send your message at this moment!')
Ejemplo n.º 8
0
def search(input):
    Speaking_engine("What would you like to search for?")
    query = Microphone_engine()
    try:
        try:
            res = client.query(query)
            results = next(res.results).text
            Speaking_engine('WOLFRAM-ALPHA says - ')
            Speaking_engine('Got it.')
            Speaking_engine(results)

        except:
            results = wikipedia.summary(query, sentences=2)
            Speaking_engine('Got it.')
            Speaking_engine('WIKIPEDIA says - ')
            Speaking_engine(results)

    except:
        webbrowser.open('www.google.com')
Ejemplo n.º 9
0
def Microphone_engine():
    obj = sr.Recognizer()
    audio = ''

    with sr.Microphone() as source:
        print("Speak...")

        audio = obj.listen(source, phrase_time_limit=5)

    print("Recognizing...")

    try:
        text = obj.recognize_google(audio, language='en_US')
        print("You said: ", text)
        return text

    except:
        Speaking_engine(
            "Sorry sir! I could not understand what you are trying to say,please try again"
        )
        return 0
Ejemplo n.º 10
0
 def timing():
     tick()
     reply = ("Current time is " + t1)
     Speaking_engine(reply)
Ejemplo n.º 11
0
def helen(data):
    #Splitting each sentence in a list of words.
    word_list = word_tokenize(data)
    
    #Setting up stop_words: words that are redundant.
    stop_words = set(stopwords.words('english'))

    #Creating space for a list of sentences without stop_words.
    if "search" not in word_list and "google" not in word_list and "Search" not in word_list and "Google" not in word_list:
        filtered_sentence = [w for w in word_list if not w in stop_words]
    else:
        filtered_sentence = [w for w in word_list]
    
    if ("bored" in filtered_sentence):
        Speaking_engine("Let's play a game then!!")
        game()
    elif 'time' in filtered_sentence:
        Speaking_engine(time.strftime("%A") + " "+ str(datetime.datetime.now())[:16])    
        timedate()
    elif 'song' in filtered_sentence and filtered_sentence.index('play') < filtered_sentence.index('song'):
        filtered_sentence = [w for w in filtered_sentence if w != "called" and w != "named" and w != "titled"]
        pos = filtered_sentence.index('song') + 1
        Speaking_engine("Opening Youtube Searches for {}".format(filtered_sentence[pos]))
        playSong(filtered_sentence[pos])  

    elif 'game' in filtered_sentence and filtered_sentence.index('play') < filtered_sentence.index('game'):
        game()

    elif 'google' in filtered_sentence or "Google" in filtered_sentence:
        if len(filtered_sentence) > 1:
            if 'open' in filtered_sentence and 'google' in filtered_sentence and filtered_sentence.index('open') < filtered_sentence.index('google'):
                google()
            if 'open' in filtered_sentence and 'Google' in filtered_sentence and filtered_sentence.index('open') < filtered_sentence.index('Google'):
                google()
            else:
                pos = 0
                if 'google' in filtered_sentence:
                    pos = filtered_sentence.index('google') + 1
                elif 'Google' in filtered_sentence:
                    pos = filtered_sentence.index('Google') + 1
                if 'word' in filtered_sentence and filtered_sentence[-1] != 'word':
                    filtered_sentence =[w for w in filtered_sentence if w != "word"]

                search_string = ''.join(filtered_sentence[pos:])
                google_search(search_string)
        else:
            Speaking_engine("If you want me to open google, say 'open google'")
            Speaking_engine("If you want me to search for a word,"
                "say 'google <word>'")

    elif 'search google' in filtered_sentence or 'search on google' in filtered_sentence or 'google' in filtered_sentence:
        if filtered_sentence[-1] == "search":
            Speaking_engine("What would you like me to search?")
            for j in range(5):
                search_string = Microphone_engine()
                if(search_string!='error'):
                    google_search(search_string)
                    break
            return None
        pos = filtered_sentence.index('search') + 1
        search_string = " ".join(filtered_sentence[pos:])
        google_search(search_string)
    elif 'location' in filtered_sentence:
        if filtered_sentence[-1]=="location":
            Speaking_engine("What place should I look for?")
            for j in range(5):
                location = Microphone_engine()
                if(location!="error"):
                    maps(location)
                    break
            return None
           
        pos = filtered_sentence.index('location')+1
        loc = "".join(filtered_sentence[pos:])
        maps(loc)
    elif 'news' in filtered_sentence:
        Speaking_engine("Here are the top 5 stories for you.")
        NewsFeed = feedparser.parse("https://timesofindia.indiatimes.com/rssfeedstopstories.cms")
        for j in range(5):
            entry = NewsFeed.entries[j]
            Speaking_engine("Number {}".format(j+1))
            print(Speaking_engine(entry.title))
            #print(Speaking_engine(entry.summary))
            print("=======================================")
    elif 'email' in filtered_sentence:
        email()
        print("==============================================")
    elif 'time' in filtered_sentence:
        timedate()
    elif 'calculate' in filtered_sentence:
        calculation()
    elif 'application' in filtered_sentence:
        Speaking_engine('Which Application do you want to open')
        input=Microphone_engine()
        open_application(input)
    elif 'play music' in filtered_sentence:
        path='G:\Music\English Chartbusters\ColdPlay'
        music = ['Everglow','Paradise','Adventure Of A Lifetime','Hymn For The Weekend','A Head Full Of Dreams']
        random_music=path+random.choice(music)+'.mp3'
        os.system(random_music)
    elif 'search' in filtered_sentence:
        Speaking_engine("What would you like to search for?")
        query=Microphone_engine()
        try:
            try:
                app_id = "V8QYE3-V8W86UARPP"
                client = wolframalpha.Client(app_id)
                res = client.query(query)
                results = next(res.results).text
                Speaking_engine('WOLFRAM-ALPHA says - ')
                Speaking_engine('Got it.')
                Speaking_engine(results)
                    
            except:
                results = wikipedia.summary(query, sentences=2)
                Speaking_engine('Got it.')
                Speaking_engine('WIKIPEDIA says - ')
                Speaking_engine(results)
        
        except:
            webbrowser.open('www.google.com')
    else:
        Speaking_engine("I am not aware of this command. Could you please try something else?")
    return None