Professional Documents
Culture Documents
Virtual desktop assistant is an awesome thing. If you want your machine to run
on your command like Jarvis did for Tony. Yes it is possible. It is possible using
Python. Python offers a good major library so that we can use it for making a
virtual assistant. Windows has Sapi5 and Linux has Espeak which can help us in
having the voice from our machine. It is a weak A.I.
Modules needed
pyttsx is a cross-platform text to speech library which is platform independent.
The major advantage of using this library for text-to-speech conversion is that it
works offline. To install this module type the below command in the terminal.
pip install pyttsx3
SpeechRecognition: It allow us to convert audio into text for further
processing. To install this module type the below command in the terminal.
pip install SpeechRecognition
webbrowser :It provides a high-level interface which allows displaying Web-
based documents to users. To install this module type the below command in the
terminal.
pip install webbrowser
Wikipedia: It is used to fetch a variety of information from the Wikipedia
website. To install this module type the below command in the terminal.
pip install wikipedia
3) takeCommand method
This method is for taking the commands and recognizing the command from the
speech_Recognition module
4) Hello method
This is just used to greet the user with a hello message.
5) Main method
Main method is the method where all the files get executed so we will call the
Take_query method here so that it can recognize and tell or give us the desired
output.
Complete Code:
import pyttsx3
import speech_recognition as sr
import webbrowser
import datetime
import wikipedia
except Exception as e:
print(e)
print("Say that again sir")
return "None"
return Query
def speak(audio):
engine = pyttsx3.init()
# getter method(gets the current value
# of engine property)
voices = engine.getProperty('voices')
def tellDay():
if day in Day_dict.keys():
day_of_the_week = Day_dict[day]
print(day_of_the_week)
speak("The day is " + day_of_the_week)
def tellTime():
def Hello():
# This function is for when the assistant
# is called it will say hello and then
# take query
speak("hello sir I am your desktop assistant. /
Tell me how may I help you")
def Take_query():
if __name__ == '__main__':
Output: