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 Listening")
audio = robot_ear.listen(mic)
try:
you = robot_ear.recognize_google(audio)
except:
you == ""
if you == (""):
robot_brain = "I can't hear you, try again"
elif "hello" in you:
robot_brain = "hello phong"
elif "today" in you:
today = date.today()
robot_brain = today.strftime("%B %d, %Y")
elif "time" in you:
now = datetime.now()
robot_brain = now.strftime("%H hours %M minutes %S seconds")
elif "Bye" in you:
robot_brain = "Bye phong"
break
else:
robot_brain = "I need update to do thit"
print("Bạn: " + you)
print("Robot: " + robot_brain)
robot_mouth = pyttsx3.init()
robot_mouth.say(robot_brain)
robot_mouth.runAndWait()
Lỗi IndentationError: unindent does not match any outer indentation level
Bạn có thấy các dòng bên trong if - else thụt - thò không giống nhau, chả ra sao vậy không?
Python thì cú pháp phụ thuộc vào thụt lề, thụt lề sai thì sẽ gây lỗi cú pháp.
4 Likes
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?