- “Alexa…” Alexa recognizes the beginning of a query and listens for more input.
- “…play…” Alexa knows to listen for music, either an artist, a radio, a song or even a stand up bit.
- “…Mambo No. Five.” Alexa fetched the song most closely related to the request, searching on Amazon Music unless stated otherwise.
- “Mambo Number Five, (A Little Bit Of…)…” With this specific song (and a few others with second titles), Alexa is cognizant of its inflection and timing, where it knows to pause and group the words in parentheses together. Don’t believe me? If you have an Alexa, go ahead and try it out. We will briefly touch on these inflections and timing more a little later.
- “Starting now, on Amazon Music. ‘Ladies and gentlemen, this is Mambo Number Five…’” Alexa understands that the request is to play the song in the query, and since it found “Mambo No. Five (A Little Bit Of…)” on Amazon Music, it returns the song.
Creating your own virtual assistant is a lot easier than you might think. Obviously, to build an ultra complex one such as Siri, Alexa or Google Assistant, I doubt any Medium article would cover it all, but this is just to get you started.
In this example of building our own IVA, we’re going to hook up some chat functions for companionship purposes, check Wikipedia for a brief summary of something, and allow you to send an email.
We are going to use Python, which is the generally preferred language for AI, mostly because of its stellar packages and strength. Python is also a generally simple language in terms of readability, so it can make these complex systems and algorithms pretty concise.
Make sure you
pip3 install packageName for the following packages, if they aren’t installed on your device already:
- SpeechRecognition: Library for performing speech recognition, with support for several engines and APIs, online and offline.
- Pyttsx3: A text-to-speech conversion library in Python. Unlike alternative libraries, it works offline ̶,̶ ̶a̶n̶d̶ ̶i̶s̶ ̶c̶o̶m̶p̶a̶t̶i̶b̶l̶e̶ ̶w̶i̶t̶h̶ ̶b̶o̶t̶h̶ ̶P̶y̶t̶h̶o̶n̶ ̶2̶ ̶a̶n̶d̶ ̶3̶. (Rest in peace, Python 2. You were good to us all.)
- Wolframalpha: Python Client built against the Wolfram|Alpha v2.0 API.
- PyAudio: Python Bindings for PortAudio.
Getting started after installing the packages
Once everything is imported, we can now begin writing our Python code. I am naming my virtual assistant Mímir, the Norse god of knowledge and wisdom. Mímir was beheaded during the Æsir-Vanir War, and afterward, Odin carried around his head to gain knowledge and counsel from it.
Now you, too, can have your very own Norse god head to carry around for knowledge!
With all of these libraries Python provides, it is very simple to create commands and personalize your queries.
Hard mode: Get a Raspberry Pi and code that to be your virtual assistant! You can do so much with this basic understanding of IVAs, so don’t be afraid to get creative with it!
Creating your own intelligent virtual assistant is not only simple if you keep organized and install the right packages, but can be a lot of fun to play around with the voice, tempo, volume and more.