Last active
January 28, 2024 11:42
-
-
Save brayn003/e3367283d1137e1fc237a685fdcae2dc to your computer and use it in GitHub Desktop.
Jarvis voice assistant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyttsx3 | |
import datetime | |
import speech_recogncition as sr | |
import wikipedia | |
import webbrowser | |
engine = pyttsx3.init() | |
# voices = engine.getProperty('voices') | |
# engine.setProperty('voice', voices[13].id) | |
def speak(text): | |
print(f'[JARVIS]: {text}') | |
engine.say(text) | |
engine.runAndWait() | |
def wish_me(): | |
hour = int(datetime.datetime.now().hour) | |
greeting = '' | |
if hour>=0 and hour<12: | |
greeting = 'Good morning!' | |
elif hour>=12 and hour<18: | |
greeting = 'Good afternoon!' | |
else: | |
greeting = 'Good evening!' | |
speak(f'{greeting} I am Jarvis. How may I help you today?') | |
def takeCommand(): | |
#It takes microphone input from the user and returns string output | |
r = sr.Recognizer() | |
with sr.Microphone() as source: | |
print("Listening...") | |
r.pause_threshold = 1 | |
audio = r.listen(source) | |
try: | |
print("Recognizing...") | |
query = r.recognize_google(audio, language='en-in') | |
print(f"[Me]: {query}") | |
except Exception as e: | |
# print(e) | |
return "None" | |
return query | |
# script starts here | |
wish_me() | |
while True: | |
# if 1: | |
query = takeCommand().lower() | |
# Logic for executing tasks based on query | |
query = query.replace('jarvis', '') | |
if 'wikipedia' in query: | |
speak('Searching Wikipedia...') | |
query = query.replace("wikipedia", "") | |
query = query.replace("search", "") | |
query = query.replace("for", "") | |
results = wikipedia.summary(query, sentences=1) | |
speak(f'According to Wikipedia, {results}') | |
elif 'open youtube' in query: | |
speak('Opening Youtube') | |
webbrowser.open("https://youtube.com") | |
elif 'open google' in query: | |
speak('Opening Google') | |
webbrowser.open("https://google.com") | |
elif 'open stack overflow' in query: | |
speak('Opening StackOverflow') | |
webbrowser.open("https://stackoverflow.com") | |
elif 'what' in query and 'time' in query: | |
strTime = datetime.datetime.now().strftime("%H:%M:%S") | |
speak(f"Sir, The time is {strTime}") | |
elif 'meaning of life' in query: | |
speak('Sir, the meaning of life is 42.') | |
elif 'how are you' in query: | |
speak('I am doing jolly good, sir.') | |
else: | |
speak('I didn\'t quiet catch you sir. Can you please try that again?') | |
At line 54 , I am getting error at (query = takeCommand().lower()) , this lower word is underlined in red color. Can someone help me??
nice bro
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ManasviSadhwani
@jyotisp
@HusainKagalwala07
I also joined the Zoom Workshop. So for fixing this issues you have to download following modules:
Go to Start and search for CMD right click on it and click on run as administrator.
after you open CMD, just type the following commands one by one. Wait for one to complete then type another command.
Commands:
pip install pyttsx3
pip install SpeechRecognition
pip install wikipedia
pip install pywin32
pip install pipwin
pipwin install PyAudio