def main():

    profile = open("profile.yaml")
    profile_data = yaml.safe_load(profile)
    profile.close()

    speak("Welcome" + profile_data["name"] +
          ", systems are now ready to run. How may i help you?")

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "-t",
        "--text",
        help="Provide text input instade of speech input using microphone.")
    args = parser.parse_args()

    if args.text:
        profile_data["is_cli"] = "true"
        speech_text = args.text
        print("Your input: " + speech_text)
        brain(speech_text, **profile_data)
    else:
        profile_data["is_cli"] = "false"
        speech_text = to_text()
        brain(speech_text, **profile_data)
    def chat(subject):
        flag = True
        print("> What more queries do you have about " + subject +
              "?. If you want to exit, type Bye!")
        speak("What more queries do you have about " + subject +
              "?. If you want to exit, say Bye!")

        while (flag == True):
            if cli == "true":
                user_response = input()
                user_response = user_response.lower()
            else:
                user_response = to_text()

            if (user_response != 'bye'):
                if (user_response == 'thanks' or user_response == 'thank you'):
                    flag = False
                    print("> You are welcome..")
                    speak("You are welcome.")
                else:
                    if (greeting(user_response) != None):
                        reply_text = greeting(user_response)
                        print("> " + reply_text)
                        speak(reply_text)
                    else:
                        reply_text = response(user_response)
                        print("> ", end="")
                        print(reply_text)
                        speak(reply_text)
                        sent_tokens.remove(user_response)
            else:
                flag = False
                print("> Bye! take care..")
                speak("Bye! take care.")
Example #3
0
def what_weather(city, key):

    base_url = "http://api.openweathermap.org/data/2.5/weather?"
    url = base_url + "appid=" + key + "&q=" + city
    weather_data = requests.get(url).json()

    reply = "OpenWeather says: It is " + weather_data["weather"][0][
        "description"] + " and " + str(
            int(float(weather_data["main"]["temp"]) -
                float(273.15))) + " degree celcius now in " + city
    print(reply)
    speak(reply)
def define(subject, cli):
    words = subject.split()
    words.remove("define")
    subject = " ".join(words)

    try:
        wiki_data = wikipedia.summary(subject, sentences=5)

        regex = re.compile(r"([^\(]*)\([^\)]*\) *(.*)")
        m = regex.match(wiki_data)
        while m:
            wiki_data = m.group(1) + m.group(2)
            m = regex.match(wiki_data)

        wiki_data = wiki_data.replace("'", "")
        print("Defination of " + subject + ":\n" + wiki_data)
        speak(wiki_data)
        print("Do you have any more question? (y/N)")
        speak("Do you have any more question?")
        if cli == "true":
            reply = input().lower()
        else:
            reply = to_text()
        set(["yes"]).issubset(set(reply.split()))
        if set(["yes"]).issubset(set(reply.split())) or set(["sure"]).issubset(
                set(reply.split())) or reply == "y":
            init_chat(subject, cli)

    except wikipedia.exceptions.DisambiguationError as e:
        print(
            "Can you please be more specific? You may choose from the following: {0}"
            .format(e))
        speak("Can you please be more specific?")
Example #5
0
def to_text():
	r = sr.Recognizer()
	with sr.Microphone() as source:
		print("Am listening!")
		audio = r.listen(source)

	try:
		speech_text = r.recognize_google(audio).lower().replace("'", "")
		print("I thinks you said: " + speech_text)
		speak("I thinks you said: " + speech_text)
		return speech_text
	except sr.UnknownValueError:
		print("Sorry, I could not understand the audio")
		speak("Sorry, I could not understand the audio")
		to_text()
	except sr.RequestError as e:
		print("Sorry, I ran into an error; {0}".format(e))
		speak("Sorry, I ran into an error; {0}".format(e))
		to_text()
def who_are_you():
	replies = ["I am Natasha, your lovely personal assistant.", "Natasha, didnt I tell you before?", "You ask that so many times! I am Natasha"]
	reply = random.choice(replies)
	print(reply)
	speak(reply)
def undefined():
	reply = "Sorry, I dont know what that means!"
	print(reply)
	speak(reply)
def how_are_you():
	reply = 'I am fine, thank you.'
	print(reply)
	speak(reply)
def where_born():
	reply = 'I was created by a magician named Sushant, in India, the magical land of Himalayas.'
	print(reply)
	speak(reply)
def who_am_i(name): 
	reply = "You are " + name + ", a brilliant person. I love you!"
	print(reply)
	speak(reply)
def tell_joke():
	jokes = ['What happens to a frogs car when it breaks down? It gets toad away.', 'Why was six scared of seven? Because seven ate nine.', 'No, I always forget the punch line.'] 
	reply = random.choice(jokes)
	print(reply)
	speak(reply)
def how_am_i():
	replies = ["You are goddamn handsome!", "My knees go weak when I see you.", "You are sexy!", "You look like the kindest person that I have met."]
	reply = random.choice(replies)
	print(reply)
	speak(reply)
def what_is_time():
    reply = "The time is" + datetime.strftime(datetime.now(), "%H:%M")
    print(reply)
    speak(reply)