1# J.A.R.V.I.S in pyton (;
2
3import speech_recognition as sr
4import pyttsx3
5import datetime
6
7
8
9engine = pyttsx3.init('sapi5')
10voices = engine.getProperty('voices')
11# print(voices[1].id) Searchig for voices
12engine.setProperty('voice', voices[1].id) # Zira(girl)
13
14
15def speak(audio):
16 engine.say(audio)
17 engine.runAndWait()
18
19def wishMe():
20 hour = int(datetime.datetime.now().hour)
21 if hour>=0 and hour<12:
22 speak("Good Morning!")
23
24 elif hour>=12 and hour<18:
25 speak("Good Afternoon!")
26
27 else:
28 speak("Good Evening!")
29
30 speak("I am JARVIS, Sir, How can I help you?")
31
32def takeCommand():
33
34 r = sr.Recognizer()
35 with sr.Microphone() as source:
36 print("Listening...")
37 r.pause_threshold = 1
38 audio = r.listen(source)
39
40 try:
41 print("Recognizing...")
42 query = r.recognize_google(audio, language='en-in')
43 print(f"User said: {query}\n")
44
45 except Exception as e:
46 # print(e)
47 print("Say that again please...")
48 return "None"
49 return query
50
51if __name__ == '__main__':
52 wishMe()
53 takeCommand()