Skip to content

This is a Virtual Desktop Assistant created using Python

License

Notifications You must be signed in to change notification settings

uditshaw/Assistancy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Virtual DeskTop Assistant using Python

A project to build an AI voice assistant using Python . The Voice assistant interacts with the humans to automate daily basic tasks.

About

Assistancy is an AI personal DeskTop assistant service built using Python. It can understand human speech and perform basic daily tasks given by the user.

When the user clicks the "SPEAK" button and specifies the appropriate trigger words , The Assistancy gets activated and executes the user commands accordingly.

If the user commands does not contain the trigger words, it searches using the Wolframe|Alpha API.

Assistancy AI Voice assistant:"Good Morning (Greets the user according to time), I am your Assistancy, How can I help you?"

Acknowledgements

Features

  • Speech to Text conversion
  • Live conversation
  • Interactive GUI
  • Cross platform

Appendix

Users need to specify their email-id and password in order for the program to sign-in into their G-mail account and send email.

Space for userid and password has been provided in line 241 - 243

server.login('<user-name>', '<pass-word>')

server.sendmail('<user-name>', mailIds[to], content)

Prerequisites

Python must be installed in your System. if not, please install python from the following link

Installation

Install Assitancy with pip

  pip install -r requirements.txt

Deployment

To deploy this project run

  python Assistancy.py

Documentation

The implemented Voice assistant can perform the following tasks:

  • Opens a wepage : Youtube , G-Mail , Google , StackOverflow , Amazon , Flipkart , Prime Video , etc.
  User said: hey assistant, open youtube
  • Predicts time
  User said: hey assistant, what is the time?
  • Fetch Top headlines from Times of India
  User said: what's the news today?
  • Abstarct necessary information from wikipedia
  User said: Who is Bill Gates according to Wikipedia

The voice assistant abstarcts first 2 lines of wikipedia and gives the information to the user.

  • Ask geographical and computational questions
  User said: What is the capital of India?
  • Predict Weather of different Cities
  User said: How is the weather of Bhubaneswar?
  • Get your public IP-Address
  User said: What is my ip-Address?
  • Hear jokes from your Virtual assistant
  User said: tell me some joke
  • Open daily used applications like Whatsapp , Telegram , Google Chrome , Office , Zoom
  User said: open chrome
  • Get the latest news on Corona virus
  User said: tell me about Corona
  • Get the Date
  User said: what is today's date
  • Make a note of some reminder
  User said: make a note
  • Hear to some trending music
  User said: hey assistant, play music
  • Send e-mail to saved contacts
  User said: hey assistant, send email
  • Quit the assistant application
  User said: hey assistant, goodbye

Functions() used:

  • speak() Function: It is used to insert the output generated by the program inside the ListBox as well as print and speak [output the voice] through the engine.say() and engine.runAndWait() methods.
  def speak(audio):
    mylist.insert(END, "Assistancy" + " : " + audio)
    root.update()
    print("Assistancy" + " : " + audio)
    engine.say(audio)
    engine.runAndWait()
  • wishMe() Function: This function is used to greet the user according to the time of the day. This function is executed only once when the program begins.
  def wishMe():
    hour = int(datetime.datetime.now().hour)
    if hour >= 0 and hour < 12:
        speak("Good Morning")
    elif hour >= 12 and hour < 17:
        speak("Good Afternoon")
    else:
        speak("Good Evening")

    speak("I am your assistancy. How can i help you?")
  • takeCommand() Function: This function is used to take voice input from the user. It runs in an infinite while loop until the speech recognision function finds some understanding words. The loop begins again if the program was unable to detect any meaningful english commands.
  def takeCommand():
    while(True):

        r = sr.Recognizer()

        with sr.Microphone() as source:

            print("Listening...")
            r.pause_threshold = 1
            audio = r.listen(source, phrase_time_limit=5)

        try:
            print("Recognizing...")
            query = r.recognize_google(audio, language='en-in')
            mylist.insert(END, "User said : " + query)
            root.update()
            print(f"User said: {query}\n")
            return query

        except Exception as e:
            print(e)
            print("Unable to Recognize your voice. Please say again.")
  • date() Function: This function is used to calculate todays date and speak it.
  def date():
    now = datetime.datetime.now()
    my_date = datetime.datetime.today()

    month_name = now.month
    day_name = now.day
    month_names = ['January', 'February', 'March', 'April', 'May', 'June',
                   'July', 'August', 'September', 'October', 'November', 'December']
    ordinalnames = ['1st', '2nd', '3rd', ' 4th', '5th', '6th', '7th', '8th', '9th', '10th', '11th', '12th', '13th', '14th', '15th',
                    '16th', '17th', '18th', '19th', '20th', '21st', '22nd', '23rd', '24rd', '25th', '26th', '27th', '28th', '29th', '30th', '31st']

    speak("Today is " + month_names[month_name-1] +
          " " + ordinalnames[day_name-1] + '.')
  • note() Function: This function is used only when the user gives command to take a note.
  def note(text):
    date = datetime.datetime.now()
    file_name = str(date).replace(":", "-") + "-note.txt"
    with open(file_name, "w") as f:
        f.write(text)

    subprocess.Popen(["notepad.exe", file_name])
  • main() function : Contains the main code of the program where all the functions are invoked and executed.
  def main_function():
    .........       .........

Graphical User Interface (GUI)

The Graphical User Interface is implemented with tkinter library.Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Let's have a look how it is used in this project.

root = Tk()
w = Label(root, text='Welcome back User!')
w.pack()

root.title('Assistancy - your favourite personal assistant')
ourMessage = 'Tool and Techniques Lab, Group - 3'
messageVar = Message(root, text=ourMessage, width=300)
messageVar.config(bg='lightgreen')
messageVar.pack()

# ScrollBar
scrollbar = Scrollbar(root)
scrollbar.pack(side=RIGHT, fill=Y)

# ListBox
mylist = Listbox(root, height=20, width=40, yscrollcommand=scrollbar.set)

mylist.pack(fill=BOTH)
scrollbar.config(command=mylist.yview)
root.geometry('700x500')
root.minsize(700, 500)

The above code creates a frame called root and packs the Label , Message, ScrollBar and ListBox with the root.

frame = Frame(root)
frame.pack()
greenbutton = Button(frame, text='SPEAK', fg='green', command=main_function)
greenbutton.pack(side=LEFT)
redbutton = Button(frame, text='STOP', fg='red', command=root.destroy)
redbutton.pack(side=LEFT)

root.mainloop()

At the end, the root frame is wrapped up and buttons are added to the frame and assigned functionalities to each function.

Libraries that will be installed using Pip install command:

1.Speech recognition

2.Pyttsx3

3.Wikipedia

4.time

5.Wolfram Alpha

In-Built libraries required to be imported:

1.os

2.datetime

3.web browser

4.subprocess

5.sys

Author

Releases

No releases published

Packages

No packages published

Languages