forked from ronitraj74/python-Learning-code
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPROJECT_2_VOICE_ASSISTANT.PY
More file actions
67 lines (54 loc) · 1.82 KB
/
PROJECT_2_VOICE_ASSISTANT.PY
File metadata and controls
67 lines (54 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import speech_recognition as sr
import pyttsx3
import webbrowser
import datetime
import wikipedia
# initialize
engine = pyttsx3.init()
recognizer = sr.Recognizer()
def speak(text):
engine.say(text)
engine.runAndWait()
def listen():
with sr.Microphone() as source:
print("Listening...")
audio = recognizer.listen(source)
try:
command = recognizer.recognize_google(audio)
print("You said:", command)
return command.lower()
except:
speak("Sorry, I didn't catch that")
return ""
def process_command(command):
if "hello" in command:
speak("Hello Ronit! How can I help you?")
elif "time" in command:
time = datetime.datetime.now().strftime("%H:%M")
speak(f"The time is {time}")
elif "open youtube" in command:
webbrowser.open("https://www.youtube.com")
speak("Opening YouTube")
elif "open my github profile" in command:
webbrowser.open("https://www.github.com/Ronit049")
speak("Opening Your github profile Ronit")
elif "open my Twitter profile" in command:
webbrowser.open("https://x.com/its_rsr04")
speak("Opening your twitter profile")
elif "search" in command:
speak("What should I search?")
query = listen()
webbrowser.open(f"https://www.google.com/search?q={query}")
elif "wikipedia" in command:
speak("Searching Wikipedia...")
query = command.replace("wikipedia", "")
result = wikipedia.summary(query, sentences=2)
speak(result)
elif "exit" in command:
speak("Goodbye!")
exit()
# main loop
speak("Voice assistant started")
while True:
command = listen()
process_command(command)