Hi....
This is @programmer_anonymous!
In this blog i am going to explain you about how to create Jarvis your Desktop Voice assistant.
By using simple python programming.
It is Jarvis voice assistant for your desktop.
Feature of jarvis.
It accepts your Voice commands and reply for your Voice commands.
It opens applications for you.
It play music for you.
Can be update for future use.
First you have to open IDLE of python and write the code given bellow
Code for jarvis in python
*********************************************************************************
import pyttsx3
import webbrowser
import smtplib
import random
import speech_recognition as sr
import wikipedia
import datetime
import wolframalpha
import os
import sys
engine = pyttsx3.init('sapi5')
client = wolframalpha.Client('HELXQ2-GYAEA8JL58')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[len(voices)-1].id)
def speak(audio):
print('Computer: ' + audio)
engine.say(audio)
engine.runAndWait()
def greetMe():
currentH = int(datetime.datetime.now().hour)
if currentH >= 0 and currentH < 12:
speak('Good Morning!')
if currentH >= 12 and currentH < 18:
speak('Good Afternoon!')
if currentH >= 18 and currentH !=0:
speak('Good Evening!')
greetMe()
speak('Hello Sir, I am your digital assistant Jarvis!')
speak('How may I help you?')
def myCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
query = r.recognize_google(audio, language='en-in')
print('User: ' + query + '\n')
except sr.UnknownValueError:
speak('Sorry sir! I didn\'t get that! Try typing the command!')
query = str(input('Command: '))
return query
if __name__ == '__main__':
while True:
query = myCommand();
query = query.lower()
if 'open youtube' in query:
speak('okay')
webbrowser.open('www.youtube.com')
elif 'open google' in query:
speak('okay')
webbrowser.open('www.google.co.in')
elif 'open gmail' in query:
speak('okay')
webbrowser.open('www.gmail.com')
elif "what\'s up" in query or 'how are you' in query:
stMsgs = ['Just doing my thing!', 'I am fine!', 'Nice!', 'I am nice and full of energy']
speak(random.choice(stMsgs))
elif 'email' in query:
speak('Who is the recipient? ')
recipient = myCommand()
if 'me' in recipient:
try:
speak('What should I say? ')
content = myCommand()
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login("Your_Username", 'Your_Password')
server.sendmail('Your_Username', "Recipient_Username", content)
server.close()
speak('Email sent!')
except:
speak('Sorry Sir! I am unable to send your message at this moment!')
elif 'nothing' in query or 'abort' in query or 'stop' in query:
speak('okay')
speak('Bye Sir, have a good day.')
sys.exit()
elif 'hello' in query:
speak('Hello Sir')
elif 'bye' in query:
speak('Bye Sir, have a good day.')
sys.exit()
elif 'play music' in query:
music_folder = Your_music_folder_path
music = [music1, music2, music3, music4, music5]
random_music = music_folder + random.choice(music) + '.mp3'
os.system(random_music)
speak('Okay, here is your music! Enjoy!')
else:
query = query
speak('Searching...')
try:
try:
res = client.query(query)
results = next(res.results).text
speak('WOLFRAM-ALPHA says - ')
speak('Got it.')
speak(results)
except:
results = wikipedia.summary(query, sentences=2)
speak('Got it.')
speak('WIKIPEDIA says - ')
speak(results)
except:
webbrowser.open('www.google.com')
speak('Next Command! Sir!')
*********************************************************************************
Output of jarvis voice assistant.
Setting environment variables
For runnig this code you need to add dependences
1.Add python path to environment variable.
2.For adding dependences open command prompt.
3.pyttsx3 - run 'pip install pyttsx3' on the cmd.
4.speechRecognition - run 'pip install speechRecognition' on the cmd.
5.wolframalpha - run 'pip install wolframalpha' on the cmd.
6.wikipedia - run 'pip install wikipedia' on the cmd.
7.PyAudio - run 'pip install PyAudio' on the cmd.
And your jarvis program is good to run
Thank you for visiting my blog.
No comments:
Post a Comment