code lập trình trợ lý ảo bởi N.B.L
code lập trình trợ lý ảo ở đây nhưng các bạn phải cài thư viên là pyttsx3, speechrecognition và pyaudio
cú pháp: (pip install pipwin, pipwin install pyaudio) (pip install pyttx3) (pip install pyaudio) nếu các bạn bị mắc lỗi 'pip' is not recognized thì bạn lên mạng tìm và phải gõ bằng tiếng anh thì nó sẽ cho kết quả chất lượng hơn
code:
import speech_recognition
import pyttsx3
from datetime import date, datetime
while 1:
robot_ear = speech_recognition.Recognizer()
robot_mouth = pyttsx3.init()
robot_brain = ""
with speech_recognition.Microphone() as mic:
print("Robot:I am listening")
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 "hello" in you:
robot_brain = "hello bao lam"
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:%M:%S")
elif "tired" in you:
robot_brain = "no, thanks"
elif "happy" in you:
robot_brain = "yes, i am so happy"
elif "vagina" in you:
robot_brain = "yes i have a big vagina"
elif "bye" in you:
robot_brain = "Bye bao lam"
print("Robot:" + robot_brain)
robot_mouth.say(robot_brain)
robot_mouth.runAndWait()
break
else:
robot_brain = "i am fine thank you and you"
print("Robot:" + robot_brain)
robot_mouth.say(robot_brain)
robot_mouth.runAndWait()
copy hết ở đây
tốt
Trả lờiXóa