What is Desktop Voice Assistant
Desktop voice assistant is a computer program which listen commands and complete task assigned by the user. It is a example of weak AI which only execute and perform task designed by the programmer.
How to make desktop Voice Assistant
We have to write a program in python for desktop voice assistant.
Modules Required
pyttsx3 - pyttsx3 is a text to speech conversion module in python. pyttsx3 helps us to convert text into speech . We have to import pyttsx3. we write import pyttsx3 to import pyttsx3.
For changing the gender of voice we have to write
Note- If pyttsx3 is not install for some reason , first you have to check the pip list for this we have to write pip list. After that you should go to https://pypi.org/project/pyttsx3 and click the release version and select the version which is in pip list and copy the version paste it in your terminal .
speech_recognition - speech_recognition is a speech to text conversion module in python. speech_recognition helps us to convert speech into text. We have to import speech_recognition . We write import speech_recognition as sr
NOTE- we use sr in place of speech_recognition.
datetime -datetime module provide time .It help us to display date in the program. we write import datetime to import datetime .
webbrowser - webbrowser module help us to collect data from web. we write import webbrowser to import webbrowser.
wikipedia- wikipedia module help us to collect data from wikipedia. we write import wikipedia to import wikipedia.
os- os module help us to open any file, folder ,desktop application .we write import os to import os.
Set up speech engine
We have to store pyttsx3 module in a variable. After that we make a function say().
For this we have to write engine= pyttsx3.init()
Function to greet the user
We define a function wish() for the AI assistant to greet user. the now().hour function abstract the hour from the current time .
If the hour is greater than zero and less than 12 , then assistant wishes user with the message of "Good Morning".
If the hour is greater than 12 and less than 18, then assistant wishes user with the message of "Good Afternoon".
If the hour is greater than 18 then assistant wishes user with the message of "Good Evening".
Set up command function
we have to define a function listen() for the AI assistant to understand the human language . the microphone capture the human speech and recognizer recognizes the speech to take command
We have to take exception handling is used to handle the exception during the run time . We use recognize_google function which uses google audio to recognize speech. For this we have to write
Main function
The main function will check the condition .If the condition is true than it will return output . We use if, else condition for this . we store the human speech stored in variable . So, we make a variable query
Conditions
'open google' in query- When user say open google , then AI assistant will say ' opening google' and open google.com in browser and off the program automatic .
'open youtube' in query- When user say open youtube , then AI assistant will say 'opening youtube' and open youtube in browser and off the program automatic.
'wikipedia' or 'what is' or 'who is' in query- When user say wikipedia or what is or who is , then AI assistant will say 'Searching wikipedia' and say the results .
'play music' in query - When user say play music , then AI assistant will say playing music and play the music and off the program automatic .
'time' in query -When user ask time ,then AI assistant will say the time.
'who are you' in query- When user say who are you ,then AI assistant will say I am Desktop Assistant.
'ok bye' in query - When user say ok bye , then AI assistant will say bye and off the program.
NOTE - you can add more conditions .
HERE ARE THE CODE
OUTPUT