Push SMS with Google Voice and Speech Synthesis
Since Google Voice's introduction there has been an easy way to command your homebrewed applications via SMS. This tutorial shows you how to push texts directly to a python application, and as a fun demo I use OSX's speech synthesizer to speak each received message. You can find me @rwitoff with any q's.
Step 1: Forward your google voice texts to your gmail account.
Step 2: In the gmail account that you forwarded your texts to, create a Filter that catches these forwarded texts with the following parameters, then click on 'Next Step'
Step 3: Elect to forward this filter to your IP address. (replace 127.0.0.1 with your public IP). This step will push an SMS directly to an SMTP server running on your machine!
Step 4: Publicize port 25 on the computer that will receive these texts. You may need to open this port in any firewalls, and forward your router's port to this machine.
Step 5: Run an SMTP mail server on your local machine to receive all of these texts from google voice, through gmail. Save the below python example to SMTPSpeaker.py on your machine, and replace my 192.168.1.118 with the local IP of your machine. Finally, run your server with 'sudo python smtpspeaker.py'.
*OSX needs sudo privileges to bind to the SMTP port 25
Test it out by sending an SMS to your google voice number and listen to your computer speak back the message!
And again, without color but copyable:
import smtpd, asyncore, re, os
class SMTPSpeaker(smtpd.SMTPServer):
def process_message(self, peer, mailfrom, rcpttos, data):
find = re.search('Content-Type: text/plain.*?\n(.*)', data, re.DOTALL)
if find and len(find.groups())>0:
msg = find.group(1)
print "The message is: %s" % msg
msg_clean = re.sub('[",\',!,@,#,$,%,^,&,*,(,)]', '', msg)
os.system('say "%s" ' % msg_clean)
else:
print "no message found"
#put your IP in here!
server = SMTPSpeaker(('192.168.1.118', 25), None)
asyncore.loop()



