0% found this document useful (0 votes)
21 views7 pages

Jarvis

This document contains code for an AI assistant named Siri that can perform tasks like telling the time, searching the web, playing music and more using various Python libraries like Pyttsx3, SpeechRecognition, Wikipedia, Datetime and OS.

Uploaded by

Bhushan Gajare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views7 pages

Jarvis

This document contains code for an AI assistant named Siri that can perform tasks like telling the time, searching the web, playing music and more using various Python libraries like Pyttsx3, SpeechRecognition, Wikipedia, Datetime and OS.

Uploaded by

Bhushan Gajare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

import pyttsx3

import speech_recognition as sr

import datetime

import wikipedia

import webbrowser

import os

import urllib

import requests

from bs4 import BeautifulSoup

import sys

from youtube_search import YoutubeSearch

import smtplib

print("Initialising Siri....")

MASTER = "Yashoditya"

AI = "Siri"

engine = pyttsx3.init('sapi5')

voices = engine.getProperty('voices')

engine.setProperty('voice', voices[1].id)

def speak(text):

engine.say(text)

engine.runAndWait()

#Main Program starts here


#This function will wish me

def wishMe():

hour = int(datetime.datetime.now().hour)

if hour>=0 and hour <12:

speak("Good Morning" + MASTER)

elif hour>=12 and hour<16:

speak("Good Afternoon" +MASTER)

else:

speak("Good Evening" + MASTER)

print(hour)

speak("How may i help you?")

#This function will take command from me(via microphone)

def takeCommand():

r = sr.Recognizer()

with sr.Microphone() as source:

print("Listening...")

audio = r.listen(source)

try :

print("Recognising...")

query = r.recognize_google(audio, language = 'en-in')

print(f"user said: {query}\n")


except Exception as e:

print(MASTER + " ,Say that again please!")

speak(MASTER + " ,Say that again please!")

query = None

return query

#Main Program starts here

speak("Initialising " + AI + (" ..."))

wishMe()

query = takeCommand()

# Logic for executing tasks as per the query

def respond(query, readmenews="https://news.google.com/topstories?hl=en-


IN&gl=IN&ceid=IN:en"):

if 'wikipedia' in query:

speak('Searching Wikipedia...')

query = query.replace("wikipedia", "")

results = wikipedia.summary(query, sentences=3)

print(results)

speak(results)

elif "find location of" in query.lower():

location = query
query = query.replace("find location of", "")

url = "https://google.nl/maps/place/" + query + '/&amp;'

webbrowser.get().open(url)

speak("Here is the location of " + query)

elif "can you talk" in query.lower():

speak("Yes I can talk like a human")

elif 'who made you' in query.lower():

speak("Yashoditya made me")

elif 'how old are you' in query.lower():

speak("I am as old as you")

elif "What is your name?" in query.lower():

speak("My name is" + AI + "Its nice to meet you!")

elif 'who are you?' in query.lower():

speak("My name is" + AI + "Its nice to meet you!")

elif "search" in query:

query = query.replace("search", "")

url = "https://google.com/search?q=" + query

webbrowser.get().open(url)

speak("Here is what I found for" + query)

elif 'open youtube' in query.lower():


url = "youtube.com"

chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'

webbrowser.get(chrome_path).open(url)

speak("Youtube is now opening...")

elif 'open google' in query.lower():

url = "google.com"

chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'

webbrowser.get(chrome_path).open(url)

speak("Google is now opening...")

elif 'YouTube search' in query.lower():

query = query.replace("YouTube search","")

speak("Searching youtube")

url = 'https://www.youtube.com/results?search_query=' + query

webbrowser.get().open(url)

speak("Here is what I searched on youtube for" + query)

elif 'open google and search' in query.lower():

query = query.replace("open google and search", "")

speak("opening google")

url = "https://google.com/search?q=" + query

webbrowser.get().open(url)

speak("Here is what I found for" + query)


elif 'open hotstar' in query.lower():

# webbrowser.open("youtube.com")

url = "hotstar.com"

chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'

webbrowser.get(chrome_path).open(url)

speak("Hotstar is now opening...")

elif 'open primevideo' in query.lower():

# webbrowser.open("youtube.com")

url = "primevideo.com"

chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'

webbrowser.get(chrome_path).open(url)

speak("Prime Video is now opening...")

elif 'play music' in query.lower():

songs_dir = "C:\\Users\\Administrator\\Desktop"

songs = os.listdir(songs_dir)

print(songs)

os.startfile(os.path.join(songs_dir, songs[0]))

elif 'time' in query.lower():

strTime = datetime.datetime.now().strftime("%H:%M:%S")

speak(f"{MASTER} the time is {strTime}")

elif 'end' in query.lower():

speak(" Goodbye!Feeling sad that you are leaving")


sys.exit()

elif 'News' or 'updates' in query.lower():

speak("Anything else you want me to do?")

while (1):

query = takeCommand()

respond(query)

You might also like