HomeinetHow to program your personal assistant using Python

How to program your personal assistant using Python

In this article, I will share a developer's efforts to create his own python-powered personal assistant. Using open source libraries for text-to-speech and speech recognition, he describes a way to create a personal "Jarvis".

How to program your personal assistant using Python

It all started with the challenge that Facebook co-founder and CEO Mark Zuckerberg announced to build his own AI personal assistant. While I didn't know the progress he's made on this endeavor, there are plenty of resources that anyone can use to create something similar for themselves.

Python is one of the most popular programming languages ​​that people should consider learning and it comes with many options to get started with your own Jarvis project. There are many open source libraries for speech recognition and synthesis available in Python. Note that you should choose wisely, as many of them are no longer compatible with newer versions of Python.

In a blog post, developer Gurwinder Gulati shared his effort at a Python-powered personal assistant in 2016. He calls his AI assistant Samwise and explains the coding process in three parts: Jarvis's Mouth, Jarvis's Ears, and Jarvis's Brain.

As the name suggests, Jarvis's Mouth deals with the process of converting text to speech. While many Python libraries are available that offer voice recognition and speech synthesis, Mr. Gulati chose to go with pyttsx – an offline, free and open source resource. It has also been updated to work with Python 3. To use it, you will need to install JPercent's version of pyttsx by running the command pip install pyttsx.. For Windows, you will need to install PyWin32 and the Microsoft Speech API.

For speech recognition/Jarvis's Ears, you should use SpeechRecognition. This awesome resource offers the freedom to use the  Sphinx project to convert audio input to text. You can also use Google and Wit.ai services to do the same with the help of SpeechRecognition.

Now that you have everything you need, let's take a look at Jarvis's Brain, which is essentially the code written by Mr. Gulati. You can put together the aforementioned resources and libraries to create your own AI assistant.

The code shared below is quite simple and you can accomplish the same after a few hours of work and research. Take a look:

[su_box title=”Jarvi's Brain”]import speech_recognition
import pyttsx
speech_engine = pyttsx.init('sapi5') # see
https://pyttsx.readthedocs.org/en/latest/engine.html#pyttsx.init
speech_engine.setProperty('rate', 150)
def speak(text):
speech_engine.say(text)
speech_engine.runAndWait()
recognizer = speech_recognition.Recognizer()
def listen():
with speech_recognition.Microphone() as source:
recognizer.adjust_for_ambient_noise(source)
audio = recognizer.listen(source)
try:
return recognizer.recognize_sphinx(audio)
# or: return recognizer.recognize_google(audio)
except speech_recognition.UnknownValueError:
print(“Could not understand audio”)
except speech_recognition.RequestError as e:
print(“Recog Error; {0}”.format(e))
return “”
speak(“Say something!”)
speak(“I heard you say ” + listen())
[/su_box]

Good luck!!!

Jarvis-Iron-Man

📧
Subscribe to the SecNews Newsletter

The most important Security & Technology news in your Inbox.

SEARCH

FOLLOW US

📧
Newsletter SecNews
The most important Security & Technology news in your inbox.

LIVE NEWS