Hello friends,

Here is my python code to control whole home just by voice commands. and also control your computer by just your voice commands. edit my program as per your need. hope you like it.

my project on GitHub

project website

smart_automation.py

import os,pyttsx,urllib,feedparser,time,serial
import speech_recognition as sr
import email.utils,smtplib
from email.mime.text import MIMEText

def text_speech(text):
 engine = pyttsx.init()
 engine.setProperty('rate', 150)
 voice=pyttsx.voice.Voice
 voice.id= 0x0000000002CC9550
 engine.setProperty('voice', voice.id)
 s=text
 engine.say(s)
 engine.runAndWait()

def speech_text():
 with sr.Microphone() as source:
 r = sr.Recognizer()
 audio = r.listen(source)
 print("You said " + r.recognize(audio))
 return r.recognize(audio)
 
def open_movie(string):
 a=""
 movie_list=["hulk","avengers","superman","spiderman"]
 for word in string:
 if word in movie_list:
 a="G:/Entertainment/Movies/Holleywood/"+word+".mkv"
 s="sir, opening"+word+"movie, it's a awesome movie , enjoy it"
 text_speech(s)
 os.startfile(a)
 continuos_loop()

def open_song(string):
 a=""
 song_list=["we own it"]
 for word in song_list:
 if word in string:
 a="G:\make-a-thon'14\jarvis_songs"+word+".mp3"
 temp="opening "+word+"song"
 text_speech(temp)
 continuos_loop() 
 
 
 
def open_software(string):
 software_list=["chrome","excel","word","notepad","wordpad","powerpoint","processing","putty","mspaint"]
 for software_name in string:
 if software_name in software_list:
 s="sir, i am opening "+software_name+" for you"
 text_speech(s)
 arg="start "+software_name+".exe"
 os.system(arg)
 continuos_loop()

def readmail():
 opener = urllib.FancyURLopener()
 _URL = "https://mail.google.com/gmail/feed/atom"
 f = opener.open(_URL)
 feed = f.read() 
 atom = feedparser.parse(feed)
 text_speech(atom.entries[2].title)
 continuos_loop()

def readnews(key):
 url=["http://news.google.com/?output=rss","http://indianexpress.com/rss/721/india.xml"]
 feed = feedparser.parse(url)
 entries = feed.entries
 collect=[]
 a=0
 for entry in entries:
 if a<6:
 text_speech(entry.title)
 a=a+1
 if a==0:
 text_speech("there is no new news")
 continuos_loop()

def continuos_loop():
 print "inside continuos loop..."
 try:
 result=speech_text()
 print "looping..",result
 if result=="jarvis":
 main()
 else:
 continuos_loop()
 
 except LookupError: 
 continuos_loop()

def time_check():
 text_speech(time.strftime("%I"+" and "+"%M"+" PM"))

def send_mail():
 
 temp1=""
 text_speech("tell the name of person to whom you want to send E-mail")
 temp=speech_text().split(" ")
 for word in temp:
 temp1+=word
 if "kush" in temp:
 temp1="kushrami16"
 elif "shivang" or "shivangi" in temp:
 temp1="shivaang13"
 elif "engineering" in temp:
 temp1="engineeringkfunde"
 mail_id=temp1+"@gmail.com"
 print "mail id =",mail_id
 to_email = mail_id #raw_input(’Recipient: ')
 servername = "smtp.gmail.com"
 username = "myemail@gmail.com"
 password = "your passsword"#getpass.getpass("%s’s password: " % username)
 msg = MIMEText(’checking mail’)
 msg.set_unixfrom(’dip patel’)
 msg[’To’] = email.utils.formataddr((’Recipient’, to_email))
 msg[’From’] = email.utils.formataddr((’Author’, 'author@example.com’))
 text_speech("sir what i write in mail")
 msg[’Subject’] = speech( text)

main()