Example #1
0
def hear():
    with speech_recognition.Microphone() as source:
        recognizer.adjust_for_ambient_noise(source)
        audio = recognizer.listen(source)

    try:
        return recognizer.recognize_google(audio)
    except speech_recognition.UnknownValueError:
        speak.talk("")
    except speech_recognition.RequestError as e:
        print("Recog Error: {0}".format(e))

    return ""
Example #2
0
def baby1():
    statement = ''
    try:
        # with sr.Microphone() as source:
        #     print('listening...')
        #     voice = listener.listen(source,2)
        #     print(voice)
        #     command = listener.recognize_google(voice)
        #     #command = listener.recognize_sphinx(voice,language="en-US")
        #     command = command.lower()
        #     print(command)
        #     command = command.replace('listening','')
        statement = talk()
        # if 'i am ' in command :
        #     command = command.replace('i am listening','')
        # # if oshan in command than execute
        # if 'covid' in command or 'covit' in command:
        #     command = command.replace('covid','')
        #     command = command.replace('listening','')
        #     statement = command
        #     print(command)
        # else :
        #     #pass
        #     print(command)
        #     command = command.replace('listening','')
        #     statement = command
    except:
        #speak("I can't understand ")
        pass

    return statement
Example #3
0
def addBirthdays(text):
    matches = datefinder.find_dates(text)
    for match in matches:
        date = match.strftime('%m%d')
    names = NERTagger.get_names(text)
    if not date:
        speak.talk("Date: ")
        date = listen.hear()
        matches = datefinder.find_dates(text)
        for match in matches:
            date = match.strftime('%m%d')
    if not names:
        speak.talk("Reason for reminder: ")
        bname = listen.hear()
    else:
        bname = names[0]
    fileName = open(birthdayFile, 'a')
    fileName.write("\n" + date + " " + bname)
    fileName.close()
    return "Reminder is set"
Example #4
0
def checkTodaysBirthdays():
    fileName = open(birthdayFile, 'r')
    today = time.strftime('%m%d')
    flag = 0
    speak.talk("Today's Birthdays")
    for line in fileName:
        if today in line:
            line = line.split(' ')
            flag = 1
            speak.talk("{0}".format(" ".join(line[1:])))
            if sys.platform == "win32":
                toaster.show_toast("Birthday Notifier",
                                   "Birthdays Today: {0}".format(" ".join(
                                       line[1:])),
                                   threaded=True)
            else:
                os.system('notify-send "Birthdays Today: {0}"'.format(" ".join(
                    line[1:])))
            while toaster.notification_active():
                time.sleep(0.1)
    if flag == 0:
        speak.talk("no one special today")
        if sys.platform == "win32":
            toaster.show_toast("Birthday Notifier",
                               "No Birthdays Today!",
                               threaded=True)
        else:
            os.system('notify-send "No Birthdays Today!"')
    return "Notification Removed"
Example #5
0
def search(text):
    sentence = ""
    text = urllib.parse.quote_plus(text)
    url = 'https://google.com/search?q=' + text
    response = requests.get(url)
    soup = BeautifulSoup(response.text, 'lxml')
    soup.prettify()
    speak.talk("Top {0} results processed from google".format(
        str(len(soup.find_all(class_='g')))))
    for g in soup.find_all(class_='g'):
        nltk_tokens = nltk.sent_tokenize(g.text)
        for tokens in nltk_tokens:
            sentence = sentence + tokens + "\n"
        string = re.sub(re.compile("/.[\s]", re.DOTALL), ",", sentence)
        print(string)
        speak.talk_fast()
        speak.talk(string)
        speak.talk_normal()
        sentence = ""
        speak.talk("Do you want to read the next result?")
        text = listen.hear()
        if text == "" or text == "no":
            return "Okay"
    return "Search something else?"
Example #6
0
import tracy as t
import re
import speak
import listen


def reply(message):
    # Get the bot's response to the message
    response = t.respond(message)
    return response


speak.talk("Hi! I'm Tracy, your personal assistant, at your service.")
speak.talk("Before we start, what's your name?")
user = input("Name: ")
speak.talk("Nice to meet you, {0}".format(user))
count = 0
while True:
    text = listen.hear()
    if text == "":
        count += 1
        if count == 5:
            speak.talk("Would you like to talk to me about something?")
            text = listen.hear()
            if text == "no":
                count = 7
        if count == 7:
            speak.talk("Going to sleep")
            exit()
        continue
    print(user + ": " + text)