Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pyttsx3
- import speech_recognition as sr
- import smtplib
- class Mirror():
- #Initializes the mirror
- def __init__(self):
- #words that should be checked for in commands
- self.keywords=["stop", "switch", "add", "remove"]
- self.engine = pyttsx3.init("sapi5")
- self.voices = self.engine.getProperty("voices")
- self.engine.setProperty("voice", self.voices[0].id)
- #Users Text-To-Speech engine to talk to user
- def Say(self, text=""):
- self.engine.say(text)
- self.engine.runAndWait()
- #Listens to user using Microphone
- def Listen(self):
- r = sr.Recognizer()
- with sr.Microphone() as source:
- audio = r.listen(source)
- try:
- response = r.recognize_google(audio)
- words = response.split()
- if words[0].lower() + " " + words[1].lower() == "hello mirror" or words[0].lower() + " " + words[1].lower() == "hay mirror":
- for word in words:
- if word in self.keywords:
- print(word)
- break
- self.Say("Hello Adam")
- print(words)
- except:
- print("Nothing to Compute")
- #def Commands(self, keyword="", arugment=""):
- m=Mirror()
- while True:
- m.Listen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement