Virtual Assistant using Python : Part 1
In this series of articles, we are to going to make a virtual assistant in python just like tony stark Jarvis. It will do tasks on our behalf such as play songs for us, open a website for us, tell us top headlines from newspaper and much more to discover in this series of articles so let’s start our journey of building our python project of a virtual assistant.
In python, there are a huge number of libraries that will help us in our journey of building a virtual assistant in python.
So let’s start with the task virtual assistant using python code:
🎯🎯Modules that are needed for our virtual assistant program in python are given below:
📕pyttsx3:
pyttsx3 module in python is a library available in python which is used for text to speech conversion in python. It is platform-independent and works for all platforms. It also works offline so it is best for use without the internet.
To install the library use the below command:
pip install pyttsx3
if the installation has been successfully completed, use the below command to check whether the library is installed successfully or not.
pip show pyttsx3
to import the library in our program use the below command:
import pyttsx3
to do the text to speech conversion we need an object which will help us to use pyttsx3 efficiently.
to create an object using pyttsx3 use the below lines of code:
assistant=pyttsx3.init() # it will initialize a object named assistant for us
📙📙Options available with pyttsx3 are given below:
💿Rate:
To set the rate with which the virtual assistant in python will speak use the below function provided by pyttsx3. The default value of the rate function is 200.
rate = assistant.getProperty(‘rate’) # get the details about the current rate of assistant
print (rate) # display the current voice rate
assistant.setProperty(‘rate’, 125) # set the voice rate
📕Volume:
volume function is used to set the volume level of the virtual assistant in python. It lies between 0.0 to 1.0 inclusive both values.
you can set the volume of the virtual assistant by using the following line of code:
volume = assistant.getProperty(‘volume’) # to know the current volume level of assistant
print (volume) # print the current volume level
assistant.setProperty(‘volume’,1.0) # reset the volume level between 0 to 1
🧐Voice:
This property is used to set the voice of the virtual assistant in python. By default 0 index is used for male voice and 1 index is used for female voice.
you can set the voice of virtual assistant by using following lines of code:
voices = assistant.getProperty('voices') #to know about the current voice
assistant.setProperty('voice', voices[0].id) #changing indexes ,0 for male
assistant.setProperty('voice', voices[1].id) # 1 for female
this is all about pyttsx3 module in python. In the next article we will discuss about more modules we are going to use in our virtual assistant using python code. So stay tuned for next article.
Share it if you love it.👍👍👍👍
Click here for part 2 of virtual assistant in python.
Would you like to see your article here on tutorialsinhand.
Join
Write4Us program by tutorialsinhand.com
About the Author
Ayush Bajpai
I am a data science enthusiast. I love to learn new technology 🛠🛠.you can reach me at this url www.linkedin.com/in/ayushbajpai47
Page Views :
Published Date :
Jun 01,2021