An embedded assistant can open an application (if installed on the system), search for a query on Google, Wikipedia and YouTube, calculate any math question, etc., simply by typing a voice command . We can process data as needed or add functionality depending on how we code things.
We use the Google Speech Recognition API and Google Text to Speech for voice input and output, respectively.
You can also use the WolframAlpha API to calculate a mathematical expression.
Playsound package is used to play saved mp3 sound from the system.
External Python package Requirements:
- & gt; gTTS - Google Text To Speech, for converting the given text to speech
- & gt; speech_recognition - for recognizing the voice command and converting to text
- & gt; selenium - for web based work from browser
- & gt; wolframalpha - for calculation given by user
- & gt; playsound - for playing the saved audio file.
- & gt; pyaudio - for voice engine in python
Well, let's start with the code. We'll split each function as a single code for easy understanding.
Here is the main function with
get_audio () and
get_audio () is designed to receive audio from a user using a microphone, the phrase limit is set to 5 seconds (you can change it). The Assistant function says to provide output consistent with the processed data.
So, we have an idea of how we sound the device and take part from the user. The next step and the main step — how you want to process your input. This is just basic code, many other algorithms (NLP) can be used to process the text appropriately. We made it static.
Wolframalpha api was used to calculate the computational part.
Now we have processed the input, it's time to act!
search_web two functions:
search_web & # 8212 ; it's just a scanner that uses a selenium package to process it. It can search Google , Wikipedia and can open YouTube . You just need to provide a name and it will open in the Firefox browser. For other browsers, you need to install the corresponding browser package in Selen. Here we are using the web driver for Firefox.
open_application — it is just a function that uses the os package to open an application present on the system.
undefined spaces ">