To build such an assistant, the foremost thing you need is speech recognition. Python is equipped with an application programming interface (API) called SpeechRecognition which will allow audio to be converted into text.
Why do we need this conversion? So that our voice audio is translated into text or a code that our virtual assistant can process digitally and carry out our command. For things to run smoothly, we need various other modules as well. A Python module is nothing but some related codes that are saved in a file, with a “.py” extension.
The modules called subprocesses are inbuilt in Python, whose commands deal with system subprocesses like restart and shut down. You will find all the details you need in any good full stack web development course.
The Packages Required and the Libraries to Import
Since we know what modules are, a package is a list of modules and a library is a list of packages. Let’s say one is creating an app and he/she needs to do some multiplication or addition and a list of operations is in a library. So, he/she can easily import one library to do those operations, which is why, importing packages and libraries is important. This is much like how we take a particular book we need from a physical library.
Libraries like Pandas and NumPy, are certain Python libraries one can turn to. Coming to our digital assistant, a Python full stack developer course online will offer you the steps for implementation of the code that will make the assistant run perfectly. The packages and libraries need to be imported simply to make the job less complicated, smooth, and effective.
Let’s say we name our digital voice assistant Marvin and you want to command it to work out impeccable answers via WolframAlpha, an answer engine that does the same. You will thus write:
marvin install wolframalpha
For any further installation of any application or website, the code can be written the same way. A full stack web developer course has comprehensive study plans that teach everything from scratch.
The Implementation Steps
As we begin the required coding to create a personal voice assistant, the first step is to install and import, as stated and shown before. Let us imagine that we needed and installed subprocess, WolframAlpha, Speech Recognition, Web Browser, Pyttsx3 (a module needed to convert text to speech), Ecapture (to click images on the computer), Datetime (tells the date and time), BeautifulSoup (a library with which we can easily get information from webpages), etc. The coding would be:
import subprocess
import wolframalpha
import pyttsx3
import speech_recognition as sr
import datetime
import webbrowser
from ecapture import ecapture as ec
from bs4 import BeautifulSoup
Next, to decide the voice of digital assistant, we choose SAPI5, a Microsoft technology used for the recognition of sound and consequent speech synthesis. After setting our engine to Pyttsx3 so that the text to speech can run, our code will be:
engine = pyttsx3.init(‘sapi5‘)
voices = engine.getProperty(‘voices‘)
engine.setProperty(‘voice‘, voices[0].id)
“0” here denotes a male voice, “1” will be female, “3” will be a boy child’s voice, and so on till 9.
Now that we have our voice and wish to hear a greeting timed to the hours of the day, this code will suffice:
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wishMe():
hour = int(datetime.datetime.now().hour)
if hour>= 0 and hour<12:
speak(“Good Morning Sir !”)
elif hour>= 12 and hour<18:
speak(“Good Afternoon Sir !”)
else:
speak(“Good Evening Sir !”)
Now to command your digital voice assistant according to your needs, you need to set up the command function:
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print(“Listening…”)
r.pause_threshold = 1
audio = r.listen(source)
try:
print(“Recognizing…”)
query = r.recognize_google(audio, language =’en-in’)
print(f“User said: {query}n”)
except Exception as e:
print(e)
print(“Unable to Recognize your voice.”)
return “None”
Once done setting up the command function, try giving it a command. Let’s say a command for sending e-mails:
def sendEmail(to, content):
server = smtplib.SMTP(‘smtp.gmail.com’, 587)
server.ehlo()
server.starttls()
# Enable low security in gmail
server.login(‘your email id’, ‘your email password’)
server.sendmail(‘your email id’, to, content)
server.close()
Once this is established, you can try it out practically:
elif ‘send a mail’ in query:
try:
speak(“What should I say?”)
content = takeCommand()
speak(“whom should i send”)
to = input()
sendEmail(to, content)
speak(“Email has been sent !”)
except Exception as e:
print(e)
speak(“I am not able to send this email”)
For calculating something, this code should be inserted:
elif “calculate” in query:
app_id = “Wolframalpha api id”
client = wolframalpha.Client(app_id)
indx = query.lower().split().index(‘calculate’)
query = query.split()[indx + 1:]
res = client.query(‘ ‘.join(query))
answer = next(res.results).text
print(“The answer is “ + answer)
speak(“The answer is “ + answer)
To open YouTube or Google, it’s a fairly simple task as follows:
elif ‘open youtube’ in query:
speak(“Here you go to Youtuben”)
webbrowser.open(“youtube.com”)
elif ‘open google’ in query:
speak(“Here you go to Googlen”)
webbrowser.open(“google.com”)
To play some music, you can try this code:
elif ‘play music’ in query or “play song” in query:
speak(“Here you go with music”)
# music_dir = “S:Song”
music_dir = “C:UsersSURAJMusic”
songs = os.listdir(music_dir)
print(songs)
random = os.startfile(os.path.join(music_dir, songs[1]))
To know the time or date, this code will help:
elif ‘the time’ in query:
strTime = datetime.datetime.now().strftime(“% H:% M:% S”)
speak(f“Sir, the time is {strTime}”)
To take a picture, the command should be:
elif “camera” in query or “take a photo” in query:
ec.capture(0, “Marvin Camera “, “img.jpg”)
The functions that your personal voice assistant will carry out might be ongoing functions like how it can help you or simple greetings or they might be summoning functions like taking a picture, playing music, reporting the news, or forecasting the weather among several others.
Like this, with the required codes, you can program your personal voice assistant to carry out your commands proficiently, say certain phrases and even crack jokes, exactly like our Google Assistant or Alexa. And, with this, you’re done creating your very own assistant!
Why This is a Good Idea for a Data Science and Web Development Project?
As web development courses keep garnering popularity, it is natural to think is web development a good career? If yes, then why? Well, technology and tech jobs are one of the fastest-growing job sectors in the world. And, a full-stack developer job along with a data science job will be one of the highest-paying tech jobs in the coming decade.
With our society and environment constantly striving towards an effortless living, technology is bound to dominate and in extension, so will any tech job. With a whopping 11.5 million jobs in data science and a 31.4% rise in AI jobs according to the Bureau of Labour Statistics (BLS), a career as a full stack Python developer looks brighter than ever. This is why, going into data science and web development is guaranteed to yield results that will exceed your expectations and will prove to be worthwhile and a full stack developer certification will only be your first step.
What will You Learn by Doing This Project?
After resolving all queries related to a full stack developer and what they do, it becomes an attractive job opportunity that is greatly sought-after. But just a job, future, and salary aren’t the only aspects that matter. What matters most is what you are able to take away from such jobs.
With data science already an established sector and full stack developers growing their roots, this is an area that will allow for a variety of opportunities and projects that you can pursue at the same time. Combining these two, you will be able to culminate your knowledge and learn about all the following topics:
- Web development
- HTML and JavaScript
- Coding languages and programming languages
- Machine learning
- Designing data models
- Knowledge of cloud architecture, DevOps, and database management systems
Such programs allow you not to only work but learn new things as you do so, gain productive experience and prepare for the work environment you’re about to encounter.
Since all tech jobs are tied together by threads of similarity, if you have a good grasp of web development, full stack development would come easy to you. And, if you know Python or other programming languages, then data science would be greatly interesting.
Web development courses offer you excellent programs to get you in touch with the fields you need to be working on, complete with a full stack developer certification.
Programming and coding for applications with Python can be learnt as part of either a Data Science certification program or a Full Stack Development certification program, as it finds applications across domains.