Skip to content

Commit 757c296

Browse files
authored
Add files via upload
1 parent 3949efa commit 757c296

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed

AI.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import pyttsx3 #Python Text To Speech module to read inputs from the users.
2+
import speech_recognition as sr
3+
import pyaudio
4+
import datetime
5+
import wikipedia
6+
import webbrowser
7+
import os
8+
9+
engine = pyttsx3.init('sapi5')
10+
voices = engine.getProperty('voices')
11+
engine.setProperty('voice', voices[0].id)
12+
13+
14+
def speak(audio):
15+
engine.say(audio)
16+
engine.runAndWait()
17+
18+
19+
def wishMe():
20+
hour = int(datetime.datetime.now().hour)
21+
if hour >= 0 and hour < 12:
22+
speak("Good Morning sir!")
23+
24+
elif hour >= 12 and hour < 16:
25+
speak("Good Afternoon sir!")
26+
27+
else:
28+
speak("Good Evening sir!")
29+
30+
speak('I am Morris. Please tell me. How may I help you?')
31+
32+
33+
def takeCommand():
34+
# It takes microphone input from the user and returns string output
35+
36+
r = sr.Recognizer()
37+
with sr.Microphone() as source:
38+
print("Listening...")
39+
# listen for 5 seconds and calculate the ambient noise energy level
40+
r.adjust_for_ambient_noise(source, duration=5)
41+
r.energy_threshold = 4000
42+
r.dynamic_energy_threshold = True
43+
r.pause_threshold = 1
44+
audio = r.listen(source)
45+
46+
try:
47+
print("Recognizing...")
48+
query = r.recognize_google(audio, language="en-in")
49+
print(f"User said: {query}\n")
50+
51+
except Exception as e:
52+
print(e)
53+
print("Say that again please...")
54+
return "None"
55+
return query
56+
57+
58+
if __name__ == "__main__":
59+
wishMe()
60+
61+
while True:
62+
# if 1:
63+
query = takeCommand().lower()
64+
65+
# Logic for executing tasks based on query
66+
if 'wikipedia' in query:
67+
speak('Searching Wikipedia...')
68+
query = query.replace('wikipedia', '')
69+
results = wikipedia.summary(query, sentences=2)
70+
speak('According to Wikipedia')
71+
# print(results)
72+
speak(results)
73+
74+
elif 'open youtube' in query:
75+
webbrowser.open('youtube.com')
76+
77+
elif 'open Google' in query:
78+
webbrowser.open('google.com')
79+
80+
elif 'open stackoverflow' in query:
81+
webbrowser.open('stackoverflow.com')
82+
83+
elif 'play music' in query:
84+
music_dir = 'C:\\Users\\pro tricks\\Music\\Trap'
85+
songs = os.listdir(music_dir)
86+
print(songs)
87+
os.startfile(os.path.join(music_dir, songs[0]))
88+
89+
elif 'time' in query:
90+
strTime = datetime.datetime.now().strftime("%H:%M:%S")
91+
speak(f"Sir, the time is {strTime}")

app.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This program says hello and asks for my name.
2+
3+
# print('Hello world!')
4+
# print('What is your name?') # ask for their name
5+
# myName = input()
6+
# print('It is good to meet you, ' + myName)
7+
# print('The length of your name is:')
8+
# print(len(myName))
9+
10+
# print('What is your age?') # ask for their age
11+
# myAge = input()
12+
# print('You will be ' + str(int(myAge) + 1) + ' in a year.')
13+
14+
# name = input('Enter your name: ')
15+
# age = int(input('How old are you, {0}? '.format(name)))
16+
# print(age)
17+
18+
# if age >= 18:
19+
# print("You're eligible to vote")
20+
21+
# else:
22+
# print("You're not eligible")
23+
24+
class ClassOne:
25+
__var_one = 1001
26+
27+
def __init__(self, __var_two):
28+
self.__var_two = __var_two
29+
self.__var_five = 5
30+
31+
def methodOne(self):
32+
var_four = 50
33+
self.__var_five = ClassOne.__var_one+self.__var_two+var_four

0 commit comments

Comments
 (0)