Skip to content

Commit 25f099c

Browse files
committed
Added files for a smart desktop assistant
1 parent 7cd99a7 commit 25f099c

File tree

2 files changed

+263
-0
lines changed

2 files changed

+263
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
This is an Intelligent Desktop Assistant with Voice Recognition capabilities.
2+
3+
It utilizes various libraries such as
4+
1. speech_recognition
5+
2. pyttsx3
6+
3. pywhatkit
7+
4. datetime
8+
5. wikipedia
9+
6. pyjokes
10+
7. geocoder
11+
8. pyautogui
12+
9. turtle and pygame to provide a range of functionalities.
13+
14+
The assistant can perform tasks like playing songs on YouTube, providing the current time, retrieving information from Wikipedia, telling jokes, capturing screenshots, taking photos using a camera, and even playing a snake game.
15+
16+
The voice recognition feature allows users to interact with the assistant by speaking commands. The program uses the pyttsx3 library for text-to-speech functionality.
17+
18+
Overall, this Smart Desktop Assistant offers a convenient and interactive way to perform various tasks using voice commands.
Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
import speech_recognition as sr
2+
import pyttsx3
3+
import pywhatkit
4+
import datetime
5+
import wikipedia
6+
import pyjokes
7+
import geocoder
8+
import pyautogui
9+
10+
import turtle
11+
import random
12+
13+
import pygame
14+
import pygame.camera
15+
16+
listener = sr.Recognizer()
17+
engine = pyttsx3.init()
18+
voices = engine.getProperty('voices')
19+
engine.setProperty('voice', voices[1].id)
20+
21+
def talk(text):
22+
engine.say(text)
23+
engine.runAndWait()
24+
25+
talk('Hello buddy , What can i help you')
26+
def take_command():
27+
try:
28+
with sr.Microphone() as source:
29+
print('listening...')
30+
voice = listener.listen(source)
31+
command = listener.recognize_google(voice)
32+
command =command.lower()
33+
if 'nova' in command:
34+
command = command.replace('nova', '')
35+
print(command)
36+
except:
37+
pass
38+
return command
39+
40+
def run_alexa():
41+
command =take_command()
42+
print(command)
43+
44+
#play song on youtube
45+
if 'play' in command:
46+
song = command.replace('play', '')
47+
talk('playing' + song)
48+
pywhatkit.playonyt(song)
49+
50+
#Current time
51+
elif 'time' in command:
52+
time = datetime.datetime.now().strftime('%H:%M')
53+
print(time)
54+
talk('Current time is '+ time)
55+
56+
#wikipedia answer
57+
elif 'what is' in command:
58+
person = command.replace('See', '')
59+
info = wikipedia.summary(person, 2)
60+
print(info)
61+
talk(info)
62+
elif 'tell me' in command:
63+
person = command.replace('See', '')
64+
info = wikipedia.summary(person, 2)
65+
print(info)
66+
talk(info)
67+
elif 'who is' in command:
68+
person = command.replace('See', '')
69+
info = wikipedia.summary(person, 2)
70+
print(info)
71+
talk(info)
72+
73+
#fun with nova
74+
elif 'i love you' in command:
75+
talk('i love you too')
76+
elif 'what are you doing' in command:
77+
talk('I am talking to you')
78+
elif 'are you single' in command:
79+
talk('I am relationship with wifi')
80+
81+
elif 'joke' in command:
82+
print(pyjokes.get_joke())
83+
talk(pyjokes.get_joke())
84+
85+
#current location
86+
elif 'location' in command:
87+
g = geocoder.ip('me')
88+
print(g.city)
89+
talk('your current location is' + g.city)
90+
91+
#take a screen shot
92+
elif 'screenshot' in command:
93+
im = pyautogui.screenshot()
94+
im.save("SS1.jpg")
95+
96+
#Take some photo
97+
elif 'take a photo' in command:
98+
pygame.camera.init()
99+
camlist = pygame.camera.list_cameras()
100+
if camlist:
101+
cam = pygame.camera.Camera(camlist[0], (640, 480))
102+
cam.start()
103+
image = cam.get_image()
104+
pygame.image.save(image, "filename.jpg")
105+
else:
106+
print("No camera on current device")
107+
108+
109+
#play snake game
110+
elif 'snake game' in command:
111+
w = 500
112+
h = 500
113+
food_size = 10
114+
delay = 100
115+
116+
offsets = {
117+
"up": (0, 20),
118+
"down": (0, -20),
119+
"left": (-20, 0),
120+
"right": (20, 0)
121+
}
122+
123+
def reset():
124+
global snake, snake_dir, food_position, pen
125+
snake = [[0, 0], [0, 20], [0, 40], [0, 60], [0, 80]]
126+
snake_dir = "up"
127+
food_position = get_random_food_position()
128+
food.goto(food_position)
129+
move_snake()
130+
131+
def move_snake():
132+
global snake_dir
133+
134+
new_head = snake[-1].copy()
135+
new_head[0] = snake[-1][0] + offsets[snake_dir][0]
136+
new_head[1] = snake[-1][1] + offsets[snake_dir][1]
137+
138+
139+
if new_head in snake[:-1]:
140+
reset()
141+
else:
142+
snake.append(new_head)
143+
144+
145+
if not food_collision():
146+
snake.pop(0)
147+
148+
149+
if snake[-1][0] > w / 2:
150+
snake[-1][0] -= w
151+
elif snake[-1][0] < - w / 2:
152+
snake[-1][0] += w
153+
elif snake[-1][1] > h / 2:
154+
snake[-1][1] -= h
155+
elif snake[-1][1] < -h / 2:
156+
snake[-1][1] += h
157+
158+
159+
pen.clearstamps()
160+
161+
162+
for segment in snake:
163+
pen.goto(segment[0], segment[1])
164+
pen.stamp()
165+
166+
167+
screen.update()
168+
169+
turtle.ontimer(move_snake, delay)
170+
171+
def food_collision():
172+
global food_position
173+
if get_distance(snake[-1], food_position) < 20:
174+
food_position = get_random_food_position()
175+
food.goto(food_position)
176+
return True
177+
return False
178+
179+
def get_random_food_position():
180+
x = random.randint(- w / 2 + food_size, w / 2 - food_size)
181+
y = random.randint(- h / 2 + food_size, h / 2 - food_size)
182+
return (x, y)
183+
184+
def get_distance(pos1, pos2):
185+
x1, y1 = pos1
186+
x2, y2 = pos2
187+
distance = ((y2 - y1) ** 2 + (x2 - x1) ** 2) ** 0.5
188+
return distance
189+
def go_up():
190+
global snake_dir
191+
if snake_dir != "down":
192+
snake_dir = "up"
193+
194+
def go_right():
195+
global snake_dir
196+
if snake_dir != "left":
197+
snake_dir = "right"
198+
199+
def go_down():
200+
global snake_dir
201+
if snake_dir!= "up":
202+
snake_dir = "down"
203+
204+
def go_left():
205+
global snake_dir
206+
if snake_dir != "right":
207+
snake_dir = "left"
208+
209+
210+
screen = turtle.Screen()
211+
screen.setup(w, h)
212+
screen.title("Snake")
213+
screen.bgcolor("blue")
214+
screen.setup(500, 500)
215+
screen.tracer(0)
216+
217+
218+
pen = turtle.Turtle("square")
219+
pen.penup()
220+
221+
222+
food = turtle.Turtle()
223+
food.shape("square")
224+
food.color("yellow")
225+
food.shapesize(food_size / 20)
226+
food.penup()
227+
228+
229+
screen.listen()
230+
screen.onkey(go_up, "Up")
231+
screen.onkey(go_right, "Right")
232+
screen.onkey(go_down, "Down")
233+
screen.onkey(go_left, "Left")
234+
235+
236+
reset()
237+
turtle.done()
238+
239+
240+
#any command doesn't match nova talk this line
241+
else:
242+
talk('Please say the command again.')
243+
244+
while True:
245+
run_alexa()

0 commit comments

Comments
 (0)