import speech_recognition
import pyttsx3
from datetime import date, datetime

robot_ear = speech_recognition.Recognizer()
robot_mouth = pyttsx3.init()
robot_brain = ""

while True:

	with speech_recognition.Microphone() as mic:
		print ("Robot: I'm listenning")
		audio = robot_ear.listen(mic)
	print("Robot: ...")

	try:
		you = robot_ear.recognize_google(audio)
	except:
		you = ""

	print("You: " + you)


	if you == "":
		robot_brain = "I can't hear you, try again"
	elif "friend" in you:
		robot_brain = "His name is Thao Hung Nguyen"
	elif "hello" in you:
		robot_brain = "Hello Mister Tuyen Minh Doe"
	elif "today" in you:
		today = date.today()
		robot_brain = "Today is " + today.strftime("%B %d, %Y")
	elif "time" in you:
		now = datetime.now()
		robot_brain = "Now is " + now.strftime("%H O'clock %M minutes %S seconds").replace('0', '')
	elif "president" in you:
		robot_brain = "Joe Biden"
	elif "John" in you:
		robot_brain = "Sorry, mister John Dinh was passed away in Vietnam in 2023. He is in Heaven now."
	elif "Henry" in you:
		robot_brain = "Henry is Son Tran's brother."
	elif "Angela" in you:
		robot_brain = "She is Kevin's sister."
	elif "how many" in you:
		robot_brain = "Eleven. Three brothers and eight sisters."
	elif "Kevin" in you:
		robot_brain = "Kevin is Angela's brother."
	elif "bye" in you:
		robot_brain = "Good bye... It's nice chatting with you. Talk to you next time."
		print ("Robot: " + robot_brain)
		robot_mouth.say(robot_brain)
		robot_mouth.runAndWait()
		break
	else:
		robot_brain = "I'm fine thank you and you"

	print ("Robot: " + robot_brain)
	robot_mouth.say(robot_brain)
	robot_mouth.runAndWait()
