Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. import pyttsx3
  2. import speech_recognition as sr
  3. import smtplib
  4.  
  5.  
  6. class Mirror():
  7.     #Initializes the mirror
  8.     def __init__(self):
  9.         #words that should be checked for in commands
  10.         self.keywords=["stop", "switch", "add", "remove"]
  11.  
  12.         self.engine = pyttsx3.init("sapi5")
  13.         self.voices = self.engine.getProperty("voices")
  14.         self.engine.setProperty("voice", self.voices[0].id)
  15.  
  16.     #Users Text-To-Speech engine to talk to user
  17.     def Say(self, text=""):
  18.         self.engine.say(text)
  19.         self.engine.runAndWait()
  20.  
  21.     #Listens to user using Microphone
  22.     def Listen(self):
  23.         r = sr.Recognizer()
  24.         with sr.Microphone() as source:
  25.             audio = r.listen(source)   
  26.         try:
  27.             response = r.recognize_google(audio)
  28.             words = response.split()
  29.             if words[0].lower() + " " + words[1].lower() == "hello mirror" or words[0].lower() + " " + words[1].lower() == "hay mirror":
  30.                 for word in words:
  31.                     if word in self.keywords:
  32.                         print(word)
  33.                         break
  34.                 self.Say("Hello Adam")
  35.             print(words)
  36.         except:
  37.             print("Nothing to Compute")
  38.            
  39.            
  40.     #def Commands(self, keyword="", arugment=""):
  41.        
  42.    
  43.    
  44.    
  45.  
  46. m=Mirror()
  47.  
  48. while True:
  49.     m.Listen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement