-
-
Save brayn003/e3367283d1137e1fc237a685fdcae2dc to your computer and use it in GitHub Desktop.
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?') | |
Traceback (most recent call last):
File "C:\Users\hussa\Anaconda3\envs\JARVIS\lib\site-packages\speech_recognition_init_.py", line 108, in get_pyaudio
import pyaudio
ModuleNotFoundError: No module named 'pyaudio'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/hussa/PycharmProjects/JARVIS/JARVIS.py", line 68, in
takeCommand()
File "C:/Users/hussa/PycharmProjects/JARVIS/JARVIS.py", line 52, in takeCommand
with sr.Microphone() as source:
File "C:\Users\hussa\Anaconda3\envs\JARVIS\lib\site-packages\speech_recognition_init_.py", line 79, in init
self.pyaudio_module = self.get_pyaudio()
File "C:\Users\hussa\Anaconda3\envs\JARVIS\lib\site-packages\speech_recognition_init_.py", line 110, in get_pyaudio
raise AttributeError("Could not find PyAudio; check installation")
AttributeError: Could not find PyAudio; check installation
Hello I am facing this issue when I am trying to run the takeCommand( ) function
I too got the same error as HusainKagalwala07
hello, I am getting this error. Also I tried installing pyaudio package but there is some installation error.
Traceback (most recent call last):
File "C:\Users\hussa\Anaconda3\envs\JARVIS\lib\site-packages\speech_recognition_init_.py", line 108, in get_pyaudio
import pyaudio
ModuleNotFoundError: No module named 'pyaudio'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/hussa/PycharmProjects/JARVIS/JARVIS.py", line 68, in
takeCommand()
File "C:/Users/hussa/PycharmProjects/JARVIS/JARVIS.py", line 52, in takeCommand
with sr.Microphone() as source:
File "C:\Users\hussa\Anaconda3\envs\JARVIS\lib\site-packages\speech_recognition_init_.py", line 79, in init
self.pyaudio_module = self.get_pyaudio()
File "C:\Users\hussa\Anaconda3\envs\JARVIS\lib\site-packages\speech_recognition_init_.py", line 110, in get_pyaudio
raise AttributeError("Could not find PyAudio; check installation")
AttributeError: Could not find PyAudio; check installation
@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
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
Hello! I'm an attendee of your Zoom workshop on Jarvis voice assistant. I am unable to run this code even after installing all packages.
This is the first error I'm getting: