In this project, we going to create a voice assistant in python programming. We will start with the working logic of the voice assistant and then we will create a voice assistant that is not too complex. After this article, you can add your own commands.
What is Voice Assistant?
Voice assistants, which we often encounter on phones, are programs that perform a task, they perform the data they receive from the user. The assistant translates the information she received as a voice into text and then performs the process.
Institution of required libraries
3 libraries will be used for this project, pyaudio, SpeechRecognition, and gTTS. Supports pyauido libraries, gtts converts texts to voices, SpeechRecognition converts voices to text.
pip install gTTS
pip install Pyaudio
pip install SpeechRecognition
Understand the Text-to-Speech Transition
gTTS library is used to switch from text to voice, it is very simple to use, the logic is to transfer the texts to audio files. We can make it easier to open files with the os library.
from import gTTS as tt import os file = tt(text = "Hi, Sure!" , lang = "en") file.save("Voice.mp3") os.system("Voice.mp3")
When the program is started, it voices the text in the text section in English and loads it into the file, then the os library opens the file.
Making Own Voice Assistant
When the basics are over, it’s time to create a personal voice assistant. Our assistant will be able to open websites, tell the time and start applications.
Let’s examine the program piece by piece, first, we call a different library, the web browser library serves to open a site with the help of the URL. The time module gives us the chance to pause the program.
The speak function creates an audio file, saves and runs it according to the given argument. In this section, we select the language, the language that the narrator will speak can be selected over lang.
After the function creation process is finished, we want a name, then we keep the name in a named variable so we can call the name with the format function.
The commands are asked in the loop, and after each command executed, it is expected for 2 seconds with the time.sleep function and continues. In the example here, when you say the name of the site you want, the site will open.