my personal assistant | JARVIS | python project by Professor
uploaded:: 2:11:14pm 3 May 2021
my first python project | personal assistant | jarvis
You can use this code for your project. It can search video on youtube and your query on google and also tell you the current time.
**Download Executable file and run this program in you computer (Windows only) : click here
It works online so please on mobile data/wifi
import speech_recognition as sr
import webbrowser as wb
import pyttsx3
from datetime import datetime
jarvis = pyttsx3.init()
r1 = sr.Recognizer()
print("hello I am jarvis how can i help you")
jarvis.say("hello I am jarvis how can i help you")
jarvis.runAndWait()
with sr.Microphone() as source:
print("say something sir...")
jarvis.say("say something sir")
jarvis.runAndWait()
print("Hint: open google, open youtube, tell me time jarvis")
try:
r1.adjust_for_ambient_noise(source)
audio = r1.listen(source)
print(r1.recognize_google(audio).lower())
if 'youtube' in r1.recognize_google(audio).lower():
r2 = sr.Recognizer()
url = "https://www.youtube.com/results?search_query="
with sr.Microphone() as source:
print('Name of video you want to search...')
jarvis.say("Name of video you want to search")
jarvis.runAndWait()
r2.adjust_for_ambient_noise(source)
audio = r2.listen(source)
try:
get = r2.recognize_google(audio).lower()
print("searching " + get + " on youtube")
jarvis.say("searching " + get + " on google")
jarvis.runAndWait()
#change this path with your browser's path
chrome_path = "C:\Program Files\Google\Chrome\Application\chrome.exe"
wb.open(url + get)
except sr.UnknownValueError:
print('could not understand')
jarvis.say('could not understand')
jarvis.runAndWait()
except sr.RequestError as e:
print('failed to get results'.format(e))
if 'google' in r1.recognize_google(audio).lower():
r2 = sr.Recognizer()
url = "https://www.google.com/search?q="
with sr.Microphone() as source:
print('what you want to search...')
jarvis.say("what you want to search...")
jarvis.runAndWait()
r2.adjust_for_ambient_noise(source)
audio = r2.listen(source)
try:
get = r2.recognize_google(audio).lower()
print("searching "+get+ " on google")
jarvis.say("searching "+get+ " on google")
jarvis.runAndWait()
chrome_path = "C:\Program Files\Google\Chrome\Application\chrome.exe"
wb.open(url + get)
except sr.UnknownValueError:
print('could not understand google')
jarvis.say('could not understand')
jarvis.runAndWait()
except sr.RequestError as e:
print('failed to get results'.format(e))
if 'time' in r1.recognize_google(audio).lower():
try:
strTime = datetime.now().strftime("%H:%M:%S")
print("the time is ", strTime)
jarvis.say(f"the time is {strTime}")
jarvis.runAndWait()
except sr.UnknownValueError:
print('could not understand')
jarvis.say('could not understand')
jarvis.runAndWait()
except sr.RequestError as e:
print('failed to get results'.format(e))
except sr.UnknownValueError:
print('could not understand last')
jarvis.say('could not understand')
jarvis.runAndWait()
except sr.RequestError as e:
print('failed to get results'.format(e))
for any query contact: fahad@blogiez.com