Gambling Affiliation

Gambling Affiliation

Thursday 28 July 2016

How To Code Your Own Personal Assistant Using Python Programming

In a blog post, programmer Gurwinder Gulati shared his quest to make a Python-powered personal assistant for himself 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 text-to-speech conversion process. While many Python libraries are available that offer voice recognition and speech synthesis, Mr. Gulati chose to move ahead with pyttsx — an offline, free and open source resource. It’s also updated to work with Python 3. To use it, you need to install JPercent’s version of pyttsx by running the command pip install pyttsx. For Windows, you should install PyWin32 and Microsoft Speech API.

Get The Best Deals on Python Programming Here

For speech recognition/Jarvis’s ears, you need to use SpeechRecognition. This great resource offers the freedom to use Sphinx project to convert the audio input into a text. You can also use Google services and Wit.ai to do the same with the help of SpeechRecognition.
Now that you’ve got everything you need, let’s take a look at Jarvis’s Brain which is basically the code written by Mr. Gulati. You can assemble the above-mentioned resources and libraries to create your own AI assistant.
The code shared below is pretty straightforward and you can get things done after few hours of work and research. Take a look:




 
Jarvis.py hosted with ❤ by GitHub
Did you find this Python-powered personal assistant project interesting? Tell us your views in the comments below.


import speech_recognition
import pyttsx
speech_engine = pyttsx.init('sapi5') # see http://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())            

No comments:

Post a Comment