import os, re, time
from twython import TwythonStreamer


# Search terms
TERMS = '#yes'

# Twitter application authentication
APP_KEY = ''
APP_SECRET = ''
OAUTH_TOKEN = ''
OAUTH_TOKEN_SECRET = ''

# Setup callbacks from Twython Streamer
class BlinkyStreamer(TwythonStreamer):
        def on_success(self, data):
                if 'text' in data:
                        print data['text'].encode('utf-8')
			tweet = data['text'].encode('utf-8')
			tweetToSpeech = re.sub(r'\w+:\/{2}[\d\w-]+(\.[\d\w-]+)*(?:(?:\/[^\s/]*))*', '', tweet) # remove url
			os.system('espeak -ven+f2 "{0}" --stdout | aplay  2>/dev/null >/dev/null'.format(tweetToSpeech)) #speech this!

stream = BlinkyStreamer(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
stream.statuses.filter(track=TERMS)