Video:-
Source_Code :-
1. Speek Function
import pyttsx3
import speech_recognition
engine = pyttsx3.init("sapi5")
voices = engine.getProperty("voices")
engine.setProperty("voice", voices[0].id)
rate = engine.setProperty("rate",170)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def takeCommand():
r = speech_recognition.Recognizer()
with speech_recognition.Microphone() as source:
print("Listening.....")
r.pause_threshold = 1
r.energy_threshold = 300
audio = r.listen(source,0,4)
try:
print("Understanding..")
query = r.recognize_google(audio,language='en-in')
print(f"You Said: {query}\n")
except Exception as e:
print("Say that again")
return "None"
return query
2. Greet Me Function
if __name__ == "__main__":
while True:
query = takeCommand().lower()
if "wake up" in query:
from GreetMe import greetMe
greetMe()
while True:
query = takeCommand().lower()
if "go to sleep" in query:
speak("Ok sir , You can me call anytime")
break
Then Make A NEW File named GreetMe.py in VsCode and paste the following:-
import pyttsx3
import datetime
engine = pyttsx3.init("sapi5")
voices = engine.getProperty("voices")
engine.setProperty("voice", voices[0].id)
engine.setProperty("rate",200)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def greetMe():
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<=12:
speak("Good Morning,sir")
elif hour >12 and hour<=18:
speak("Good Afternoon ,sir")
else:
speak("Good Evening,sir")
speak("Please tell me, How can I help you ?")
No comments:
Post a Comment